-
Notifications
You must be signed in to change notification settings - Fork 34
[TASK] Add length validation for the model fields #2127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,75 @@ | ||||||
| <?php | ||||||
|
|
||||||
| declare(strict_types=1); | ||||||
|
|
||||||
| namespace TTN\Tea\Tests\Functional\Domain\Model; | ||||||
|
|
||||||
| use PHPUnit\Framework\Attributes\CoversClass; | ||||||
| use PHPUnit\Framework\Attributes\Test; | ||||||
| use TTN\Tea\Domain\Model\Tea; | ||||||
| use TYPO3\CMS\Extbase\Validation\ValidatorResolver; | ||||||
| use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; | ||||||
|
|
||||||
| #[CoversClass(Tea::class)] | ||||||
| final class TeaTest extends FunctionalTestCase | ||||||
| { | ||||||
| protected array $testExtensionsToLoad = ['ttn/tea']; | ||||||
|
|
||||||
| private Tea $subject; | ||||||
|
|
||||||
| protected function setUp(): void | ||||||
| { | ||||||
| parent::setUp(); | ||||||
|
|
||||||
| $this->subject = new Tea(); | ||||||
|
|
||||||
| } | ||||||
|
|
||||||
| #[Test] | ||||||
| public function validTitleLengthReturnsNoError(): void | ||||||
| { | ||||||
| $this->subject->setTitle(str_repeat('p', 255)); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We also should have a test |
||||||
|
|
||||||
| $validatorResolver = $this->getContainer()->get(ValidatorResolver::class); | ||||||
| $validator = $validatorResolver->getBaseValidatorConjunction(Tea::class); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can move these two lines to |
||||||
| $result = $validator->validate($this->subject); | ||||||
| self::assertFalse($result->forProperty('title')->hasErrors()); | ||||||
|
|
||||||
| } | ||||||
|
|
||||||
| #[Test] | ||||||
| public function invalidTitleLengthReturnsError(): void | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| { | ||||||
| $this->subject->setTitle(str_repeat('p', 256)); | ||||||
|
|
||||||
| $validatorResolver = $this->getContainer()->get(ValidatorResolver::class); | ||||||
| $validator = $validatorResolver->getBaseValidatorConjunction(Tea::class); | ||||||
| $result = $validator->validate($this->subject); | ||||||
| self::assertTrue($result->forProperty('title')->hasErrors()); | ||||||
|
|
||||||
| } | ||||||
|
|
||||||
| #[Test] | ||||||
| public function validateDescriptionLengthReturnsNoErrors(): void | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| { | ||||||
| $this->subject->setDescription(str_repeat('d', 2000)); | ||||||
|
|
||||||
| $validatorResolver = $this->getContainer()->get(ValidatorResolver::class); | ||||||
| $validator = $validatorResolver->getBaseValidatorConjunction(Tea::class); | ||||||
| $result = $validator->validate($this->subject); | ||||||
| self::assertFalse($result->forProperty('description')->hasErrors()); | ||||||
|
|
||||||
| } | ||||||
|
|
||||||
| #[Test] | ||||||
| public function invalidDescriptionLengthReturnsError(): void | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| { | ||||||
| $this->subject->setDescription(str_repeat('d', 2001)); | ||||||
|
|
||||||
| $validatorResolver = $this->getContainer()->get(ValidatorResolver::class); | ||||||
| $validator = $validatorResolver->getBaseValidatorConjunction(Tea::class); | ||||||
| $result = $validator->validate($this->subject); | ||||||
| self::assertTrue($result->forProperty('description')->hasErrors()); | ||||||
| } | ||||||
|
|
||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this blank line. |
||||||
| } | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's be more specific: