|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace SlackPhp\BlockKit\Tests\Partials; |
| 6 | + |
| 7 | +use SlackPhp\BlockKit\Exception; |
| 8 | +use SlackPhp\BlockKit\Partials\Text; |
| 9 | +use SlackPhp\BlockKit\Tests\TestCase; |
| 10 | + |
| 11 | +/** |
| 12 | + * @covers \SlackPhp\BlockKit\Partials\Text |
| 13 | + */ |
| 14 | +class TextTest extends TestCase |
| 15 | +{ |
| 16 | + private const MAX_LENGTH = 5; |
| 17 | + private const MIN_LENGTH = 2; |
| 18 | + |
| 19 | + public function testCanValidateEnglishText() |
| 20 | + { |
| 21 | + $text = new class () extends Text { |
| 22 | + }; |
| 23 | + |
| 24 | + $text->validateString('abc', self::MAX_LENGTH); |
| 25 | + |
| 26 | + $this->expectException(Exception::class); |
| 27 | + |
| 28 | + $this->expectExceptionMessage('Text element must have a "text" value with a length of at most 5'); |
| 29 | + $text->validateString('abcdefg', self::MAX_LENGTH); |
| 30 | + |
| 31 | + $this->expectExceptionMessage('Text element must have a "text" value with a length of at least 2'); |
| 32 | + $text->validateString('a', self::MAX_LENGTH, self::MIN_LENGTH); |
| 33 | + } |
| 34 | + |
| 35 | + public function testCanValidateJapaneseText() |
| 36 | + { |
| 37 | + $text = new class () extends Text { |
| 38 | + }; |
| 39 | + |
| 40 | + $text->validateString('いろは', self::MAX_LENGTH); |
| 41 | + |
| 42 | + $this->expectException(Exception::class); |
| 43 | + |
| 44 | + $this->expectExceptionMessage('Text element must have a "text" value with a length of at most 5'); |
| 45 | + $text->validateString('いろはにほへと', self::MAX_LENGTH); |
| 46 | + |
| 47 | + $this->expectExceptionMessage('Text element must have a "text" value with a length of at least 2'); |
| 48 | + $text->validateString('い', self::MAX_LENGTH, self::MIN_LENGTH); |
| 49 | + } |
| 50 | +} |
0 commit comments