generated from rich-id/bundle-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dumazeau
committed
Jul 15, 2021
1 parent
20b92d9
commit 14bf9dc
Showing
18 changed files
with
708 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
tests/Infrastructure/FormType/TermsVersionFormTypeTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RichId\TermsModuleBundle\Tests\Infrastructure\FormType; | ||
|
||
use RichCongress\TestFramework\TestConfiguration\Annotation\TestConfig; | ||
use RichCongress\TestSuite\TestCase\ControllerTestCase; | ||
use RichId\TermsModuleBundle\Domain\Entity\Terms; | ||
use RichId\TermsModuleBundle\Domain\Entity\TermsVersion; | ||
use RichId\TermsModuleBundle\Domain\Model\TermsEdition; | ||
use RichId\TermsModuleBundle\Infrastructure\FormType\TermsVersionFormType; | ||
use Symfony\Component\Form\FormFactoryInterface; | ||
|
||
/** | ||
* @covers \RichId\TermsModuleBundle\Infrastructure\FormType\TermsVersionFormType | ||
* @TestConfig("kernel") | ||
*/ | ||
final class TermsVersionFormTypeTest extends ControllerTestCase | ||
{ | ||
/** @var FormFactoryInterface */ | ||
public $formFactory; | ||
|
||
public function testSubmitEmpty(): void | ||
{ | ||
$terms = new Terms(); | ||
$termsVersion = new TermsVersion(); | ||
$termsVersion->setTerms($terms); | ||
|
||
$model = new TermsEdition($termsVersion); | ||
$form = $this->formFactory->create(TermsVersionFormType::class, $model); | ||
|
||
$form->submit( | ||
[ | ||
'_token' => $this->getCsrfToken(TermsVersionFormType::class), | ||
] | ||
); | ||
|
||
$this->assertTrue($form->isSynchronized()); | ||
$this->assertFalse($form->isValid()); | ||
|
||
$output = $form->getData(); | ||
$this->assertNull($output->getTitle()); | ||
$this->assertNull($output->getContent()); | ||
$this->assertNull($output->getPublicationDate()); | ||
$this->assertNull($output->isTermsPublished()); | ||
$this->assertNull($output->needVersionActivation()); | ||
$this->assertSame($termsVersion, $output->getEntity()); | ||
} | ||
|
||
public function testSubmitValidDataMinimum(): void | ||
{ | ||
$terms = new Terms(); | ||
$termsVersion = new TermsVersion(); | ||
$termsVersion->setTerms($terms); | ||
|
||
$model = new TermsEdition($termsVersion); | ||
$form = $this->formFactory->create(TermsVersionFormType::class, $model); | ||
|
||
$form->submit( | ||
[ | ||
'title' => 'My title', | ||
'content' => 'My content', | ||
'isTermsPublished' => '0', | ||
'_token' => $this->getCsrfToken(TermsVersionFormType::class), | ||
] | ||
); | ||
|
||
$this->assertTrue($form->isSynchronized()); | ||
$this->assertTrue($form->isValid()); | ||
|
||
$output = $form->getData(); | ||
$this->assertSame('My title', $output->getTitle()); | ||
$this->assertSame('My content', $output->getContent()); | ||
$this->assertFalse($output->isTermsPublished()); | ||
$this->assertNull($output->getPublicationDate()); | ||
$this->assertNull($output->needVersionActivation()); | ||
$this->assertSame($termsVersion, $output->getEntity()); | ||
} | ||
|
||
public function testSubmitValidDataFull(): void | ||
{ | ||
$terms = new Terms(); | ||
$termsVersion = new TermsVersion(); | ||
$termsVersion->setTerms($terms); | ||
|
||
$model = new TermsEdition($termsVersion); | ||
$form = $this->formFactory->create(TermsVersionFormType::class, $model); | ||
|
||
$form->submit( | ||
[ | ||
'title' => 'My title', | ||
'content' => 'My content', | ||
'publicationDate' => '2021-01-01', | ||
'isTermsPublished' => '0', | ||
'needVersionActivation' => 'true', | ||
'_token' => $this->getCsrfToken(TermsVersionFormType::class), | ||
] | ||
); | ||
|
||
$this->assertTrue($form->isSynchronized()); | ||
$this->assertTrue($form->isValid()); | ||
|
||
$output = $form->getData(); | ||
$this->assertSame('My title', $output->getTitle()); | ||
$this->assertSame('My content', $output->getContent()); | ||
$this->assertSame('2021-01-01', $output->getPublicationDate()->format('Y-m-d')); | ||
$this->assertFalse($output->isTermsPublished()); | ||
$this->assertTrue($output->needVersionActivation()); | ||
$this->assertSame($termsVersion, $output->getEntity()); | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
tests/Infrastructure/ValidatorConstraints/CantContentChangeIfTermsPublishedTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RichId\TermsModuleBundle\Tests\Infrastructure\ValidatorConstraints; | ||
|
||
use RichCongress\TestFramework\TestConfiguration\Annotation\TestConfig; | ||
use RichId\TermsModuleBundle\Domain\Entity\Terms; | ||
use RichId\TermsModuleBundle\Domain\Entity\TermsVersion; | ||
use RichId\TermsModuleBundle\Domain\Model\TermsEdition; | ||
use RichId\TermsModuleBundle\Infrastructure\ValidatorConstraints\CantContentChangeIfTermsPublished; | ||
use RichId\TermsModuleBundle\Tests\Resources\Entity\DummyUser; | ||
use RichId\TermsModuleBundle\Tests\Resources\TestCase\ConstraintTestCase; | ||
|
||
/** | ||
* @covers \RichId\TermsModuleBundle\Infrastructure\ValidatorConstraints\CantContentChangeIfTermsPublished | ||
* @TestConfig("kernel") | ||
*/ | ||
final class CantContentChangeIfTermsPublishedTest extends ConstraintTestCase | ||
{ | ||
/** @var CantContentChangeIfTermsPublished */ | ||
public $validator; | ||
|
||
public function testGetTargets(): void | ||
{ | ||
$this->assertSame('class', $this->validator->getTargets()); | ||
} | ||
|
||
public function testValidatedBy(): void | ||
{ | ||
$this->assertSame(CantContentChangeIfTermsPublished::class, $this->validator->validatedBy()); | ||
} | ||
|
||
public function testValidatorWithBadClass(): void | ||
{ | ||
$violations = $this->validate(new DummyUser()); | ||
$this->assertEmpty($violations); | ||
} | ||
|
||
public function testValidatorNotEnabledTermsVersion(): void | ||
{ | ||
$terms = new Terms(); | ||
$termsVersion = new TermsVersion(); | ||
$termsVersion->setTerms($terms); | ||
$termsVersion->setContent('Old content'); | ||
|
||
$model = new TermsEdition($termsVersion); | ||
$model->setContent('New Content'); | ||
|
||
$violations = $this->validate($model); | ||
$this->assertEmpty($violations); | ||
} | ||
|
||
public function testValidatorEnabledTermsVersionContentNotChange(): void | ||
{ | ||
$terms = new Terms(); | ||
$termsVersion = new TermsVersion(); | ||
$termsVersion->setTerms($terms); | ||
$termsVersion->setContent('Old content'); | ||
$termsVersion->enable(); | ||
|
||
$model = new TermsEdition($termsVersion); | ||
$model->setContent('Old content'); | ||
|
||
$violations = $this->validate($model); | ||
$this->assertEmpty($violations); | ||
} | ||
|
||
public function testValidatorEnabledTermsVersionContentChange(): void | ||
{ | ||
$terms = new Terms(); | ||
$termsVersion = new TermsVersion(); | ||
$termsVersion->setTerms($terms); | ||
$termsVersion->setContent('Old content'); | ||
$termsVersion->enable(); | ||
|
||
$model = new TermsEdition($termsVersion); | ||
$model->setContent('New content'); | ||
|
||
$violations = $this->validate($model); | ||
|
||
$this->assertCount(1, $violations); | ||
$this->assertSame('The content cannot be changed when the version is published.', $violations[0]->getMessage()); | ||
$this->assertSame('content', $violations[0]->getPropertyPath()); | ||
} | ||
} |
Oops, something went wrong.