tissue/tests/Unit/Utilities/FormatterTest.php

100 lines
3.0 KiB
PHP
Raw Normal View History

2019-01-19 02:17:49 +09:00
<?php
namespace Tests\Unit\Utilities;
use App\Utilities\Formatter;
use Tests\TestCase;
class FormatterTest extends TestCase
{
public function testNormalizeUrlWithoutQuery()
{
$formatter = new Formatter();
$url = 'http://example.com/path/to';
$this->assertEquals($url, $formatter->normalizeUrl($url));
}
public function testNormalizeUrlWithSortedQuery()
{
$formatter = new Formatter();
$url = 'http://example.com/path/to?foo=bar&hoge=fuga';
$this->assertEquals($url, $formatter->normalizeUrl($url));
}
public function testNormalizeUrlWithUnsortedQuery()
{
$formatter = new Formatter();
$url = 'http://example.com/path/to?hoge=fuga&foo=bar';
$this->assertEquals('http://example.com/path/to?foo=bar&hoge=fuga', $formatter->normalizeUrl($url));
}
public function testNormalizeUrlWithSortedQueryAndFragment()
{
$formatter = new Formatter();
$url = 'http://example.com/path/to?foo=bar&hoge=fuga#fragment';
$this->assertEquals($url, $formatter->normalizeUrl($url));
}
public function testNormalizeUrlWithFragment()
{
$formatter = new Formatter();
$url = 'http://example.com/path/to#fragment';
$this->assertEquals($url, $formatter->normalizeUrl($url));
}
public function testNormalizeUrlWithSortedQueryAndZeroLengthFragment()
{
$formatter = new Formatter();
$url = 'http://example.com/path/to?foo=bar&hoge=fuga#';
$this->assertEquals('http://example.com/path/to?foo=bar&hoge=fuga', $formatter->normalizeUrl($url));
}
2020-01-29 03:41:14 +09:00
public function testProfileImageSrcSet()
{
$formatter = new Formatter();
$profileImageProvider = new class() {
public function getProfileImageUrl(int $size)
{
return "https://example.com/$size.png";
}
};
$this->assertSame(
'https://example.com/128.png 1x,https://example.com/256.png 2x',
$formatter->profileImageSrcSet($profileImageProvider, 128, 2)
);
}
2020-07-31 23:10:54 +09:00
/**
* @dataProvider provideNormalizeTagName
*/
public function testNormalizeTagName($input, $expected)
{
$formatter = new Formatter();
$normalized = $formatter->normalizeTagName($input);
$this->assertSame($expected, $normalized);
$this->assertSame($expected, $formatter->normalizeTagName($normalized));
}
public function provideNormalizeTagName()
{
return [
'LowerCase' => ['example', 'example'],
'UpperCase' => ['EXAMPLE', 'example'],
'HalfWidthKana' => ['ティッシュ', 'ティッシュ'],
'FullWidthAlphabet' => ['', 'tissue'],
'組み文字1' => ['13㎝', '13cm'],
'組み文字2' => ['13㌢㍍', '13センチメートル'],
'Script' => ['ℬ𝒶𝒷𝓊𝓂𝒾', 'babumi'],
2020-07-31 23:19:35 +09:00
'NFD' => ['オカズ', 'オカズ'],
2020-07-31 23:10:54 +09:00
];
}
2019-01-19 03:02:37 +09:00
}