mirror of https://github.com/FriendsOfTYPO3/tea.git synced 2024-11-09 23:56:14 +01:00

[FEATURE] Add length validation for the model fields

resolves https://github.com/TYPO3-Documentation/tea/issues/458
This commit is contained in:
lina.wolf 2022-10-20 14:44:32 +00:00
parent 0fa4cfe8d9
commit e6647b4000
2 changed files with 27 additions and 0 deletions

View file

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace TTN\Tea\Domain\Model\Product; namespace TTN\Tea\Domain\Model\Product;
use TYPO3\CMS\Extbase\Annotation\ORM\Lazy; use TYPO3\CMS\Extbase\Annotation\ORM\Lazy;
use TYPO3\CMS\Extbase\Annotation\Validate;
use TYPO3\CMS\Extbase\Domain\Model\FileReference; use TYPO3\CMS\Extbase\Domain\Model\FileReference;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity; use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
use TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy; use TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy;
@ -30,6 +31,9 @@ class Tea extends AbstractEntity
return $this->title; return $this->title;
} }
/**
* @Validate("StringLength", options={"maximum": 255})
*/
public function setTitle(string $title): void public function setTitle(string $title): void
{ {
$this->title = $title; $this->title = $title;
@ -40,6 +44,9 @@ class Tea extends AbstractEntity
return $this->description; return $this->description;
} }
/**
* @Validate("StringLength", options={"maximum": 2000})
*/
public function setDescription(string $description): void public function setDescription(string $description): void
{ {
$this->description = $description; $this->description = $description;

View file

@ -101,4 +101,24 @@ class TeaControllerTest extends UnitTestCase
$this->subject->showAction($tea) $this->subject->showAction($tea)
); );
} }
/**
* @test
*/
public function showActionWithOverlongTeaTitleCallsErrorAction(): void
{
$tea = new Tea();
$stringLength256 = 'Lorem ipsum dolor sit amet, consetetur sadipscing '
.'elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore'
.' magna aliquyam erat, sed diam voluptua. At vero eos et accusam'
.' et justo duo dolores et ea rebum. Stet clita kasd gubergren, '
.'no sea takimata xxx';
$tea->setTitle($stringLength256);
self::assertEquals(
400,
$this->subject->showAction($tea)->getStatusCode(),
);
}
} }