diff --git a/README.md b/README.md index a884d56..6d05e21 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ In either case, configure Doctrine's interface mapping to deal with your custom doctrine: orm: resolve_target_entities: - \Webfactory\NewsletterRegistrationBundle\Entity\NewsletterInterface: '\AppBundle\Newsletter\Entity\Newsletter' + \Webfactory\NewsletterRegistrationBundle\Entity\CategoryInterface: '\AppBundle\Newsletter\Entity\Category' ``` Side node: The templates and example above assume that you want to keep your Newsletter classes inside a Newsletter @@ -116,15 +116,15 @@ implementations: # src/services.yml services: - AppBundle\Newsletter\Entity\NewsletterRepository: + AppBundle\Newsletter\Entity\CategoryRepository: factory: - '@doctrine.orm.entity_manager' - 'getRepository' arguments: - - 'AppBundle\Newsletter\Entity\Newsletter' + - 'AppBundle\Newsletter\Entity\Category' - Webfactory\NewsletterRegistrationBundle\Entity\NewsletterRepositoryInterface: - alias: 'AppBundle\Newsletter\Entity\NewsletterRepository' + Webfactory\NewsletterRegistrationBundle\Entity\CategoryRepositoryInterface: + alias: 'AppBundle\Newsletter\Entity\CategoryRepository' AppBundle\Newsletter\Entity\PendingOptInRepository: factory: diff --git a/Resources/app-class-templates/Category.php b/Resources/app-class-templates/Category.php new file mode 100644 index 0000000..1d6ae8e --- /dev/null +++ b/Resources/app-class-templates/Category.php @@ -0,0 +1,11 @@ +edit.registration.updated Ihre Registrierung wurde aktualisiert. - - edit.registration.updated.no.newsletters.chosen + + edit.registration.updated.no.categories.chosen Ihre Newsletter-Abos wurden gelöscht, aber Ihre Registrierungsdaten sind (wie Ihre Email-Adresse) sind weitertin in unserer Datenbank gespeichert. Wenn Sie diese auch löschen möchten, nutzen Sie bitte den untenstehende Knopf. diff --git a/Resources/translations/webfactory-newsletter-registration+intl-icu.en.xlf b/Resources/translations/webfactory-newsletter-registration+intl-icu.en.xlf index 872b2d0..fe634eb 100644 --- a/Resources/translations/webfactory-newsletter-registration+intl-icu.en.xlf +++ b/Resources/translations/webfactory-newsletter-registration+intl-icu.en.xlf @@ -25,8 +25,8 @@ edit.registration.updated Your newsletter registration was updated. - - edit.registration.updated.no.newsletters.chosen + + edit.registration.updated.no.categories.chosen All your newsletter subscriptions have been deleted, but your registration data (like your email address) is still saved in our database. If you would like to delete that data too, please delete your registration with the button below. diff --git a/src/Controller.php b/src/Controller.php index b6c1e61..83c5279 100644 --- a/src/Controller.php +++ b/src/Controller.php @@ -169,9 +169,9 @@ public function editRegistration(string $uuid, Request $request, FlashBagAwareSe if ($editForm->isSubmitted() && $editForm->isValid()) { $this->editRegistrationTask->editRegistration($recipient); - $messageKey = \count($recipient->getNewsletters()) > 0 + $messageKey = \count($recipient->getCategories()) > 0 ? 'edit.registration.updated' - : 'edit.registration.updated.no.newsletters.chosen'; + : 'edit.registration.updated.no.categories.chosen'; $session->getFlashBag()->add( 'success', $this->translator->trans($messageKey, [], 'webfactory-newsletter-registration') diff --git a/src/DependencyInjection/services.yml b/src/DependencyInjection/services.yml index 459df3d..69082c1 100644 --- a/src/DependencyInjection/services.yml +++ b/src/DependencyInjection/services.yml @@ -16,7 +16,7 @@ services: Webfactory\NewsletterRegistrationBundle\StartRegistration\Type: arguments: - - '@Webfactory\NewsletterRegistrationBundle\Entity\NewsletterRepositoryInterface' + - '@Webfactory\NewsletterRegistrationBundle\Entity\CategoryRepositoryInterface' - '@Webfactory\NewsletterRegistrationBundle\Entity\PendingOptInFactory' tags: ['form.type'] @@ -44,7 +44,7 @@ services: Webfactory\NewsletterRegistrationBundle\EditRegistration\Type: arguments: - - '@Webfactory\NewsletterRegistrationBundle\Entity\NewsletterRepositoryInterface' + - '@Webfactory\NewsletterRegistrationBundle\Entity\CategoryRepositoryInterface' tags: ['form.type'] Webfactory\NewsletterRegistrationBundle\DeleteRegistration\Type: diff --git a/src/EditRegistration/Type.php b/src/EditRegistration/Type.php index 3600b15..ef36e6f 100644 --- a/src/EditRegistration/Type.php +++ b/src/EditRegistration/Type.php @@ -5,25 +5,25 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\HiddenType; use Symfony\Component\Form\FormBuilderInterface; -use Webfactory\NewsletterRegistrationBundle\Entity\NewsletterRepositoryInterface; +use Webfactory\NewsletterRegistrationBundle\Entity\CategoryRepositoryInterface; class Type extends AbstractType { - use TypeHasNewslettersElementTrait; + use TypeHasCategoriesElementTrait; - public const ELEMENT_NEWSLETTERS = 'newsletters'; + public const ELEMENT_CATEGORIES = 'categories'; - public function __construct(NewsletterRepositoryInterface $newsletterRepository) + public function __construct(CategoryRepositoryInterface $categoryRepository) { - $this->newsletterRepository = $newsletterRepository; + $this->categoryRepository = $categoryRepository; } public function buildForm(FormBuilderInterface $builder, array $options): void { - $this->addNewslettersElementToForm($builder, false); + $this->addCategoriesElementToForm($builder, false); - // We need at least one element in addition to the newsletters above, so that Symfony recognizes the form being - // submitted even if no newsletters where chosen. + // We need at least one element in addition to the categories above, so that Symfony recognizes the form being + // submitted even if no categories where chosen. $builder->add('hidden', HiddenType::class, ['mapped' => false]); } } diff --git a/src/EditRegistration/TypeHasNewslettersElementTrait.php b/src/EditRegistration/TypeHasCategoriesElementTrait.php similarity index 61% rename from src/EditRegistration/TypeHasNewslettersElementTrait.php rename to src/EditRegistration/TypeHasCategoriesElementTrait.php index afdd0c0..cc061aa 100644 --- a/src/EditRegistration/TypeHasNewslettersElementTrait.php +++ b/src/EditRegistration/TypeHasCategoriesElementTrait.php @@ -5,16 +5,16 @@ use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Validator\Constraints\Choice; -use Webfactory\NewsletterRegistrationBundle\Entity\NewsletterRepositoryInterface; +use Webfactory\NewsletterRegistrationBundle\Entity\CategoryRepositoryInterface; -trait TypeHasNewslettersElementTrait +trait TypeHasCategoriesElementTrait { - protected NewsletterRepositoryInterface $newsletterRepository; + protected CategoryRepositoryInterface $categoryRepository; - protected function addNewslettersElementToForm(FormBuilderInterface $builder, bool $recipientHasToChooseAtLeastOne) + protected function addCategoriesElementToForm(FormBuilderInterface $builder, bool $recipientHasToChooseAtLeastOne) { - // add newsletter choices, if there is more than one - $choices = $this->newsletterRepository->findVisible(); + // add category choices, if there is more than one + $choices = $this->categoryRepository->findVisible(); if (\count($choices) < 2) { return; } @@ -25,10 +25,10 @@ protected function addNewslettersElementToForm(FormBuilderInterface $builder, bo } $builder->add( - self::ELEMENT_NEWSLETTERS, + self::ELEMENT_CATEGORIES, ChoiceType::class, [ - 'label' => 'Newsletters', + 'label' => 'Categories', 'multiple' => true, 'expanded' => true, 'choices' => $choices, diff --git a/src/Entity/Newsletter.php b/src/Entity/Category.php similarity index 89% rename from src/Entity/Newsletter.php rename to src/Entity/Category.php index 4d40f62..ec5d14e 100644 --- a/src/Entity/Newsletter.php +++ b/src/Entity/Category.php @@ -5,7 +5,7 @@ use Doctrine\ORM\Mapping as ORM; #[ORM\MappedSuperclass] -abstract class Newsletter implements NewsletterInterface +abstract class Category implements CategoryInterface { #[ORM\Id] #[ORM\GeneratedValue] @@ -18,7 +18,7 @@ abstract class Newsletter implements NewsletterInterface #[ORM\Column(type: 'boolean', nullable: false, options: ['default' => true])] protected bool $visible; - /** Used for sorting amongst other Newsletters. */ + /** Used for sorting amongst other Categories. */ #[ORM\Column(type: 'integer', nullable: false, options: ['default' => 0])] protected int $rank; diff --git a/src/Entity/NewsletterInterface.php b/src/Entity/CategoryInterface.php similarity index 78% rename from src/Entity/NewsletterInterface.php rename to src/Entity/CategoryInterface.php index 0500d3e..5735bef 100644 --- a/src/Entity/NewsletterInterface.php +++ b/src/Entity/CategoryInterface.php @@ -2,7 +2,7 @@ namespace Webfactory\NewsletterRegistrationBundle\Entity; -interface NewsletterInterface +interface CategoryInterface { public function getName(): string; } diff --git a/src/Entity/NewsletterRepository.php b/src/Entity/CategoryRepository.php similarity index 72% rename from src/Entity/NewsletterRepository.php rename to src/Entity/CategoryRepository.php index 1e14f40..9ab84a6 100644 --- a/src/Entity/NewsletterRepository.php +++ b/src/Entity/CategoryRepository.php @@ -4,7 +4,7 @@ use Doctrine\ORM\EntityRepository; -abstract class NewsletterRepository extends EntityRepository implements NewsletterRepositoryInterface +abstract class CategoryRepository extends EntityRepository implements CategoryRepositoryInterface { public function findVisible(): array { diff --git a/src/Entity/NewsletterRepositoryInterface.php b/src/Entity/CategoryRepositoryInterface.php similarity index 62% rename from src/Entity/NewsletterRepositoryInterface.php rename to src/Entity/CategoryRepositoryInterface.php index 7f62b0f..ad06848 100644 --- a/src/Entity/NewsletterRepositoryInterface.php +++ b/src/Entity/CategoryRepositoryInterface.php @@ -2,10 +2,10 @@ namespace Webfactory\NewsletterRegistrationBundle\Entity; -interface NewsletterRepositoryInterface +interface CategoryRepositoryInterface { /** - * @return NewsletterInterface[] + * @return CategoryInterface[] */ public function findVisible(): array; } diff --git a/src/Entity/PendingOptIn.php b/src/Entity/PendingOptIn.php index bab9cdc..5f8f42b 100644 --- a/src/Entity/PendingOptIn.php +++ b/src/Entity/PendingOptIn.php @@ -29,14 +29,14 @@ abstract class PendingOptIn implements PendingOptInInterface protected DateTimeImmutable $registrationDate; /** - * @var Collection + * @var Collection */ - #[ORM\ManyToMany(targetEntity: NewsletterInterface::class)] + #[ORM\ManyToMany(targetEntity: CategoryInterface::class)] #[ORM\JoinTable( joinColumns: [new ORM\JoinColumn(referencedColumnName: 'uuid', onDelete: 'CASCADE')], inverseJoinColumns: [new ORM\JoinColumn(onDelete: 'CASCADE')] )] - protected Collection $newsletters; + protected Collection $categories; public static function fromRegistrationFormData(array $formData): ?PendingOptInInterface { @@ -48,20 +48,20 @@ public static function fromRegistrationFormData(array $formData): ?PendingOptInI return new static( null, $emailAddress, - $formData[StartRegistrationType::ELEMENT_NEWSLETTERS] ?? [] + $formData[StartRegistrationType::ELEMENT_CATEGORIES] ?? [] ); } public function __construct( ?string $uuid, EmailAddress $emailAddress, - array $newsletters = [], + array $categories = [], ?DateTimeImmutable $registrationDate = null ) { $this->uuid = $uuid ?: Uuid::uuid4()->toString(); $this->emailAddress = $emailAddress; $this->emailAddressHash = $emailAddress->getHash(); - $this->newsletters = new ArrayCollection($newsletters); + $this->categories = new ArrayCollection($categories); $this->registrationDate = $registrationDate ?: new DateTimeImmutable(); } @@ -84,9 +84,9 @@ public function setEmailAddressIfItMatchesStoredHash(EmailAddress $emailAddress) $this->emailAddress = $emailAddress; } - public function getNewsletters(): array + public function getCategories(): array { - return $this->newsletters->toArray(); + return $this->categories->toArray(); } public function getRegistrationDate(): DateTimeImmutable diff --git a/src/Entity/PendingOptInInterface.php b/src/Entity/PendingOptInInterface.php index a42f6df..12003d2 100644 --- a/src/Entity/PendingOptInInterface.php +++ b/src/Entity/PendingOptInInterface.php @@ -16,9 +16,9 @@ public function getEmailAddress(): EmailAddress; public function setEmailAddressIfItMatchesStoredHash(EmailAddress $email): void; /** - * @return NewsletterInterface[] + * @return CategoryInterface[] */ - public function getNewsletters(): array; + public function getCategories(): array; public function getRegistrationDate(): DateTimeImmutable; diff --git a/src/Entity/Recipient.php b/src/Entity/Recipient.php index c90c727..7949561 100644 --- a/src/Entity/Recipient.php +++ b/src/Entity/Recipient.php @@ -30,33 +30,33 @@ abstract class Recipient implements RecipientInterface protected DateTimeImmutable $optInDate; /** - * @var Collection + * @var Collection */ - #[ORM\ManyToMany(targetEntity: NewsletterInterface::class)] + #[ORM\ManyToMany(targetEntity: CategoryInterface::class)] #[ORM\JoinTable( joinColumns: [new ORM\JoinColumn(onDelete: 'CASCADE')], inverseJoinColumns: [new ORM\JoinColumn(onDelete: 'CASCADE')] )] - protected Collection $newsletters; + protected Collection $categories; public static function fromPendingOptIn(PendingOptInInterface $pendingOptIn): RecipientInterface { return new static( $pendingOptIn->getUuid(), $pendingOptIn->getEmailAddress(), - $pendingOptIn->getNewsletters() + $pendingOptIn->getCategories() ); } public function __construct( ?string $uuid, EmailAddress $emailAddress, - array $newsletters = [], + array $categories = [], ?DateTimeImmutable $optInDate = null ) { $this->uuid = $uuid ?: Uuid::uuid4()->toString(); $this->emailAddress = $emailAddress->getEmailAddress(); - $this->newsletters = new ArrayCollection($newsletters); + $this->categories = new ArrayCollection($categories); $this->optInDate = $optInDate ?: new DateTimeImmutable(); } @@ -75,13 +75,13 @@ public function getOptInDate(): DateTimeImmutable return $this->optInDate; } - public function getNewsletters(): array + public function getCategories(): array { - return $this->newsletters->toArray(); + return $this->categories->toArray(); } - public function setNewsletters(array $newsletters): void + public function setCategories(array $categories): void { - $this->newsletters = new ArrayCollection($newsletters); + $this->categories = new ArrayCollection($categories); } } diff --git a/src/Entity/RecipientInterface.php b/src/Entity/RecipientInterface.php index f283f75..ec0c516 100644 --- a/src/Entity/RecipientInterface.php +++ b/src/Entity/RecipientInterface.php @@ -11,12 +11,12 @@ public function getUuid(): string; public function getEmailAddress(): EmailAddress; /** - * @return NewsletterInterface[] + * @return CategoryInterface[] */ - public function getNewsletters(): array; + public function getCategories(): array; /** - * @param NewsletterInterface[] $newsletters + * @param CategoryInterface[] $categories */ - public function setNewsletters(array $newsletters): void; + public function setCategories(array $categories): void; } diff --git a/src/Resources/views/EditRegistration/forms.html.twig b/src/Resources/views/EditRegistration/forms.html.twig index 9005938..d7484fd 100644 --- a/src/Resources/views/EditRegistration/forms.html.twig +++ b/src/Resources/views/EditRegistration/forms.html.twig @@ -8,18 +8,18 @@

Your Newsletter Registration

-{% if editForm.newsletters is defined %} -

Change the newsletters you're subscribed to

+{% if editForm.categories is defined %} +

Change the newsletter categories you're subscribed to

{{ form_start(editForm) }} - {{ form_errors(editForm.newsletters) }} - {{ form_label(editForm.newsletters) }} - {{ form_widget(editForm.newsletters) }} + {{ form_errors(editForm.categories) }} + {{ form_label(editForm.categories) }} + {{ form_widget(editForm.categories) }} - + {{ form_end(editForm) }} -{% elseif recipient.newsletters |length == 1 %} -

You are subscribed to the "{{ recipient.newsletters[0].name }}" newsletter with your email address {{ recipient.emailAddress }}.

+{% elseif recipient.categories |length == 1 %} +

You are subscribed to the "{{ recipient.categories[0].name }}" newsletter with your email address {{ recipient.emailAddress }}.

{% endif %}

Delete your whole Newsletter Registration

diff --git a/src/Resources/views/StartRegistration/form-partial.html.twig b/src/Resources/views/StartRegistration/form-partial.html.twig index ad7a05f..c429f37 100644 --- a/src/Resources/views/StartRegistration/form-partial.html.twig +++ b/src/Resources/views/StartRegistration/form-partial.html.twig @@ -13,10 +13,10 @@ {{ form_label(registrationForm.emailAddress) }}: {{ form_widget(registrationForm.emailAddress) }} - {% if registrationForm.newsletters is defined %} - {{ form_errors(registrationForm.newsletters) }} - {{ form_label(registrationForm.newsletters) }}: - {{ form_widget(registrationForm.newsletters) }} + {% if registrationForm.categories is defined %} + {{ form_errors(registrationForm.categories) }} + {{ form_label(registrationForm.categories) }}: + {{ form_widget(registrationForm.categories) }} {% endif %} {{ form_widget(registrationForm.url) }} diff --git a/src/StartRegistration/Type.php b/src/StartRegistration/Type.php index 04d612a..4efaa33 100644 --- a/src/StartRegistration/Type.php +++ b/src/StartRegistration/Type.php @@ -5,24 +5,24 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\CallbackTransformer; use Symfony\Component\Form\FormBuilderInterface; -use Webfactory\NewsletterRegistrationBundle\EditRegistration\TypeHasNewslettersElementTrait; -use Webfactory\NewsletterRegistrationBundle\Entity\NewsletterRepositoryInterface; +use Webfactory\NewsletterRegistrationBundle\EditRegistration\TypeHasCategoriesElementTrait; +use Webfactory\NewsletterRegistrationBundle\Entity\CategoryRepositoryInterface; use Webfactory\NewsletterRegistrationBundle\Entity\PendingOptInFactoryInterface; use Webfactory\NewsletterRegistrationBundle\Entity\PendingOptInInterface; class Type extends AbstractType { - use TypeHasNewslettersElementTrait; + use TypeHasCategoriesElementTrait; public const ELEMENT_EMAIL_ADDRESS = 'emailAddress'; - public const ELEMENT_NEWSLETTERS = 'newsletters'; + public const ELEMENT_CATEGORIES = 'categories'; public const ELEMENT_HONEYPOT = 'url'; protected PendingOptInFactoryInterface $pendingOptInFactory; - public function __construct(NewsletterRepositoryInterface $newsletterRepository, PendingOptInFactoryInterface $pendingOptInFactory) + public function __construct(CategoryRepositoryInterface $categoryRepository, PendingOptInFactoryInterface $pendingOptInFactory) { - $this->newsletterRepository = $newsletterRepository; + $this->categoryRepository = $categoryRepository; $this->pendingOptInFactory = $pendingOptInFactory; } @@ -30,7 +30,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void { $builder->add(static::ELEMENT_EMAIL_ADDRESS, EmailAddressType::class); - $this->addNewslettersElementToForm($builder, true); + $this->addCategoriesElementToForm($builder, true); // fake field for spam protection $builder->add(static::ELEMENT_HONEYPOT, HoneypotType::class); @@ -44,7 +44,7 @@ function (?PendingOptInInterface $pendingOptIn): array { return [ static::ELEMENT_EMAIL_ADDRESS => (string) $pendingOptIn->getEmailAddress(), - static::ELEMENT_NEWSLETTERS => $pendingOptIn->getNewsletters(), + static::ELEMENT_CATEGORIES => $pendingOptIn->getCategories(), ]; }, function (array $formData) use ($that): ?PendingOptInInterface { diff --git a/tests/Entity/CategoryRepositoryTest.php b/tests/Entity/CategoryRepositoryTest.php new file mode 100644 index 0000000..443f3ae --- /dev/null +++ b/tests/Entity/CategoryRepositoryTest.php @@ -0,0 +1,59 @@ +repository = self::getContainer() + ->get('doctrine') + ->getManager() + ->getRepository(Category::class); + } + + #[Test] + public function findVisible_returns_visible_categories() + { + CategoryFactory::createOne(); + + $categories = $this->repository->findVisible(); + + $this->assertCount(1, $categories); + $this->assertContainsOnly(Category::class, $categories); + } + + #[Test] + public function findVisible_does_not_return_invisible_categories() + { + CategoryFactory::createOne(['visible' => false]); + + $this->assertEmpty($this->repository->findVisible()); + } + + #[Test] + public function findVisible_orders_by_rank() + { + CategoryFactory::createOne(['name' => '1', 'rank' => 1]); + CategoryFactory::createOne(['name' => '3', 'rank' => 3]); + CategoryFactory::createOne(['name' => '2', 'rank' => 2]); + + $categories = $this->repository->findVisible(); + + $this->assertEquals(['1', '2', '3'], array_map(fn ($c) => $c->getName(), $categories)); + } +} diff --git a/tests/Entity/NewsletterTest.php b/tests/Entity/CategoryTest.php similarity index 65% rename from tests/Entity/NewsletterTest.php rename to tests/Entity/CategoryTest.php index 8b6adc1..b7c6891 100644 --- a/tests/Entity/NewsletterTest.php +++ b/tests/Entity/CategoryTest.php @@ -5,14 +5,14 @@ use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; -use Webfactory\NewsletterRegistrationBundle\Tests\Entity\Dummy\Newsletter; +use Webfactory\NewsletterRegistrationBundle\Tests\Entity\Dummy\Category; -class NewsletterTest extends TestCase +class CategoryTest extends TestCase { #[DoesNotPerformAssertions] #[Test] public function can_be_constructed() { - new Newsletter(null, 'newsletter name'); + new Category(null, 'category name'); } } diff --git a/tests/Entity/Dummy/Category.php b/tests/Entity/Dummy/Category.php new file mode 100644 index 0000000..9af01e9 --- /dev/null +++ b/tests/Entity/Dummy/Category.php @@ -0,0 +1,10 @@ +repository = self::getContainer() - ->get('doctrine') - ->getManager() - ->getRepository(Newsletter::class); - } - - #[Test] - public function findVisible_returns_visible_newsletters() - { - NewsletterFactory::createOne(); - - $newsletters = $this->repository->findVisible(); - - $this->assertCount(1, $newsletters); - $this->assertContainsOnly(Newsletter::class, $newsletters); - } - - #[Test] - public function findVisible_does_not_return_invisible_newsletters() - { - NewsletterFactory::createOne(['visible' => false]); - - $this->assertEmpty($this->repository->findVisible()); - } - - #[Test] - public function findVisible_orders_by_rank() - { - NewsletterFactory::createOne(['name' => '1', 'rank' => 1]); - NewsletterFactory::createOne(['name' => '3', 'rank' => 3]); - NewsletterFactory::createOne(['name' => '2', 'rank' => 2]); - - $newsletters = $this->repository->findVisible(); - - $this->assertEquals(['1', '2', '3'], array_map(fn ($n) => $n->getName(), $newsletters)); - } -} diff --git a/tests/Entity/PendingOptInFactoryTest.php b/tests/Entity/PendingOptInFactoryTest.php index fbbb275..3febc96 100644 --- a/tests/Entity/PendingOptInFactoryTest.php +++ b/tests/Entity/PendingOptInFactoryTest.php @@ -8,7 +8,7 @@ use Webfactory\NewsletterRegistrationBundle\Entity\EmailAddress; use Webfactory\NewsletterRegistrationBundle\Entity\PendingOptInFactory; use Webfactory\NewsletterRegistrationBundle\StartRegistration\Type as StartRegistrationType; -use Webfactory\NewsletterRegistrationBundle\Tests\Entity\Dummy\Newsletter; +use Webfactory\NewsletterRegistrationBundle\Tests\Entity\Dummy\Category; class PendingOptInFactoryTest extends TestCase { @@ -22,7 +22,7 @@ protected function setUp(): void } #[Test] - public function fromRegistrationFormData_without_newsletter_choices(): void + public function fromRegistrationFormData_without_category_choices(): void { // The PendingOptInFactory uses get_declared_classes() to find a PendingOptInInterface // implementation outside the Webfactory\NewsletterRegistrationBundle namespace — @@ -37,20 +37,20 @@ class_exists(AppPendingOptIn::class); } #[Test] - public function fromRegistrationFormData_with_newsletter_choices(): void + public function fromRegistrationFormData_with_category_choices(): void { // The PendingOptInFactory uses get_declared_classes() to find a PendingOptInInterface // implementation outside the Webfactory\NewsletterRegistrationBundle namespace — // the class must be loaded before the factory is called: class_exists(AppPendingOptIn::class); - $newslettersForPendingOptIn = [new Newsletter(1, 'newsletter 1')]; + $categoriesForPendingOptIn = [new Category(1, 'category 1')]; $pendingOptIn = $this->factory->fromRegistrationFormData([ StartRegistrationType::ELEMENT_EMAIL_ADDRESS => new EmailAddress('webfactory@example.com', 'secret'), - StartRegistrationType::ELEMENT_NEWSLETTERS => $newslettersForPendingOptIn, + StartRegistrationType::ELEMENT_CATEGORIES => $categoriesForPendingOptIn, ]); $this->assertEquals('webfactory@example.com', (string) $pendingOptIn->getEmailAddress()); - $this->assertEquals($newslettersForPendingOptIn, $pendingOptIn->getNewsletters()); + $this->assertEquals($categoriesForPendingOptIn, $pendingOptIn->getCategories()); } } diff --git a/tests/Entity/PendingOptInTest.php b/tests/Entity/PendingOptInTest.php index befdfa1..747259d 100644 --- a/tests/Entity/PendingOptInTest.php +++ b/tests/Entity/PendingOptInTest.php @@ -10,7 +10,7 @@ use Webfactory\NewsletterRegistrationBundle\Entity\EmailAddress; use Webfactory\NewsletterRegistrationBundle\Exception\EmailAddressDoesNotMatchHashOfPendingOptInException; use Webfactory\NewsletterRegistrationBundle\StartRegistration\Type as StartRegistrationType; -use Webfactory\NewsletterRegistrationBundle\Tests\Entity\Dummy\Newsletter; +use Webfactory\NewsletterRegistrationBundle\Tests\Entity\Dummy\Category; use Webfactory\NewsletterRegistrationBundle\Tests\Entity\Dummy\PendingOptIn; class PendingOptInTest extends TestCase @@ -35,14 +35,14 @@ public function registrationDate_is_added_if_omitted(): void #[DoesNotPerformAssertions] #[Test] - public function static_construction_with_newsletters(): void + public function static_construction_with_categories(): void { PendingOptIn::fromRegistrationFormData( [ StartRegistrationType::ELEMENT_EMAIL_ADDRESS => new EmailAddress('webfactory@example.org', 'secret'), - StartRegistrationType::ELEMENT_NEWSLETTERS => [ - new Newsletter(null, 'First Newsletter'), - new Newsletter(null, 'Second Newsletter'), + StartRegistrationType::ELEMENT_CATEGORIES => [ + new Category(null, 'First Category'), + new Category(null, 'Second Category'), ], ] ); @@ -50,7 +50,7 @@ public function static_construction_with_newsletters(): void #[DoesNotPerformAssertions] #[Test] - public function static_construction_without_newsletters(): void + public function static_construction_without_categories(): void { PendingOptIn::fromRegistrationFormData( [ diff --git a/tests/Entity/RecipientFactoryTest.php b/tests/Entity/RecipientFactoryTest.php index 754a021..0f07114 100644 --- a/tests/Entity/RecipientFactoryTest.php +++ b/tests/Entity/RecipientFactoryTest.php @@ -7,7 +7,7 @@ use PHPUnit\Framework\TestCase; use Webfactory\NewsletterRegistrationBundle\Entity\EmailAddress; use Webfactory\NewsletterRegistrationBundle\Entity\RecipientFactory; -use Webfactory\NewsletterRegistrationBundle\Tests\Entity\Dummy\Newsletter; +use Webfactory\NewsletterRegistrationBundle\Tests\Entity\Dummy\Category; use Webfactory\NewsletterRegistrationBundle\Tests\Entity\Dummy\PendingOptIn; class RecipientFactoryTest extends TestCase @@ -20,13 +20,13 @@ public function fromPendingOptIn() // the class must be loaded before the factory is called: class_exists(AppRecipient::class); - $newslettersForPendingOptIn = [new Newsletter(1, 'newsletter 1')]; + $categoriesForPendingOptIn = [new Category(1, 'category 1')]; $recipient = (new RecipientFactory())->fromPendingOptIn( - new PendingOptIn('uuid', new EmailAddress('webfactory@example.com', 'secret'), $newslettersForPendingOptIn) + new PendingOptIn('uuid', new EmailAddress('webfactory@example.com', 'secret'), $categoriesForPendingOptIn) ); $this->assertEquals('uuid', $recipient->getUuid()); $this->assertEquals('webfactory@example.com', (string) $recipient->getEmailAddress()); - $this->assertEquals($newslettersForPendingOptIn, $recipient->getNewsletters()); + $this->assertEquals($categoriesForPendingOptIn, $recipient->getCategories()); } } diff --git a/tests/Entity/RecipientTest.php b/tests/Entity/RecipientTest.php index 0e28340..42bb223 100644 --- a/tests/Entity/RecipientTest.php +++ b/tests/Entity/RecipientTest.php @@ -7,7 +7,7 @@ use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Webfactory\NewsletterRegistrationBundle\Entity\EmailAddress; -use Webfactory\NewsletterRegistrationBundle\Tests\Entity\Dummy\Newsletter; +use Webfactory\NewsletterRegistrationBundle\Tests\Entity\Dummy\Category; use Webfactory\NewsletterRegistrationBundle\Tests\Entity\Dummy\PendingOptIn; use Webfactory\NewsletterRegistrationBundle\Tests\Entity\Dummy\Recipient; @@ -32,21 +32,21 @@ public function optInDate_is_added_if_omitted() } #[Test] - public function static_construction_with_newsletters() + public function static_construction_with_categories() { - $newslettersForPendingOptIn = [new Newsletter(1, 'newsletter 1'), new Newsletter(2, 'newsletter 2')]; - $pendingOptIn = new PendingOptIn('uuid', new EmailAddress('webfactory@example.com', 'secret'), $newslettersForPendingOptIn); + $categoriesForPendingOptIn = [new Category(1, 'category 1'), new Category(2, 'category 2')]; + $pendingOptIn = new PendingOptIn('uuid', new EmailAddress('webfactory@example.com', 'secret'), $categoriesForPendingOptIn); $recipient = Recipient::fromPendingOptIn($pendingOptIn); $this->assertEquals('uuid', $recipient->getUuid()); $this->assertEquals('webfactory@example.com', (string) $recipient->getEmailAddress()); - $this->assertEquals($newslettersForPendingOptIn, $recipient->getNewsletters()); + $this->assertEquals($categoriesForPendingOptIn, $recipient->getCategories()); } #[DoesNotPerformAssertions] #[Test] - public function static_construction_without_newsletters() + public function static_construction_without_categories() { $pendingOptIn = new PendingOptIn('uuid', new EmailAddress('webfactory@example.com', 'secret')); diff --git a/tests/Factory/NewsletterFactory.php b/tests/Factory/CategoryFactory.php similarity index 63% rename from tests/Factory/NewsletterFactory.php rename to tests/Factory/CategoryFactory.php index 51eb5c7..25fb086 100644 --- a/tests/Factory/NewsletterFactory.php +++ b/tests/Factory/CategoryFactory.php @@ -2,10 +2,10 @@ namespace Webfactory\NewsletterRegistrationBundle\Tests\Factory; -use Webfactory\NewsletterRegistrationBundle\Tests\Entity\Dummy\Newsletter; +use Webfactory\NewsletterRegistrationBundle\Tests\Entity\Dummy\Category; use Zenstruck\Foundry\Persistence\PersistentObjectFactory; -final class NewsletterFactory extends PersistentObjectFactory +final class CategoryFactory extends PersistentObjectFactory { protected function defaults(): array { @@ -18,13 +18,13 @@ protected function defaults(): array protected function initialize(): static { - return $this->instantiateWith(function (array $attributes): Newsletter { - return new Newsletter(null, $attributes['name'], $attributes['rank'], $attributes['visible']); + return $this->instantiateWith(function (array $attributes): Category { + return new Category(null, $attributes['name'], $attributes['rank'], $attributes['visible']); }); } public static function class(): string { - return Newsletter::class; + return Category::class; } } diff --git a/tests/Fixtures/config/doctrine.php b/tests/Fixtures/config/doctrine.php index 2f9755b..2d5d2d4 100644 --- a/tests/Fixtures/config/doctrine.php +++ b/tests/Fixtures/config/doctrine.php @@ -1,8 +1,8 @@ extension('doctrine', [ @@ -12,7 +12,7 @@ ], 'orm' => [ 'resolve_target_entities' => [ - NewsletterInterface::class => Newsletter::class, + CategoryInterface::class => Category::class, ], 'mappings' => [ 'BundleEntities' => [ diff --git a/tests/Fixtures/config/functional_services.php b/tests/Fixtures/config/functional_services.php index 77818ef..1fec304 100644 --- a/tests/Fixtures/config/functional_services.php +++ b/tests/Fixtures/config/functional_services.php @@ -4,11 +4,11 @@ use function Symfony\Component\DependencyInjection\Loader\Configurator\service; -use Webfactory\NewsletterRegistrationBundle\Entity\NewsletterRepositoryInterface; +use Webfactory\NewsletterRegistrationBundle\Entity\CategoryRepositoryInterface; use Webfactory\NewsletterRegistrationBundle\Entity\PendingOptInRepositoryInterface; use Webfactory\NewsletterRegistrationBundle\Entity\RecipientFactoryInterface; use Webfactory\NewsletterRegistrationBundle\Entity\RecipientRepositoryInterface; -use Webfactory\NewsletterRegistrationBundle\Tests\Entity\Dummy\Newsletter; +use Webfactory\NewsletterRegistrationBundle\Tests\Entity\Dummy\Category; use Webfactory\NewsletterRegistrationBundle\Tests\Entity\Dummy\PendingOptIn; use Webfactory\NewsletterRegistrationBundle\Tests\Entity\Dummy\Recipient; use Webfactory\NewsletterRegistrationBundle\Tests\Fixtures\DummyRecipientFactory; @@ -39,7 +39,7 @@ ->factory([service('doctrine.orm.entity_manager'), 'getRepository']) ->args([Recipient::class]); - $services->set(NewsletterRepositoryInterface::class) + $services->set(CategoryRepositoryInterface::class) ->factory([service('doctrine.orm.entity_manager'), 'getRepository']) - ->args([Newsletter::class]); + ->args([Category::class]); }; diff --git a/tests/Functional/ControllerTest.php b/tests/Functional/ControllerTest.php index 975309a..833ab8b 100644 --- a/tests/Functional/ControllerTest.php +++ b/tests/Functional/ControllerTest.php @@ -5,7 +5,7 @@ use PHPUnit\Framework\Attributes\Test; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Webfactory\NewsletterRegistrationBundle\Entity\EmailAddress; -use Webfactory\NewsletterRegistrationBundle\Tests\Factory\NewsletterFactory; +use Webfactory\NewsletterRegistrationBundle\Tests\Factory\CategoryFactory; use Webfactory\NewsletterRegistrationBundle\Tests\Factory\PendingOptInFactory; use Webfactory\NewsletterRegistrationBundle\Tests\Factory\RecipientFactory; use Zenstruck\Foundry\Test\Factories; @@ -51,14 +51,14 @@ public function confirm_registration_sets_success_flash(): void } #[Test] - public function edit_registration_with_no_newsletter_selected_sets_success_flash(): void + public function edit_registration_with_no_category_selected_sets_success_flash(): void { $client = static::createClient(); - NewsletterFactory::createMany(2); + CategoryFactory::createMany(2); $recipient = RecipientFactory::createOne(); $crawler = $client->request('GET', sprintf('/%s/', $recipient->getUuid())); - $form = $crawler->selectButton("Change newsletters you're subscribed to")->form(); + $form = $crawler->selectButton("Change newsletter categories you're subscribed to")->form(); $client->submit($form); self::assertSelectorTextContains( @@ -70,15 +70,15 @@ public function edit_registration_with_no_newsletter_selected_sets_success_flash } #[Test] - public function edit_registration_with_newsletter_selected_sets_success_flash(): void + public function edit_registration_with_category_selected_sets_success_flash(): void { $client = static::createClient(); - $newsletters = NewsletterFactory::createMany(2); + $categories = CategoryFactory::createMany(2); $recipient = RecipientFactory::createOne(); $crawler = $client->request('GET', sprintf('/%s/', $recipient->getUuid())); - $form = $crawler->selectButton("Change newsletters you're subscribed to")->form(); - $client->submit($form, ['newsletters' => [$newsletters[0]->getId()]]); + $form = $crawler->selectButton("Change newsletter categories you're subscribed to")->form(); + $client->submit($form, ['categories' => [$categories[0]->getId()]]); self::assertSelectorTextContains('.flash-success', 'Your newsletter registration was updated.'); } diff --git a/tests/Resources/AppClassTemplatesTest.php b/tests/Resources/AppClassTemplatesTest.php index 8768c7d..1730679 100644 --- a/tests/Resources/AppClassTemplatesTest.php +++ b/tests/Resources/AppClassTemplatesTest.php @@ -2,8 +2,8 @@ namespace Webfactory\NewsletterRegistrationBundle\Tests\Resources; -use AppBundle\Newsletter\Entity\Newsletter as NewsletterTemplate; -use AppBundle\Newsletter\Entity\NewsletterRepository as NewsletterRepositoryTemplate; +use AppBundle\Newsletter\Entity\Category as CategoryTemplate; +use AppBundle\Newsletter\Entity\CategoryRepository as CategoryRepositoryTemplate; use AppBundle\Newsletter\Entity\PendingOptIn as PendingOptInTemplate; use AppBundle\Newsletter\Entity\PendingOptInRepository as PendingOptInRepositoryTemplate; use AppBundle\Newsletter\Entity\Recipient as RecipientTemplate; @@ -17,9 +17,9 @@ use Doctrine\ORM\Tools\SchemaValidator; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; -use Webfactory\NewsletterRegistrationBundle\Entity\Newsletter as AbstractNewsletter; -use Webfactory\NewsletterRegistrationBundle\Entity\NewsletterInterface; -use Webfactory\NewsletterRegistrationBundle\Entity\NewsletterRepository as AbstractNewsletterRepository; +use Webfactory\NewsletterRegistrationBundle\Entity\Category as AbstractCategory; +use Webfactory\NewsletterRegistrationBundle\Entity\CategoryInterface; +use Webfactory\NewsletterRegistrationBundle\Entity\CategoryRepository as AbstractCategoryRepository; use Webfactory\NewsletterRegistrationBundle\Entity\PendingOptIn as AbstractPendingOptIn; use Webfactory\NewsletterRegistrationBundle\Entity\PendingOptInRepository as AbstractPendingOptInRepository; use Webfactory\NewsletterRegistrationBundle\Entity\Recipient as AbstractRecipient; @@ -33,8 +33,8 @@ protected function setUp(): void { $resolveTargetEntityListener = new ResolveTargetEntityListener(); $resolveTargetEntityListener->addResolveTargetEntity( - NewsletterInterface::class, - NewsletterTemplate::class, + CategoryInterface::class, + CategoryTemplate::class, [] ); @@ -55,9 +55,9 @@ protected function setUp(): void } #[Test] - public function newsletter_template_extends_abstract_newsletter(): void + public function category_template_extends_abstract_category(): void { - self::assertTrue(is_subclass_of(NewsletterTemplate::class, AbstractNewsletter::class)); + self::assertTrue(is_subclass_of(CategoryTemplate::class, AbstractCategory::class)); } #[Test] @@ -73,9 +73,9 @@ public function pending_opt_in_template_extends_abstract_pending_opt_in(): void } #[Test] - public function newsletter_repository_template_extends_abstract_newsletter_repository(): void + public function category_repository_template_extends_abstract_category_repository(): void { - self::assertTrue(is_subclass_of(NewsletterRepositoryTemplate::class, AbstractNewsletterRepository::class)); + self::assertTrue(is_subclass_of(CategoryRepositoryTemplate::class, AbstractCategoryRepository::class)); } #[Test] @@ -99,9 +99,9 @@ public function mapping_validates_without_errors(): void } #[Test] - public function newsletter_table_name_is_correct(): void + public function category_table_name_is_correct(): void { - self::assertTrue($this->getSchema()->hasTable('wfd_newsletterNewsletter')); + self::assertTrue($this->getSchema()->hasTable('wfd_newsletterCategory')); } #[Test] diff --git a/tests/StartRegistration/TypeTest.php b/tests/StartRegistration/TypeTest.php index abf0b8b..02dad28 100644 --- a/tests/StartRegistration/TypeTest.php +++ b/tests/StartRegistration/TypeTest.php @@ -13,36 +13,36 @@ use Symfony\Component\Validator\Validation; use Symfony\Contracts\Translation\TranslatorInterface; use Webfactory\NewsletterRegistrationBundle\Entity\BlockedEmailAddressHashRepositoryInterface; +use Webfactory\NewsletterRegistrationBundle\Entity\CategoryRepositoryInterface; use Webfactory\NewsletterRegistrationBundle\Entity\EmailAddress; use Webfactory\NewsletterRegistrationBundle\Entity\EmailAddressFactory; use Webfactory\NewsletterRegistrationBundle\Entity\EmailAddressFactoryInterface; -use Webfactory\NewsletterRegistrationBundle\Entity\NewsletterRepositoryInterface; use Webfactory\NewsletterRegistrationBundle\Entity\PendingOptInFactoryInterface; use Webfactory\NewsletterRegistrationBundle\Entity\PendingOptInRepositoryInterface; use Webfactory\NewsletterRegistrationBundle\Entity\RecipientRepositoryInterface; use Webfactory\NewsletterRegistrationBundle\StartRegistration\EmailAddressType; use Webfactory\NewsletterRegistrationBundle\StartRegistration\HoneypotType; use Webfactory\NewsletterRegistrationBundle\StartRegistration\Type as StartRegistrationType; -use Webfactory\NewsletterRegistrationBundle\Tests\Entity\Dummy\Newsletter; +use Webfactory\NewsletterRegistrationBundle\Tests\Entity\Dummy\Category; use Webfactory\NewsletterRegistrationBundle\Tests\Entity\Dummy\PendingOptIn; class TypeTest extends TypeTestCase { protected const MINIMAL_INTERVAL_BETWEEN_OPT_IN_EMAILS_IN_HOURS = 1; - protected NewsletterRepositoryInterface&MockObject $newsletterRepository; + protected CategoryRepositoryInterface&MockObject $categoryRepository; protected PendingOptInFactoryInterface&MockObject $pendingOptInFactory; protected BlockedEmailAddressHashRepositoryInterface&MockObject $blockedEmailAddressHashRepository; protected PendingOptInRepositoryInterface&MockObject $pendingOptInRepository; protected RecipientRepositoryInterface&MockObject $recipientRepository; protected EmailAddressFactoryInterface $emailAddressFactory; protected TranslatorInterface&MockObject $translator; - protected ?Newsletter $newsletter1; - protected ?Newsletter $newsletter2; + protected ?Category $category1; + protected ?Category $category2; protected function setUp(): void { - $this->newsletterRepository = $this->createMock(NewsletterRepositoryInterface::class); + $this->categoryRepository = $this->createMock(CategoryRepositoryInterface::class); $this->pendingOptInFactory = $this->createMock(PendingOptInFactoryInterface::class); $this->blockedEmailAddressHashRepository = $this->createMock(BlockedEmailAddressHashRepositoryInterface::class); $this->pendingOptInRepository = $this->createMock(PendingOptInRepositoryInterface::class); @@ -55,35 +55,35 @@ protected function setUp(): void } #[Test] - public function view_has_no_newsletter_choices_element_if_there_are_no_choices(): void + public function view_has_no_category_choices_element_if_there_are_no_choices(): void { $formView = $this->factory->create(StartRegistrationType::class)->createView(); - $this->assertArrayNotHasKey(startRegistrationType::ELEMENT_NEWSLETTERS, $formView->vars['form']->children); + $this->assertArrayNotHasKey(StartRegistrationType::ELEMENT_CATEGORIES, $formView->vars['form']->children); } #[Test] - public function view_has_no_newsletter_choice_element_if_there_is_exactly_one_choice(): void + public function view_has_no_category_choice_element_if_there_is_exactly_one_choice(): void { - $this->setUpOneNewsletter(); + $this->setUpOneCategory(); $formView = $this->factory->create(StartRegistrationType::class)->createView(); - $this->assertArrayNotHasKey(startRegistrationType::ELEMENT_NEWSLETTERS, $formView->vars['form']->children); + $this->assertArrayNotHasKey(StartRegistrationType::ELEMENT_CATEGORIES, $formView->vars['form']->children); } #[Test] - public function view_contains_newsletter_choice_element_if_there_is_more_than_one_choice(): void + public function view_contains_category_choice_element_if_there_is_more_than_one_choice(): void { - $this->setUpTwoNewsletters(); + $this->setUpTwoCategories(); $formView = $this->factory->create(StartRegistrationType::class)->createView(); - $newslettersVars = $formView->vars['form']->children[startRegistrationType::ELEMENT_NEWSLETTERS]->vars; - $this->assertArrayHasKey('choices', $newslettersVars); - - $this->assertCount(2, $newslettersVars['choices']); - $this->assertEquals($this->newsletter1->getId(), $newslettersVars['choices'][0]->value); - $this->assertEquals($this->newsletter1->getName(), $newslettersVars['choices'][0]->label); - $this->assertEquals($this->newsletter2->getId(), $newslettersVars['choices'][1]->value); - $this->assertEquals($this->newsletter2->getName(), $newslettersVars['choices'][1]->label); + $categoriesVars = $formView->vars['form']->children[StartRegistrationType::ELEMENT_CATEGORIES]->vars; + $this->assertArrayHasKey('choices', $categoriesVars); + + $this->assertCount(2, $categoriesVars['choices']); + $this->assertEquals($this->category1->getId(), $categoriesVars['choices'][0]->value); + $this->assertEquals($this->category1->getName(), $categoriesVars['choices'][0]->label); + $this->assertEquals($this->category2->getId(), $categoriesVars['choices'][1]->value); + $this->assertEquals($this->category2->getName(), $categoriesVars['choices'][1]->label); } #[Test] @@ -91,7 +91,7 @@ public function does_not_validate_without_honeypot() { $form = $this->factory->create(StartRegistrationType::class); $form->submit([ - startRegistrationType::ELEMENT_EMAIL_ADDRESS => 'webfactory@example.com', + StartRegistrationType::ELEMENT_EMAIL_ADDRESS => 'webfactory@example.com', ]); $this->assertFalse($form->isValid()); @@ -107,8 +107,8 @@ public function does_not_validate_with_filled_honeypot() { $form = $this->factory->create(StartRegistrationType::class); $form->submit([ - startRegistrationType::ELEMENT_EMAIL_ADDRESS => 'webfactory@example.com', - startRegistrationType::ELEMENT_HONEYPOT => 'http://spam.com', + StartRegistrationType::ELEMENT_EMAIL_ADDRESS => 'webfactory@example.com', + StartRegistrationType::ELEMENT_HONEYPOT => 'http://spam.com', ]); $this->assertFalse($form->isValid()); @@ -121,8 +121,8 @@ public function does_not_validate_without_email_address() { $form = $this->factory->create(StartRegistrationType::class); $form->submit([ - startRegistrationType::ELEMENT_EMAIL_ADDRESS => '', - startRegistrationType::ELEMENT_HONEYPOT => '', + StartRegistrationType::ELEMENT_EMAIL_ADDRESS => '', + StartRegistrationType::ELEMENT_HONEYPOT => '', ]); $this->assertTrue($form->isSynchronized()); $this->assertFalse($form->isValid()); @@ -135,8 +135,8 @@ public function does_not_validate_with_invalid_email_address() { $form = $this->factory->create(StartRegistrationType::class); $form->submit([ - startRegistrationType::ELEMENT_EMAIL_ADDRESS => 'this is no valid email address', - startRegistrationType::ELEMENT_HONEYPOT => '', + StartRegistrationType::ELEMENT_EMAIL_ADDRESS => 'this is no valid email address', + StartRegistrationType::ELEMENT_HONEYPOT => '', ]); $this->assertTrue($form->isSynchronized()); @@ -155,8 +155,8 @@ public function does_not_validate_with_already_registering_email_address_if_not_ $form = $this->factory->create(StartRegistrationType::class); $form->submit([ - startRegistrationType::ELEMENT_EMAIL_ADDRESS => 'webfactory@example.com', - startRegistrationType::ELEMENT_HONEYPOT => '', + StartRegistrationType::ELEMENT_EMAIL_ADDRESS => 'webfactory@example.com', + StartRegistrationType::ELEMENT_HONEYPOT => '', ]); $this->assertTrue($form->isSynchronized()); @@ -185,23 +185,23 @@ public function does_validate_with_already_registering_email_address_if_enough_t $form = $this->factory->create(StartRegistrationType::class); $form->submit([ - startRegistrationType::ELEMENT_EMAIL_ADDRESS => 'webfactory@example.com', - startRegistrationType::ELEMENT_HONEYPOT => '', + StartRegistrationType::ELEMENT_EMAIL_ADDRESS => 'webfactory@example.com', + StartRegistrationType::ELEMENT_HONEYPOT => '', ]); $this->assertTrue($form->isValid()); } #[Test] - public function does_not_validate_if_newsletter_choices_exist_but_none_was_selected() + public function does_not_validate_if_category_choices_exist_but_none_was_selected() { - $this->setUpTwoNewsletters(); + $this->setUpTwoCategories(); $form = $this->factory->create(StartRegistrationType::class); $form->submit([ - startRegistrationType::ELEMENT_EMAIL_ADDRESS => 'webfactory@example.com', - startRegistrationType::ELEMENT_NEWSLETTERS => [], - startRegistrationType::ELEMENT_HONEYPOT => '', + StartRegistrationType::ELEMENT_EMAIL_ADDRESS => 'webfactory@example.com', + StartRegistrationType::ELEMENT_CATEGORIES => [], + StartRegistrationType::ELEMENT_HONEYPOT => '', ]); $this->assertFalse($form->isValid()); @@ -214,7 +214,7 @@ public function does_not_validate_if_newsletter_choices_exist_but_none_was_selec } #[Test] - public function provides_PendingOptIn_if_submitted_with_valid_data_without_newsletter_choices() + public function provides_PendingOptIn_if_submitted_with_valid_data_without_category_choices() { $pendingOptIn = new PendingOptIn(null, new EmailAddress('webfactory@example.com', 'secret')); $this->pendingOptInFactory @@ -232,8 +232,8 @@ function (array $formData) { $form = $this->factory->create(StartRegistrationType::class); $form->submit([ - startRegistrationType::ELEMENT_EMAIL_ADDRESS => 'webfactory@example.com', - startRegistrationType::ELEMENT_HONEYPOT => '', + StartRegistrationType::ELEMENT_EMAIL_ADDRESS => 'webfactory@example.com', + StartRegistrationType::ELEMENT_HONEYPOT => '', ]); $this->assertTrue($form->isValid()); @@ -241,14 +241,14 @@ function (array $formData) { } #[Test] - public function provides_PendingOptIn_if_submitted_with_valid_data_and_newsletter_choices() + public function provides_PendingOptIn_if_submitted_with_valid_data_and_category_choices() { - $this->setUpTwoNewsletters(); + $this->setUpTwoCategories(); $pendingOptIn = new PendingOptIn( null, new EmailAddress('webfactory@example.com', 'secret'), - [$this->newsletter1, $this->newsletter2] + [$this->category1, $this->category2] ); $this->pendingOptInFactory ->method('fromRegistrationFormData') @@ -258,8 +258,8 @@ function (array $formData) { return \array_key_exists(StartRegistrationType::ELEMENT_EMAIL_ADDRESS, $formData) && $formData[StartRegistrationType::ELEMENT_EMAIL_ADDRESS] instanceof EmailAddress && 'webfactory@example.com' === (string) $formData[StartRegistrationType::ELEMENT_EMAIL_ADDRESS]->getEmailAddress() - && \array_key_exists(StartRegistrationType::ELEMENT_NEWSLETTERS, $formData) - && $formData[StartRegistrationType::ELEMENT_NEWSLETTERS] === [$this->newsletter1, $this->newsletter2]; + && \array_key_exists(StartRegistrationType::ELEMENT_CATEGORIES, $formData) + && $formData[StartRegistrationType::ELEMENT_CATEGORIES] === [$this->category1, $this->category2]; } ) ) @@ -267,9 +267,9 @@ function (array $formData) { $form = $this->factory->create(StartRegistrationType::class); $form->submit([ - startRegistrationType::ELEMENT_EMAIL_ADDRESS => 'webfactory@example.com', - startRegistrationType::ELEMENT_NEWSLETTERS => [$this->newsletter1->getId(), $this->newsletter2->getId()], - startRegistrationType::ELEMENT_HONEYPOT => '', + StartRegistrationType::ELEMENT_EMAIL_ADDRESS => 'webfactory@example.com', + StartRegistrationType::ELEMENT_CATEGORIES => [$this->category1->getId(), $this->category2->getId()], + StartRegistrationType::ELEMENT_HONEYPOT => '', ]); $this->assertTrue($form->isValid()); @@ -283,7 +283,7 @@ protected function getExtensions(): array return [ new PreloadedExtension( [ - new StartRegistrationType($this->newsletterRepository, $this->pendingOptInFactory), + new StartRegistrationType($this->categoryRepository, $this->pendingOptInFactory), new EmailAddressType( $this->blockedEmailAddressHashRepository, $this->pendingOptInRepository, @@ -299,16 +299,16 @@ protected function getExtensions(): array ]; } - protected function setUpOneNewsletter(): void + protected function setUpOneCategory(): void { - $this->newsletter1 = new Newsletter(1, 'Newsletter 1'); - $this->newsletterRepository->method('findVisible')->willReturn([$this->newsletter1]); + $this->category1 = new Category(1, 'Category 1'); + $this->categoryRepository->method('findVisible')->willReturn([$this->category1]); } - protected function setUpTwoNewsletters(): void + protected function setUpTwoCategories(): void { - $this->newsletter1 = new Newsletter(1, 'Newsletter 1'); - $this->newsletter2 = new Newsletter(2, 'Newsletter 2'); - $this->newsletterRepository->method('findVisible')->willReturn([$this->newsletter1, $this->newsletter2]); + $this->category1 = new Category(1, 'Category 1'); + $this->category2 = new Category(2, 'Category 2'); + $this->categoryRepository->method('findVisible')->willReturn([$this->category1, $this->category2]); } }