Skip to content

[TASK] Add length validation for the model fields#2127

Open
hermannatz wants to merge 1 commit into
TYPO3BestPractices:mainfrom
hermannatz:feature/458-add-length-validation-model-fields
Open

[TASK] Add length validation for the model fields#2127
hermannatz wants to merge 1 commit into
TYPO3BestPractices:mainfrom
hermannatz:feature/458-add-length-validation-model-fields

Conversation

@hermannatz
Copy link
Copy Markdown

@hermannatz hermannatz commented May 14, 2026

Add functional tests for title and description validation to verify the configured Extbase validators.

Resolves: #458

@oliverklee oliverklee added the enhancement New feature or request label May 14, 2026
@oliverklee oliverklee added this to the 4.1.0 milestone May 14, 2026
Add functional tests for title and description validation
to verify the configured Extbase validators.

Resolves: TYPO3BestPractices#458
Releases: main"
@oliverklee oliverklee force-pushed the feature/458-add-length-validation-model-fields branch from ba35c8c to f8bb3da Compare May 19, 2026 07:34
Copy link
Copy Markdown
Contributor

@oliverklee oliverklee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can move these two lines to setUp() and make $validator a property to reduce code duplication.

}

#[Test]
public function validTitleLengthReturnsNoError(): void
Copy link
Copy Markdown
Contributor

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:

Suggested change
public function validTitleLengthReturnsNoError(): void
public function titleWithMaximumLengthPassesValidation(): void

#[Test]
public function validTitleLengthReturnsNoError(): void
{
$this->subject->setTitle(str_repeat('p', 255));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also should have a test emptyTitleDoesNotPassValidation so we also test the NotEmpty validation.

}

#[Test]
public function invalidTitleLengthReturnsError(): void
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function invalidTitleLengthReturnsError(): void
public function titleLongerThanMaximumLengthDoesNotPassValidation(): void

}

#[Test]
public function validateDescriptionLengthReturnsNoErrors(): void
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function validateDescriptionLengthReturnsNoErrors(): void
public function titleWithMaximumLengthPassesValidation(): void

}

#[Test]
public function invalidDescriptionLengthReturnsError(): void
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function invalidDescriptionLengthReturnsError(): void
public function descriptionLongerThanMaximumLengthDoesNotPassValidation(): void

$result = $validator->validate($this->subject);
self::assertTrue($result->forProperty('description')->hasErrors());
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this blank line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add length validation for the model fields

2 participants