Add check for orphaned newsletter posts

[MAILPOET-1587]
This commit is contained in:
Rostislav Wolny
2024-08-01 14:50:18 +02:00
committed by Aschepikov
parent 45114e4da2
commit 9b8af4cafd
5 changed files with 92 additions and 0 deletions

View File

@@ -9,6 +9,7 @@ use MailPoet\Entities\SegmentEntity;
use MailPoet\Entities\SubscriberEntity;
use MailPoet\Test\DataFactories\Newsletter;
use MailPoet\Test\DataFactories\NewsletterLink;
use MailPoet\Test\DataFactories\NewsletterPost;
use MailPoet\Test\DataFactories\ScheduledTask;
use MailPoet\Test\DataFactories\ScheduledTaskSubscriber;
use MailPoet\Test\DataFactories\Segment;
@@ -159,4 +160,18 @@ class DataInconsistencyRepositoryTest extends \MailPoetTest {
$this->repository->cleanupOrphanedNewsletterLinks();
verify($this->repository->getOrphanedNewsletterLinksCount())->equals(0);
}
public function testItHandlesOrphanedNewsletterPosts(): void {
$newsletterToDelete = (new Newsletter())->create();
$newsletterToKeep = (new Newsletter())->create();
(new NewsletterPost($newsletterToDelete))->create();
(new NewsletterPost($newsletterToKeep))->create();
$this->entityManager->remove($newsletterToDelete);
$this->entityManager->flush();
verify($this->repository->getOrphanedNewsletterPostsCount())->equals(1);
$this->repository->cleanupOrphanedNewsletterPosts();
verify($this->repository->getOrphanedNewsletterPostsCount())->equals(0);
}
}