[TASK] Add length validation for the model fields#2127
Open
hermannatz wants to merge 1 commit into
Open
Conversation
Add functional tests for title and description validation to verify the configured Extbase validators. Resolves: TYPO3BestPractices#458 Releases: main"
ba35c8c to
f8bb3da
Compare
oliverklee
requested changes
May 19, 2026
Contributor
oliverklee
left a comment
There was a problem hiding this comment.
Looks already quite good - thank your for this!
I've added some remarks.
Also, the PR title should read:
[TASK] Add tests for the model property validations
| $this->subject->setTitle(str_repeat('p', 255)); | ||
|
|
||
| $validatorResolver = $this->getContainer()->get(ValidatorResolver::class); | ||
| $validator = $validatorResolver->getBaseValidatorConjunction(Tea::class); |
Contributor
There was a problem hiding this comment.
We can move these two lines to setUp() and make $validator a property to reduce code duplication.
| } | ||
|
|
||
| #[Test] | ||
| public function validTitleLengthReturnsNoError(): void |
Contributor
There was a problem hiding this comment.
Let's be more specific:
Suggested change
| public function validTitleLengthReturnsNoError(): void | |
| public function titleWithMaximumLengthPassesValidation(): void |
| #[Test] | ||
| public function validTitleLengthReturnsNoError(): void | ||
| { | ||
| $this->subject->setTitle(str_repeat('p', 255)); |
Contributor
There was a problem hiding this comment.
We also should have a test emptyTitleDoesNotPassValidation so we also test the NotEmpty validation.
| } | ||
|
|
||
| #[Test] | ||
| public function invalidTitleLengthReturnsError(): void |
Contributor
There was a problem hiding this comment.
Suggested change
| public function invalidTitleLengthReturnsError(): void | |
| public function titleLongerThanMaximumLengthDoesNotPassValidation(): void |
| } | ||
|
|
||
| #[Test] | ||
| public function validateDescriptionLengthReturnsNoErrors(): void |
Contributor
There was a problem hiding this comment.
Suggested change
| public function validateDescriptionLengthReturnsNoErrors(): void | |
| public function titleWithMaximumLengthPassesValidation(): void |
| } | ||
|
|
||
| #[Test] | ||
| public function invalidDescriptionLengthReturnsError(): void |
Contributor
There was a problem hiding this comment.
Suggested change
| public function invalidDescriptionLengthReturnsError(): void | |
| public function descriptionLongerThanMaximumLengthDoesNotPassValidation(): void |
| $result = $validator->validate($this->subject); | ||
| self::assertTrue($result->forProperty('description')->hasErrors()); | ||
| } | ||
|
|
Contributor
There was a problem hiding this comment.
Please remove this blank line.
This was referenced May 19, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add functional tests for title and description validation to verify the configured Extbase validators.
Resolves: #458