mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-11 09:43:13 +08:00
Ensured URL titles are trimmed to avoid error when persisted in database
This commit is contained in:
@@ -11,6 +11,10 @@ use Shlinkio\Shlink\Core\Model\ShortUrlMeta;
|
||||
use Shlinkio\Shlink\Core\Validation\ShortUrlInputFilter;
|
||||
use stdClass;
|
||||
|
||||
use function str_pad;
|
||||
|
||||
use const STR_PAD_BOTH;
|
||||
|
||||
class ShortUrlMetaTest extends TestCase
|
||||
{
|
||||
/**
|
||||
@@ -99,4 +103,28 @@ class ShortUrlMetaTest extends TestCase
|
||||
yield ['谷歌', '谷歌'];
|
||||
yield ['гугл', 'гугл'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider provideTitles
|
||||
*/
|
||||
public function titleIsCroppedIfTooLong(?string $title, ?string $expectedTitle): void
|
||||
{
|
||||
$meta = ShortUrlMeta::fromRawData([
|
||||
'title' => $title,
|
||||
'longUrl' => '',
|
||||
]);
|
||||
|
||||
self::assertEquals($expectedTitle, $meta->getTitle());
|
||||
}
|
||||
|
||||
public function provideTitles(): iterable
|
||||
{
|
||||
yield [null, null];
|
||||
yield ['foo', 'foo'];
|
||||
yield [str_pad('bar', 600, ' ', STR_PAD_BOTH), 'bar'];
|
||||
yield [str_pad('', 512, 'a'), str_pad('', 512, 'a')];
|
||||
yield [str_pad('', 600, 'b'), str_pad('', 512, 'b')];
|
||||
yield [str_pad('', 800, 'b'), str_pad('', 512, 'b')];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user