TextTest.php 100 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  5. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  6. *
  7. * Licensed under The MIT License
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  11. * @link https://cakephp.org CakePHP(tm) Project
  12. * @since 1.2.0
  13. * @license https://opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\Utility;
  16. use Cake\I18n\DateTime;
  17. use Cake\TestSuite\TestCase;
  18. use Cake\Utility\Text;
  19. use InvalidArgumentException;
  20. use PHPUnit\Framework\Attributes\DataProvider;
  21. use ReflectionMethod;
  22. use Transliterator;
  23. /**
  24. * TextTest class
  25. */
  26. class TextTest extends TestCase
  27. {
  28. /**
  29. * @var \Cake\Utility\Text
  30. */
  31. protected $Text;
  32. /**
  33. * @var string
  34. */
  35. protected $encoding;
  36. public function setUp(): void
  37. {
  38. parent::setUp();
  39. $this->encoding = mb_internal_encoding();
  40. $this->Text = new Text();
  41. }
  42. public function tearDown(): void
  43. {
  44. parent::tearDown();
  45. mb_internal_encoding($this->encoding);
  46. unset($this->Text);
  47. }
  48. /**
  49. * testUuidGeneration method
  50. */
  51. public function testUuidGeneration(): void
  52. {
  53. $result = Text::uuid();
  54. $pattern = '/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/';
  55. $match = (bool)preg_match($pattern, $result);
  56. $this->assertTrue($match);
  57. }
  58. /**
  59. * testMultipleUuidGeneration method
  60. */
  61. public function testMultipleUuidGeneration(): void
  62. {
  63. $check = [];
  64. $count = mt_rand(10, 1000);
  65. $pattern = '/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/';
  66. for ($i = 0; $i < $count; $i++) {
  67. $result = Text::uuid();
  68. $match = (bool)preg_match($pattern, $result);
  69. $this->assertTrue($match);
  70. $this->assertNotContains($result, $check);
  71. $check[] = $result;
  72. }
  73. }
  74. /**
  75. * testInsert method
  76. */
  77. public function testInsert(): void
  78. {
  79. $string = 'some string';
  80. $expected = 'some string';
  81. $result = Text::insert($string, []);
  82. $this->assertSame($expected, $result);
  83. $string = '2 + 2 = :sum. Cake is :adjective.';
  84. $expected = '2 + 2 = 4. Cake is yummy.';
  85. $result = Text::insert($string, ['sum' => '4', 'adjective' => 'yummy']);
  86. $this->assertSame($expected, $result);
  87. $string = '2 + 2 = %sum. Cake is %adjective.';
  88. $result = Text::insert($string, ['sum' => '4', 'adjective' => 'yummy'], ['before' => '%']);
  89. $this->assertSame($expected, $result);
  90. $string = '2 + 2 = 2sum2. Cake is 9adjective9.';
  91. $result = Text::insert($string, ['sum' => '4', 'adjective' => 'yummy'], ['format' => '/([\d])%s\\1/']);
  92. $this->assertSame($expected, $result);
  93. $string = '2 + 2 = 12sum21. Cake is 23adjective45.';
  94. $expected = '2 + 2 = 4. Cake is 23adjective45.';
  95. $result = Text::insert($string, ['sum' => '4', 'adjective' => 'yummy'], ['format' => '/([\d])([\d])%s\\2\\1/']);
  96. $this->assertSame($expected, $result);
  97. $string = ':web :web_site';
  98. $expected = 'www http';
  99. $result = Text::insert($string, ['web' => 'www', 'web_site' => 'http']);
  100. $this->assertSame($expected, $result);
  101. $string = '2 + 2 = <sum. Cake is <adjective>.';
  102. $expected = '2 + 2 = <sum. Cake is yummy.';
  103. $result = Text::insert($string, ['sum' => '4', 'adjective' => 'yummy'], ['before' => '<', 'after' => '>']);
  104. $this->assertSame($expected, $result);
  105. $string = '2 + 2 = \:sum. Cake is :adjective.';
  106. $expected = '2 + 2 = :sum. Cake is yummy.';
  107. $result = Text::insert($string, ['sum' => '4', 'adjective' => 'yummy']);
  108. $this->assertSame($expected, $result);
  109. $string = '2 + 2 = !:sum. Cake is :adjective.';
  110. $result = Text::insert($string, ['sum' => '4', 'adjective' => 'yummy'], ['escape' => '!']);
  111. $this->assertSame($expected, $result);
  112. $string = '2 + 2 = \%sum. Cake is %adjective.';
  113. $expected = '2 + 2 = %sum. Cake is yummy.';
  114. $result = Text::insert($string, ['sum' => '4', 'adjective' => 'yummy'], ['before' => '%']);
  115. $this->assertSame($expected, $result);
  116. $string = ':a :b \:a :a';
  117. $expected = '1 2 :a 1';
  118. $result = Text::insert($string, ['a' => 1, 'b' => 2]);
  119. $this->assertSame($expected, $result);
  120. $string = ':a :b :c';
  121. $expected = '2 3';
  122. $result = Text::insert($string, ['b' => 2, 'c' => 3], ['clean' => true]);
  123. $this->assertSame($expected, $result);
  124. $string = ':a :b :c';
  125. $expected = '1 3';
  126. $result = Text::insert($string, ['a' => 1, 'c' => 3], ['clean' => true]);
  127. $this->assertSame($expected, $result);
  128. $string = ':a :b :c';
  129. $expected = '2 3';
  130. $result = Text::insert($string, ['b' => 2, 'c' => 3], ['clean' => true]);
  131. $this->assertSame($expected, $result);
  132. $string = ':a, :b and :c';
  133. $expected = '2 and 3';
  134. $result = Text::insert($string, ['b' => 2, 'c' => 3], ['clean' => true]);
  135. $this->assertSame($expected, $result);
  136. $string = '":a, :b and :c"';
  137. $expected = '"1, 2"';
  138. $result = Text::insert($string, ['a' => 1, 'b' => 2], ['clean' => true]);
  139. $this->assertSame($expected, $result);
  140. $string = '"${a}, ${b} and ${c}"';
  141. $expected = '"1, 2"';
  142. $result = Text::insert($string, ['a' => 1, 'b' => 2], ['before' => '${', 'after' => '}', 'clean' => true]);
  143. $this->assertSame($expected, $result);
  144. $string = '<img src=":src" alt=":alt" class="foo :extra bar"/>';
  145. $expected = '<img src="foo" class="foo bar"/>';
  146. $result = Text::insert($string, ['src' => 'foo'], ['clean' => 'html']);
  147. $this->assertSame($expected, $result);
  148. $string = '<img src=":src" class=":no :extra"/>';
  149. $expected = '<img src="foo"/>';
  150. $result = Text::insert($string, ['src' => 'foo'], ['clean' => 'html']);
  151. $this->assertSame($expected, $result);
  152. $string = '<img src=":src" class=":no :extra"/>';
  153. $expected = '<img src="foo" class="bar"/>';
  154. $result = Text::insert($string, ['src' => 'foo', 'extra' => 'bar'], ['clean' => 'html']);
  155. $this->assertSame($expected, $result);
  156. $result = Text::insert('update saved_urls set url = :url where id = :id', ['url' => 'http://www.testurl.com/param1:url/param2:id', 'id' => 1]);
  157. $expected = 'update saved_urls set url = http://www.testurl.com/param1:url/param2:id where id = 1';
  158. $this->assertSame($expected, $result);
  159. $result = Text::insert('update saved_urls set url = :url where id = :id', ['id' => 1, 'url' => 'http://www.testurl.com/param1:url/param2:id']);
  160. $expected = 'update saved_urls set url = http://www.testurl.com/param1:url/param2:id where id = 1';
  161. $this->assertSame($expected, $result);
  162. $result = Text::insert(':me cake. :subject :verb fantastic.', ['me' => 'I :verb', 'subject' => 'cake', 'verb' => 'is']);
  163. $expected = 'I :verb cake. cake is fantastic.';
  164. $this->assertSame($expected, $result);
  165. $result = Text::insert(':I.am: :not.yet: passing.', ['I.am' => 'We are'], ['before' => ':', 'after' => ':', 'clean' => ['replacement' => ' of course', 'method' => 'text']]);
  166. $expected = 'We are of course passing.';
  167. $this->assertSame($expected, $result);
  168. $result = Text::insert(
  169. ':I.am: :not.yet: passing.',
  170. ['I.am' => 'We are'],
  171. ['before' => ':', 'after' => ':', 'clean' => true]
  172. );
  173. $expected = 'We are passing.';
  174. $this->assertSame($expected, $result);
  175. $string = 'switching :timeout / :timeout_count';
  176. $expected = 'switching 5 / 10';
  177. $result = Text::insert($string, ['timeout' => 5, 'timeout_count' => 10]);
  178. $this->assertSame($expected, $result);
  179. $string = 'switching :timeout / :timeout_count';
  180. $expected = 'switching 5 / 10';
  181. $result = Text::insert($string, ['timeout_count' => 10, 'timeout' => 5]);
  182. $this->assertSame($expected, $result);
  183. $string = 'switching :timeout_count by :timeout';
  184. $expected = 'switching 10 by 5';
  185. $result = Text::insert($string, ['timeout' => 5, 'timeout_count' => 10]);
  186. $this->assertSame($expected, $result);
  187. $string = 'switching :timeout_count by :timeout';
  188. $expected = 'switching 10 by 5';
  189. $result = Text::insert($string, ['timeout_count' => 10, 'timeout' => 5]);
  190. $this->assertSame($expected, $result);
  191. $string = 'inserting a :user.email';
  192. $expected = 'inserting a security@example.com';
  193. $result = Text::insert($string, [
  194. 'user.email' => 'security@example.com',
  195. 'user.id' => 2,
  196. 'user.created' => DateTime::parse('2016-01-01'),
  197. ]);
  198. $this->assertSame($expected, $result);
  199. $string = 'Sum is :sum (:ob).';
  200. $expected = 'Sum is 26083 (foo).';
  201. $result = Text::insert($string, ['sum' => 26083, 'ob' => 'foo']); // crc32('ob') = 26083
  202. $this->assertSame($expected, $result);
  203. }
  204. /**
  205. * test Clean Insert
  206. */
  207. public function testCleanInsert(): void
  208. {
  209. $result = Text::cleanInsert(':incomplete', [
  210. 'clean' => true, 'before' => ':', 'after' => '',
  211. ]);
  212. $this->assertSame('', $result);
  213. $result = Text::cleanInsert(
  214. ':incomplete',
  215. [
  216. 'clean' => ['method' => 'text', 'replacement' => 'complete'],
  217. 'before' => ':', 'after' => '']
  218. );
  219. $this->assertSame('complete', $result);
  220. $result = Text::cleanInsert(':in.complete', [
  221. 'clean' => true, 'before' => ':', 'after' => '',
  222. ]);
  223. $this->assertSame('', $result);
  224. $result = Text::cleanInsert(
  225. ':in.complete and',
  226. [
  227. 'clean' => true, 'before' => ':', 'after' => '']
  228. );
  229. $this->assertSame('', $result);
  230. $result = Text::cleanInsert(':in.complete or stuff', [
  231. 'clean' => true, 'before' => ':', 'after' => '',
  232. ]);
  233. $this->assertSame('stuff', $result);
  234. $result = Text::cleanInsert(
  235. '<p class=":missing" id=":missing">Text here</p>',
  236. ['clean' => 'html', 'before' => ':', 'after' => '']
  237. );
  238. $this->assertSame('<p>Text here</p>', $result);
  239. }
  240. /**
  241. * Tests that non-insertable variables (i.e. arrays) are skipped when used as values in
  242. * Text::insert().
  243. */
  244. public function testAutoIgnoreBadInsertData(): void
  245. {
  246. $data = ['foo' => 'alpha', 'bar' => 'beta', 'fale' => []];
  247. $result = Text::insert('(:foo > :bar || :fale!)', $data, ['clean' => 'text']);
  248. $this->assertSame('(alpha > beta || !)', $result);
  249. }
  250. /**
  251. * testTokenize method
  252. */
  253. public function testTokenize(): void
  254. {
  255. $result = Text::tokenize('A,(short,boring test)');
  256. $expected = ['A', '(short,boring test)'];
  257. $this->assertSame($expected, $result);
  258. $result = Text::tokenize('A,(short,more interesting( test)');
  259. $expected = ['A', '(short,more interesting( test)'];
  260. $this->assertSame($expected, $result);
  261. $result = Text::tokenize('A,(short,very interesting( test))');
  262. $expected = ['A', '(short,very interesting( test))'];
  263. $this->assertSame($expected, $result);
  264. $result = Text::tokenize('"single tag"', ' ', '"', '"');
  265. $expected = ['"single tag"'];
  266. $this->assertSame($expected, $result);
  267. $result = Text::tokenize('tagA "single tag" tagB', ' ', '"', '"');
  268. $expected = ['tagA', '"single tag"', 'tagB'];
  269. $this->assertSame($expected, $result);
  270. $result = Text::tokenize('tagA "first tag" tagB "second tag" tagC', ' ', '"', '"');
  271. $expected = ['tagA', '"first tag"', 'tagB', '"second tag"', 'tagC'];
  272. $this->assertSame($expected, $result);
  273. // Ideographic width space.
  274. $result = Text::tokenize("tagA\xe3\x80\x80\"single\xe3\x80\x80tag\"\xe3\x80\x80tagB", "\xe3\x80\x80", '"', '"');
  275. $expected = ['tagA', '"single tag"', 'tagB'];
  276. $this->assertSame($expected, $result);
  277. }
  278. public function testReplaceWithQuestionMarkInString(): void
  279. {
  280. $string = ':a, :b and :c?';
  281. $expected = '2 and 3?';
  282. $result = Text::insert($string, ['b' => 2, 'c' => 3], ['clean' => true]);
  283. $this->assertSame($expected, $result);
  284. }
  285. /**
  286. * test that wordWrap() works the same as built-in wordwrap function
  287. */
  288. #[DataProvider('wordWrapProvider')]
  289. public function testWordWrap(string $text, int $width, string $break = "\n", bool $cut = false): void
  290. {
  291. $result = Text::wordWrap($text, $width, $break, $cut);
  292. $expected = wordwrap($text, $width, $break, $cut);
  293. $this->assertTextEquals($expected, $result, 'Text not wrapped same as built-in function.');
  294. }
  295. /**
  296. * data provider for testWordWrap method
  297. *
  298. * @return array
  299. */
  300. public static function wordWrapProvider(): array
  301. {
  302. return [
  303. [
  304. 'The quick brown fox jumped over the lazy dog.',
  305. 33,
  306. ],
  307. [
  308. 'A very long woooooooooooord.',
  309. 8,
  310. ],
  311. [
  312. 'A very long woooooooooooord. Right.',
  313. 8,
  314. ],
  315. ];
  316. }
  317. /**
  318. * test that wordWrap() properly handle unicode strings.
  319. */
  320. public function testWordWrapUnicodeAware(): void
  321. {
  322. $text = 'Но вим омниюм факёльиси элыктрам, мюнырэ лэгыры векж ыт. Выльёт квюандо нюмквуам ты кюм. Зыд эю рыбюм.';
  323. $result = Text::wordWrap($text, 33, "\n", true);
  324. $expected = <<<TEXT
  325. Но вим омниюм факёльиси элыктрам,
  326. мюнырэ лэгыры векж ыт. Выльёт квю
  327. андо нюмквуам ты кюм. Зыд эю рыбю
  328. м.
  329. TEXT;
  330. $this->assertTextEquals($expected, $result, 'Text not wrapped.');
  331. $text = 'Но вим омниюм факёльиси элыктрам, мюнырэ лэгыры векж ыт. Выльёт квюандо нюмквуам ты кюм. Зыд эю рыбюм.';
  332. $result = Text::wordWrap($text, 33, "\n");
  333. $expected = <<<TEXT
  334. Но вим омниюм факёльиси элыктрам,
  335. мюнырэ лэгыры векж ыт. Выльёт
  336. квюандо нюмквуам ты кюм. Зыд эю
  337. рыбюм.
  338. TEXT;
  339. $this->assertTextEquals($expected, $result, 'Text not wrapped.');
  340. }
  341. /**
  342. * test that wordWrap() properly handle newline characters.
  343. */
  344. public function testWordWrapNewlineAware(): void
  345. {
  346. $text = 'This is a line that is almost the 55 chars long.
  347. This is a new sentence which is manually newlined, but is so long it needs two lines.';
  348. $result = Text::wordWrap($text, 55);
  349. $expected = <<<TEXT
  350. This is a line that is almost the 55 chars long.
  351. This is a new sentence which is manually newlined, but
  352. is so long it needs two lines.
  353. TEXT;
  354. $this->assertTextEquals($expected, $result, 'Text not wrapped.');
  355. }
  356. /**
  357. * test wrap method.
  358. */
  359. public function testWrap(): void
  360. {
  361. $text = 'This is the song that never ends. This is the song that never ends. This is the song that never ends.';
  362. $result = Text::wrap($text, 33);
  363. $expected = <<<TEXT
  364. This is the song that never ends.
  365. This is the song that never ends.
  366. This is the song that never ends.
  367. TEXT;
  368. $this->assertTextEquals($expected, $result, 'Text not wrapped.');
  369. $result = Text::wrap($text, ['width' => 20, 'wordWrap' => false]);
  370. $expected = 'This is the song th' . "\n" .
  371. 'at never ends. This' . "\n" .
  372. ' is the song that n' . "\n" .
  373. 'ever ends. This is ' . "\n" .
  374. 'the song that never' . "\n" .
  375. ' ends.';
  376. $this->assertTextEquals($expected, $result, 'Text not wrapped.');
  377. }
  378. /**
  379. * test wrap() indenting
  380. */
  381. public function testWrapIndent(): void
  382. {
  383. $text = 'This is the song that never ends. This is the song that never ends. This is the song that never ends.';
  384. $result = Text::wrap($text, ['width' => 33, 'indent' => "\t", 'indentAt' => 1]);
  385. $expected = <<<TEXT
  386. This is the song that never ends.
  387. This is the song that never ends.
  388. This is the song that never ends.
  389. TEXT;
  390. $this->assertTextEquals($expected, $result);
  391. }
  392. /**
  393. * test wrapBlock() identical to wrap()
  394. */
  395. public function testWrapBlockIndenticalToWrap(): void
  396. {
  397. $text = 'This is the song that never ends. This is the song that never ends. This is the song that never ends.';
  398. $result = Text::wrapBlock($text, 33);
  399. $expected = Text::wrap($text, 33);
  400. $this->assertTextEquals($expected, $result);
  401. $result = Text::wrapBlock($text, ['width' => 33, 'indentAt' => 0]);
  402. $expected = Text::wrap($text, ['width' => 33, 'indentAt' => 0]);
  403. $this->assertTextEquals($expected, $result);
  404. }
  405. /**
  406. * test wrapBlock() indenting from first line
  407. */
  408. public function testWrapBlockWithIndentAt0(): void
  409. {
  410. $text = 'This is the song that never ends. This is the song that never ends. This is the song that never ends.';
  411. $result = Text::wrapBlock($text, ['width' => 33, 'indent' => "\t", 'indentAt' => 0]);
  412. $expected = <<<TEXT
  413. This is the song that never
  414. ends. This is the song that
  415. never ends. This is the song
  416. that never ends.
  417. TEXT;
  418. $this->assertTextEquals($expected, $result);
  419. }
  420. /**
  421. * test wrapBlock() indenting from second line
  422. */
  423. public function testWrapBlockWithIndentAt1(): void
  424. {
  425. $text = 'This is the song that never ends. This is the song that never ends. This is the song that never ends.';
  426. $result = Text::wrapBlock($text, ['width' => 33, 'indent' => "\t", 'indentAt' => 1]);
  427. $expected = <<<TEXT
  428. This is the song that never ends.
  429. This is the song that never
  430. ends. This is the song that
  431. never ends.
  432. TEXT;
  433. $this->assertTextEquals($expected, $result);
  434. }
  435. /**
  436. * test wrapBlock() indenting with multibyte caracters
  437. */
  438. public function testWrapBlockIndentWithMultibyte(): void
  439. {
  440. $text = 'This is the song that never ends. 这是永远不会结束的歌曲。 This is the song that never ends.';
  441. $result = Text::wrapBlock($text, ['width' => 33, 'indent' => ' → ', 'indentAt' => 1]);
  442. $expected = <<<TEXT
  443. This is the song that never ends.
  444. → 这是永远不会结束的歌曲。 This is the song
  445. → that never ends.
  446. TEXT;
  447. $this->assertTextEquals($expected, $result);
  448. }
  449. /**
  450. * test isMultibyte() checking multibyte characters
  451. */
  452. public function testIsMultibyteString(): void
  453. {
  454. $text = 'This is a test string without multi-bytes';
  455. $result = Text::isMultibyte($text);
  456. $this->assertFalse($result);
  457. $text = 'This is a test string with multi-bytes 这是永远不会结束的歌曲';
  458. $result = Text::isMultibyte($text);
  459. $this->assertTrue($result);
  460. }
  461. /**
  462. * testTruncate method
  463. */
  464. public function testTruncate(): void
  465. {
  466. $text1 = 'The quick brown fox jumps over the lazy dog';
  467. $text2 = 'Heiz&ouml;lr&uuml;cksto&szlig;abd&auml;mpfung';
  468. $text3 = '<b>&copy; 2005-2007, Cake Software Foundation, Inc.</b><br />written by Alexander Wegener';
  469. $text4 = '<IMG src="mypic.jpg"> This image tag is not XHTML conform!<br><hr/><b>But the following image tag should be conform <img src="mypic.jpg" alt="Me, myself and I" /></b><br />Great, or?';
  470. $text5 = '0<b>1<i>2<span class="myclass">3</span>4<u>5</u>6</i>7</b>8<b>9</b>0';
  471. $text6 = "<p><strong>Extra dates have been announced for this year's tour.</strong></p><p>Tickets for the new shows in</p>";
  472. $text7 = 'El moño está en el lugar correcto. Eso fue lo que dijo la niña, ¿habrá dicho la verdad?';
  473. $text8 = 'Vive la R' . chr(195) . chr(169) . 'publique de France';
  474. $text9 = 'НОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
  475. $text10 = 'http://example.com/something/foo:bar';
  476. $this->assertSame('H…', $this->Text->truncate('Hello', 2));
  477. $this->assertSame('Hel…', $this->Text->truncate('Hello', 3, ['exact' => false]));
  478. $this->assertSame('The quick brow…', $this->Text->truncate($text1, 15));
  479. $this->assertSame('The quick…', $this->Text->truncate($text1, 15, ['exact' => false]));
  480. $this->assertSame('The quick brown fox jumps over the lazy dog', $this->Text->truncate($text1, 100));
  481. $this->assertSame('Heiz&ouml…', $this->Text->truncate($text2, 10));
  482. $this->assertSame('Heiz&ouml;…', $this->Text->truncate($text2, 10, ['exact' => false]));
  483. $this->assertSame('<b>&copy; 2005-2007…', $this->Text->truncate($text3, 20));
  484. $this->assertSame('<IMG src="mypi…', $this->Text->truncate($text4, 15));
  485. $this->assertSame('0<b>1<', $this->Text->truncate($text5, 6, ['ellipsis' => '']));
  486. $this->assertSame("The quick brow\xe2\x80\xa6", $this->Text->truncate($text1, 15, ['html' => true]));
  487. $this->assertSame("The quick\xe2\x80\xa6", $this->Text->truncate($text1, 15, ['exact' => false, 'html' => true]));
  488. $this->assertSame("Heiz&ouml;lr&uuml;c\xe2\x80\xa6", $this->Text->truncate($text2, 10, ['html' => true]));
  489. $this->assertSame("Heiz&ouml;lr&uuml;ck\xe2\x80\xa6", $this->Text->truncate($text2, 10, ['exact' => false, 'html' => true]));
  490. $this->assertSame("<b>&copy; 2005-2007, Cake S\xe2\x80\xa6</b>", $this->Text->truncate($text3, 20, ['html' => true]));
  491. $this->assertSame("<IMG src=\"mypic.jpg\"> This image ta\xe2\x80\xa6", $this->Text->truncate($text4, 15, ['html' => true]));
  492. $this->assertSame("<IMG src=\"mypic.jpg\"> This image tag is not XHTML conform!<br><hr/><b>But the\xe2\x80\xa6</b>", $this->Text->truncate($text4, 45, ['html' => true]));
  493. $this->assertSame('<IMG src="mypic.jpg"> This image tag is not XHTML conform!<br><hr/><b>But the following image tag should be conform <img src="mypic.jpg" alt="Me, myself and I" /></b><br />Great,' . "\xe2\x80\xa6", $this->Text->truncate($text4, 90, ['html' => true]));
  494. $this->assertSame('0<b>1<i>2<span class="myclass">3</span>4<u>5</u></i></b>', $this->Text->truncate($text5, 6, ['ellipsis' => '', 'html' => true]));
  495. $this->assertSame($text5, $this->Text->truncate($text5, 20, ['ellipsis' => '', 'html' => true]));
  496. $this->assertSame("<p><strong>Extra dates have been announced for this year's\xe2\x80\xa6</strong></p>", $this->Text->truncate($text6, 48, ['exact' => false, 'html' => true]));
  497. $this->assertSame($text7, $this->Text->truncate($text7, 255));
  498. $this->assertSame('El moño está e…', $this->Text->truncate($text7, 15));
  499. $this->assertSame('Vive la R' . chr(195) . chr(169) . 'publ…', $this->Text->truncate($text8, 15));
  500. $this->assertSame('НОПРСТУФХ…', $this->Text->truncate($text9, 10));
  501. $this->assertSame('http://example.com/something/…', $this->Text->truncate($text10, 30));
  502. $this->assertSame('1 <b>2...</b>', $this->Text->truncate('1 <b>2 345</b>', 6, ['exact' => false, 'html' => true, 'ellipsis' => '...']));
  503. $this->assertSame('&amp;', $this->Text->truncate('&amp;', 1, ['html' => true]));
  504. $text = '<p><span style="font-size: medium;"><a>Iamatestwithnospacesandhtml</a></span></p>';
  505. $result = $this->Text->truncate($text, 10, [
  506. 'ellipsis' => '...',
  507. 'exact' => false,
  508. 'html' => true,
  509. ]);
  510. $expected = '<p><span style="font-size: medium;"><a>Iamatestwi...</a></span></p>';
  511. $this->assertSame($expected, $result);
  512. $text = "<style>text-align: center;</style><script>console.log('test');</script><p>The quick brown fox jumps over the lazy dog</p>";
  513. $expected = "<style>text-align: center;</style><script>console.log('test');</script><p>The qu...</p>";
  514. $result = $this->Text->truncate($text, 9, ['html' => true, 'ellipsis' => '...']);
  515. $this->assertSame($expected, $result);
  516. }
  517. /**
  518. * Test truncate() method with both exact and html.
  519. */
  520. public function testTruncateExactHtml(): void
  521. {
  522. $text = '<a href="http://example.org">hello</a> world';
  523. $expected = '<a href="http://example.org">hell..</a>';
  524. $result = Text::truncate($text, 6, [
  525. 'ellipsis' => '..',
  526. 'exact' => true,
  527. 'html' => true,
  528. ]);
  529. $this->assertSame($expected, $result);
  530. $expected = '<a href="http://example.org">hello..</a>';
  531. $result = Text::truncate($text, 6, [
  532. 'ellipsis' => '..',
  533. 'exact' => false,
  534. 'html' => true,
  535. ]);
  536. $this->assertSame($expected, $result);
  537. }
  538. /**
  539. * testTruncate method with non utf8 sites
  540. */
  541. public function testTruncateLegacy(): void
  542. {
  543. mb_internal_encoding('ISO-8859-1');
  544. $text = '<b>&copy; 2005-2007, Cake Software Foundation, Inc.</b><br />written by Alexander Wegener';
  545. $result = $this->Text->truncate($text, 31, [
  546. 'html' => true,
  547. 'exact' => false,
  548. ]);
  549. $expected = '<b>&copy; 2005-2007, Cake Software…</b>';
  550. $this->assertSame($expected, $result);
  551. $result = $this->Text->truncate($text, 31, [
  552. 'html' => true,
  553. 'exact' => true,
  554. ]);
  555. $expected = '<b>&copy; 2005-2007, Cake Software F…</b>';
  556. $this->assertSame($expected, $result);
  557. }
  558. /**
  559. * Test truncate() method with trimWidth
  560. */
  561. public function testTruncateTrimWidth(): void
  562. {
  563. $text = 'The quick brown fox jumps over the lazy dog';
  564. $this->assertSame('The quick brown...', Text::truncate($text, 18, ['ellipsis' => '...', 'trimWidth' => false]));
  565. $this->assertSame('The quick brown...', Text::truncate($text, 18, ['ellipsis' => '...', 'trimWidth' => true]));
  566. $text = 'はしこい茶色の狐はのろまな犬を飛び越える';
  567. $this->assertSame('はしこい茶色の狐はのろまな犬を...', Text::truncate($text, 18, ['ellipsis' => '...', 'trimWidth' => false]));
  568. $this->assertSame('はしこい茶色の...', Text::truncate($text, 18, ['ellipsis' => '...', 'trimWidth' => true]));
  569. $text = 'はしこい茶色の狐 - The quick brown fox';
  570. $this->assertSame('はしこい茶色の狐 - The quick bro...', Text::truncate($text, 27, ['ellipsis' => '...', 'trimWidth' => false]));
  571. $this->assertSame('はしこい茶色の狐 - The q...', Text::truncate($text, 27, ['ellipsis' => '...', 'trimWidth' => true]));
  572. $this->assertSame('はしこい茶色の狐 - The...', Text::truncate($text, 27, ['ellipsis' => '...', 'trimWidth' => true, 'exact' => false]));
  573. $text = '<p>はしこい<font color="brown">茶色</font>の狐はのろまな犬を飛び越える</p>';
  574. $this->assertSame('<p>はしこい<font color="brown">茶色</font>の狐はのろまな犬を...</p>', Text::truncate($text, 18, ['ellipsis' => '...', 'trimWidth' => false, 'html' => true]));
  575. $this->assertSame('<p>はしこい<font color="brown">茶色</font>の...</p>', Text::truncate($text, 18, ['ellipsis' => '...', 'trimWidth' => true, 'html' => true]));
  576. $text = <<<HTML
  577. <IMG src="mypic.jpg">このimageタグはXHTMLに準拠していない!<br>
  578. <hr/><b>でも次のimageタグは準拠しているはず <img src="mypic.jpg" alt="私の、私自身そして私" /></b><br />
  579. 素晴らしい、でしょ?
  580. HTML;
  581. $this->assertSame("<IMG src=\"mypic.jpg\">このimageタグはXHTMLに準拠していない!<br>\n<hr/><b>でも次の…</b>", Text::truncate($text, 30, ['html' => true]));
  582. $this->assertSame('<IMG src="mypic.jpg">このimageタグはXHTMLに準拠し…', Text::truncate($text, 30, ['html' => true, 'trimWidth' => true]));
  583. }
  584. /**
  585. * testTail method
  586. */
  587. public function testTail(): void
  588. {
  589. $text1 = 'The quick brown fox jumps over the lazy dog';
  590. $text2 = 'Heiz&ouml;lr&uuml;cksto&szlig;abd&auml;mpfung';
  591. $text3 = 'El moño está en el lugar correcto. Eso fue lo que dijo la niña, ¿habrá dicho la verdad?';
  592. $text4 = 'Vive la R' . chr(195) . chr(169) . 'publique de France';
  593. $text5 = 'НОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
  594. $result = $this->Text->tail($text1, 13);
  595. $this->assertSame('…the lazy dog', $result);
  596. $result = $this->Text->tail($text1, 13, ['exact' => false]);
  597. $this->assertSame('…lazy dog', $result);
  598. $result = $this->Text->tail($text1, 100);
  599. $this->assertSame('The quick brown fox jumps over the lazy dog', $result);
  600. $result = $this->Text->tail($text2, 10);
  601. $this->assertSame('…ml;mpfung', $result);
  602. $result = $this->Text->tail($text2, 10, ['exact' => false]);
  603. $this->assertSame('…', $result);
  604. $result = $this->Text->tail($text3, 255);
  605. $this->assertSame($text3, $result);
  606. $result = $this->Text->tail($text3, 21);
  607. $this->assertSame('…brá dicho la verdad?', $result);
  608. $result = $this->Text->tail($text4, 25);
  609. $this->assertSame('… la R' . chr(195) . chr(169) . 'publique de France', $result);
  610. $result = $this->Text->tail($text5, 10);
  611. $this->assertSame('…фхцчшщъыь', $result);
  612. $result = $this->Text->tail($text5, 6, ['ellipsis' => '']);
  613. $this->assertSame('чшщъыь', $result);
  614. }
  615. /**
  616. * Tests highlight() method.
  617. */
  618. public function testHighlight(): void
  619. {
  620. $text = 'This is a test text';
  621. $phrases = ['This', 'text'];
  622. $result = $this->Text->highlight($text, $phrases, ['format' => '<b>\1</b>']);
  623. $expected = '<b>This</b> is a test <b>text</b>';
  624. $this->assertSame($expected, $result);
  625. $phrases = ['is', 'text'];
  626. $result = $this->Text->highlight($text, $phrases, ['format' => '<b>\1</b>', 'regex' => "|\b%s\b|iu"]);
  627. $expected = 'This <b>is</b> a test <b>text</b>';
  628. $this->assertSame($expected, $result);
  629. $text = 'This is a test text';
  630. $phrases = '';
  631. $result = $this->Text->highlight($text, $phrases, ['format' => '<b>\1</b>']);
  632. $this->assertSame($text, $result);
  633. $text = 'This is a (test) text';
  634. $phrases = '(test';
  635. $result = $this->Text->highlight($text, $phrases, ['format' => '<b>\1</b>']);
  636. $this->assertSame('This is a <b>(test</b>) text', $result);
  637. $text = 'Ich saß in einem Café am Übergang';
  638. $expected = 'Ich <b>saß</b> in einem <b>Café</b> am <b>Übergang</b>';
  639. $phrases = ['saß', 'café', 'übergang'];
  640. $result = $this->Text->highlight($text, $phrases, ['format' => '<b>\1</b>']);
  641. $this->assertSame($expected, $result);
  642. }
  643. /**
  644. * Tests highlight() method with limit.
  645. */
  646. public function testHighlightLimit(): void
  647. {
  648. $text = 'This is a test text with some more text';
  649. $phrases = ['This', 'text'];
  650. $result = $this->Text->highlight($text, $phrases, ['format' => '<b>\1</b>']);
  651. $expected = '<b>This</b> is a test <b>text</b> with some more <b>text</b>';
  652. $this->assertSame($expected, $result);
  653. $result = $this->Text->highlight($text, $phrases, ['format' => '<b>\1</b>', 'limit' => 1]);
  654. $expected = '<b>This</b> is a test <b>text</b> with some more text';
  655. $this->assertSame($expected, $result);
  656. }
  657. /**
  658. * testHighlightHtml method
  659. */
  660. public function testHighlightHtml(): void
  661. {
  662. $text1 = '<p>strongbow isn&rsquo;t real cider</p>';
  663. $text2 = '<p>strongbow <strong>isn&rsquo;t</strong> real cider</p>';
  664. $text3 = '<img src="what-a-strong-mouse.png" alt="What a strong mouse!" />';
  665. $text4 = 'What a strong mouse: <img src="what-a-strong-mouse.png" alt="What a strong mouse!" />';
  666. $options = ['format' => '<b>\1</b>', 'html' => true];
  667. $expected = '<p><b>strong</b>bow isn&rsquo;t real cider</p>';
  668. $this->assertSame($expected, $this->Text->highlight($text1, 'strong', $options));
  669. $expected = '<p><b>strong</b>bow <strong>isn&rsquo;t</strong> real cider</p>';
  670. $this->assertSame($expected, $this->Text->highlight($text2, 'strong', $options));
  671. $this->assertSame($text3, $this->Text->highlight($text3, 'strong', $options));
  672. $this->assertSame($text3, $this->Text->highlight($text3, ['strong', 'what'], $options));
  673. $expected = '<b>What</b> a <b>strong</b> mouse: <img src="what-a-strong-mouse.png" alt="What a strong mouse!" />';
  674. $this->assertSame($expected, $this->Text->highlight($text4, ['strong', 'what'], $options));
  675. }
  676. /**
  677. * testHighlightMulti method
  678. */
  679. public function testHighlightMulti(): void
  680. {
  681. $text = 'This is a test text';
  682. $phrases = ['This', 'text'];
  683. $result = $this->Text->highlight($text, $phrases, ['format' => ['<b>\1</b>', '<em>\1</em>']]);
  684. $expected = '<b>This</b> is a test <em>text</em>';
  685. $this->assertSame($expected, $result);
  686. }
  687. /**
  688. * testHighlightCaseInsensitivity method
  689. */
  690. public function testHighlightCaseInsensitivity(): void
  691. {
  692. $text = 'This is a Test text';
  693. $expected = 'This is a <b>Test</b> text';
  694. $result = $this->Text->highlight($text, 'test', ['format' => '<b>\1</b>']);
  695. $this->assertSame($expected, $result);
  696. $result = $this->Text->highlight($text, ['test'], ['format' => '<b>\1</b>']);
  697. $this->assertSame($expected, $result);
  698. }
  699. /**
  700. * testExcerpt method
  701. */
  702. public function testExcerpt(): void
  703. {
  704. $text = 'This is a phrase with test text to play with';
  705. $expected = '...ase with test text to ...';
  706. $result = $this->Text->excerpt($text, 'test', 9, '...');
  707. $this->assertSame($expected, $result);
  708. $expected = 'This is a...';
  709. $result = $this->Text->excerpt($text, 'not_found', 9, '...');
  710. $this->assertSame($expected, $result);
  711. $expected = 'This is a phras...';
  712. $result = $this->Text->excerpt($text, '', 9, '...');
  713. $this->assertSame($expected, $result);
  714. $expected = $text;
  715. $result = $this->Text->excerpt($text, '', 200, '...');
  716. $this->assertSame($expected, $result);
  717. $expected = '...a phrase w...';
  718. $result = $this->Text->excerpt($text, 'phrase', 2, '...');
  719. $this->assertSame($expected, $result);
  720. $phrase = 'This is a phrase with test text';
  721. $expected = $text;
  722. $result = $this->Text->excerpt($text, $phrase, 13, '...');
  723. $this->assertSame($expected, $result);
  724. $text = 'aaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaa';
  725. $phrase = 'bbbbbbbb';
  726. $result = $this->Text->excerpt($text, $phrase, 10);
  727. $expected = '…aaaaaaaaaabbbbbbbbaaaaaaaaaa…';
  728. $this->assertSame($expected, $result);
  729. }
  730. /**
  731. * testExcerptCaseInsensitivity method
  732. */
  733. public function testExcerptCaseInsensitivity(): void
  734. {
  735. $text = 'This is a phrase with test text to play with';
  736. $expected = '...ase with test text to ...';
  737. $result = $this->Text->excerpt($text, 'TEST', 9, '...');
  738. $this->assertSame($expected, $result);
  739. $expected = 'This is a...';
  740. $result = $this->Text->excerpt($text, 'NOT_FOUND', 9, '...');
  741. $this->assertSame($expected, $result);
  742. }
  743. /**
  744. * testListGeneration method
  745. */
  746. public function testListGeneration(): void
  747. {
  748. $result = $this->Text->toList([]);
  749. $this->assertSame('', $result);
  750. $result = $this->Text->toList(['One']);
  751. $this->assertSame('One', $result);
  752. $result = $this->Text->toList(['Larry', 'Curly', 'Moe']);
  753. $this->assertSame('Larry, Curly and Moe', $result);
  754. $result = $this->Text->toList(['Dusty', 'Lucky', 'Ned'], 'y');
  755. $this->assertSame('Dusty, Lucky y Ned', $result);
  756. $result = $this->Text->toList([1 => 'Dusty', 2 => 'Lucky', 3 => 'Ned'], 'y');
  757. $this->assertSame('Dusty, Lucky y Ned', $result);
  758. $result = $this->Text->toList([1 => 'Dusty', 2 => 'Lucky', 3 => 'Ned'], 'and', ' + ');
  759. $this->assertSame('Dusty + Lucky and Ned', $result);
  760. $result = $this->Text->toList(['name1' => 'Dusty', 'name2' => 'Lucky']);
  761. $this->assertSame('Dusty and Lucky', $result);
  762. $result = $this->Text->toList(['test_0' => 'banana', 'test_1' => 'apple', 'test_2' => 'lemon']);
  763. $this->assertSame('banana, apple and lemon', $result);
  764. }
  765. /**
  766. * testUtf8 method
  767. */
  768. public function testUtf8(): void
  769. {
  770. $string = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
  771. $result = Text::utf8($string);
  772. $expected = [33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
  773. 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
  774. 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105,
  775. 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126];
  776. $this->assertSame($expected, $result);
  777. $string = '¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
  778. $result = Text::utf8($string);
  779. $expected = [161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181,
  780. 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200];
  781. $this->assertSame($expected, $result);
  782. $string = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
  783. $result = Text::utf8($string);
  784. $expected = [201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221,
  785. 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242,
  786. 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263,
  787. 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
  788. 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300];
  789. $this->assertSame($expected, $result);
  790. $string = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
  791. $result = Text::utf8($string);
  792. $expected = [301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321,
  793. 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342,
  794. 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363,
  795. 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384,
  796. 385, 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400];
  797. $this->assertSame($expected, $result);
  798. $string = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
  799. $result = Text::utf8($string);
  800. $expected = [401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421,
  801. 422, 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442,
  802. 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463,
  803. 464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484,
  804. 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500];
  805. $this->assertSame($expected, $result);
  806. $string = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
  807. $result = Text::utf8($string);
  808. $expected = [601, 602, 603, 604, 605, 606, 607, 608, 609, 610, 611, 612, 613, 614, 615, 616, 617, 618, 619, 620, 621,
  809. 622, 623, 624, 625, 626, 627, 628, 629, 630, 631, 632, 633, 634, 635, 636, 637, 638, 639, 640, 641, 642,
  810. 643, 644, 645, 646, 647, 648, 649, 650, 651, 652, 653, 654, 655, 656, 657, 658, 659, 660, 661, 662, 663,
  811. 664, 665, 666, 667, 668, 669, 670, 671, 672, 673, 674, 675, 676, 677, 678, 679, 680, 681, 682, 683, 684,
  812. 685, 686, 687, 688, 689, 690, 691, 692, 693, 694, 695, 696, 697, 698, 699, 700];
  813. $this->assertSame($expected, $result);
  814. $string = 'ЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
  815. $result = Text::utf8($string);
  816. $expected = [1024, 1025, 1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1034, 1035, 1036, 1037, 1038, 1039, 1040, 1041,
  817. 1042, 1043, 1044, 1045, 1046, 1047, 1048, 1049, 1050, 1051];
  818. $this->assertSame($expected, $result);
  819. $string = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
  820. $result = Text::utf8($string);
  821. $expected = [1052, 1053, 1054, 1055, 1056, 1057, 1058, 1059, 1060, 1061, 1062, 1063, 1064, 1065, 1066, 1067, 1068, 1069,
  822. 1070, 1071, 1072, 1073, 1074, 1075, 1076, 1077, 1078, 1079, 1080, 1081, 1082, 1083, 1084, 1085, 1086, 1087,
  823. 1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095, 1096, 1097, 1098, 1099, 1100];
  824. $this->assertSame($expected, $result);
  825. $string = 'չպջռսվտ';
  826. $result = Text::utf8($string);
  827. $expected = [1401, 1402, 1403, 1404, 1405, 1406, 1407];
  828. $this->assertSame($expected, $result);
  829. $string = 'فقكلمنهوىيًٌٍَُ';
  830. $result = Text::utf8($string);
  831. $expected = [1601, 1602, 1603, 1604, 1605, 1606, 1607, 1608, 1609, 1610, 1611, 1612, 1613, 1614, 1615];
  832. $this->assertSame($expected, $result);
  833. $string = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
  834. $result = Text::utf8($string);
  835. $expected = [10032, 10033, 10034, 10035, 10036, 10037, 10038, 10039, 10040, 10041, 10042, 10043, 10044,
  836. 10045, 10046, 10047, 10048, 10049, 10050, 10051, 10052, 10053, 10054, 10055, 10056, 10057,
  837. 10058, 10059, 10060, 10061, 10062, 10063, 10064, 10065, 10066, 10067, 10068, 10069, 10070,
  838. 10071, 10072, 10073, 10074, 10075, 10076, 10077, 10078];
  839. $this->assertSame($expected, $result);
  840. $string = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
  841. $result = Text::utf8($string);
  842. $expected = [11904, 11905, 11906, 11907, 11908, 11909, 11910, 11911, 11912, 11913, 11914, 11915, 11916, 11917, 11918, 11919,
  843. 11920, 11921, 11922, 11923, 11924, 11925, 11926, 11927, 11928, 11929, 11931, 11932, 11933, 11934, 11935, 11936,
  844. 11937, 11938, 11939, 11940, 11941, 11942, 11943, 11944, 11945, 11946, 11947, 11948, 11949, 11950, 11951, 11952,
  845. 11953, 11954, 11955, 11956, 11957, 11958, 11959, 11960, 11961, 11962, 11963, 11964, 11965, 11966, 11967, 11968,
  846. 11969, 11970, 11971, 11972, 11973, 11974, 11975, 11976, 11977, 11978, 11979, 11980, 11981, 11982, 11983, 11984,
  847. 11985, 11986, 11987, 11988, 11989, 11990, 11991, 11992, 11993, 11994, 11995, 11996, 11997, 11998, 11999, 12000];
  848. $this->assertSame($expected, $result);
  849. $string = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
  850. $result = Text::utf8($string);
  851. $expected = [12101, 12102, 12103, 12104, 12105, 12106, 12107, 12108, 12109, 12110, 12111, 12112, 12113, 12114, 12115, 12116,
  852. 12117, 12118, 12119, 12120, 12121, 12122, 12123, 12124, 12125, 12126, 12127, 12128, 12129, 12130, 12131, 12132,
  853. 12133, 12134, 12135, 12136, 12137, 12138, 12139, 12140, 12141, 12142, 12143, 12144, 12145, 12146, 12147, 12148,
  854. 12149, 12150, 12151, 12152, 12153, 12154, 12155, 12156, 12157, 12158, 12159];
  855. $this->assertSame($expected, $result);
  856. $string = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
  857. $result = Text::utf8($string);
  858. $expected = [45601, 45602, 45603, 45604, 45605, 45606, 45607, 45608, 45609, 45610, 45611, 45612, 45613, 45614, 45615, 45616,
  859. 45617, 45618, 45619, 45620, 45621, 45622, 45623, 45624, 45625, 45626, 45627, 45628, 45629, 45630, 45631, 45632,
  860. 45633, 45634, 45635, 45636, 45637, 45638, 45639, 45640, 45641, 45642, 45643, 45644, 45645, 45646, 45647, 45648,
  861. 45649, 45650, 45651, 45652, 45653, 45654, 45655, 45656, 45657, 45658, 45659, 45660, 45661, 45662, 45663, 45664,
  862. 45665, 45666, 45667, 45668, 45669, 45670, 45671, 45672, 45673, 45674, 45675, 45676, 45677, 45678, 45679, 45680,
  863. 45681, 45682, 45683, 45684, 45685, 45686, 45687, 45688, 45689, 45690, 45691, 45692, 45693, 45694, 45695, 45696,
  864. 45697, 45698, 45699, 45700];
  865. $this->assertSame($expected, $result);
  866. $string = 'ﹰﹱﹲﹳﹴ﹵ﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
  867. $result = Text::utf8($string);
  868. $expected = [65136, 65137, 65138, 65139, 65140, 65141, 65142, 65143, 65144, 65145, 65146, 65147, 65148, 65149, 65150, 65151,
  869. 65152, 65153, 65154, 65155, 65156, 65157, 65158, 65159, 65160, 65161, 65162, 65163, 65164, 65165, 65166, 65167,
  870. 65168, 65169, 65170, 65171, 65172, 65173, 65174, 65175, 65176, 65177, 65178, 65179, 65180, 65181, 65182, 65183,
  871. 65184, 65185, 65186, 65187, 65188, 65189, 65190, 65191, 65192, 65193, 65194, 65195, 65196, 65197, 65198, 65199,
  872. 65200];
  873. $this->assertSame($expected, $result);
  874. $string = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
  875. $result = Text::utf8($string);
  876. $expected = [65201, 65202, 65203, 65204, 65205, 65206, 65207, 65208, 65209, 65210, 65211, 65212, 65213, 65214, 65215, 65216,
  877. 65217, 65218, 65219, 65220, 65221, 65222, 65223, 65224, 65225, 65226, 65227, 65228, 65229, 65230, 65231, 65232,
  878. 65233, 65234, 65235, 65236, 65237, 65238, 65239, 65240, 65241, 65242, 65243, 65244, 65245, 65246, 65247, 65248,
  879. 65249, 65250, 65251, 65252, 65253, 65254, 65255, 65256, 65257, 65258, 65259, 65260, 65261, 65262, 65263, 65264,
  880. 65265, 65266, 65267, 65268, 65269, 65270, 65271, 65272, 65273, 65274, 65275, 65276];
  881. $this->assertSame($expected, $result);
  882. $string = 'abcdefghijklmnopqrstuvwxyz';
  883. $result = Text::utf8($string);
  884. $expected = [65345, 65346, 65347, 65348, 65349, 65350, 65351, 65352, 65353, 65354, 65355, 65356, 65357, 65358, 65359, 65360,
  885. 65361, 65362, 65363, 65364, 65365, 65366, 65367, 65368, 65369, 65370];
  886. $this->assertSame($expected, $result);
  887. $string = '。「」、・ヲァィゥェォャュョッーアイウエオカキク';
  888. $result = Text::utf8($string);
  889. $expected = [65377, 65378, 65379, 65380, 65381, 65382, 65383, 65384, 65385, 65386, 65387, 65388, 65389, 65390, 65391, 65392,
  890. 65393, 65394, 65395, 65396, 65397, 65398, 65399, 65400];
  891. $this->assertSame($expected, $result);
  892. $string = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
  893. $result = Text::utf8($string);
  894. $expected = [65401, 65402, 65403, 65404, 65405, 65406, 65407, 65408, 65409, 65410, 65411, 65412, 65413, 65414, 65415, 65416,
  895. 65417, 65418, 65419, 65420, 65421, 65422, 65423, 65424, 65425, 65426, 65427, 65428, 65429, 65430, 65431, 65432,
  896. 65433, 65434, 65435, 65436, 65437, 65438];
  897. $this->assertSame($expected, $result);
  898. $string = 'Ĥēĺļŏ, Ŵőřļď!';
  899. $result = Text::utf8($string);
  900. $expected = [292, 275, 314, 316, 335, 44, 32, 372, 337, 345, 316, 271, 33];
  901. $this->assertSame($expected, $result);
  902. $string = 'Hello, World!';
  903. $result = Text::utf8($string);
  904. $expected = [72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33];
  905. $this->assertSame($expected, $result);
  906. $string = '¨';
  907. $result = Text::utf8($string);
  908. $expected = [168];
  909. $this->assertSame($expected, $result);
  910. $string = '¿';
  911. $result = Text::utf8($string);
  912. $expected = [191];
  913. $this->assertSame($expected, $result);
  914. $string = 'čini';
  915. $result = Text::utf8($string);
  916. $expected = [269, 105, 110, 105];
  917. $this->assertSame($expected, $result);
  918. $string = 'moći';
  919. $result = Text::utf8($string);
  920. $expected = [109, 111, 263, 105];
  921. $this->assertSame($expected, $result);
  922. $string = 'državni';
  923. $result = Text::utf8($string);
  924. $expected = [100, 114, 382, 97, 118, 110, 105];
  925. $this->assertSame($expected, $result);
  926. $string = '把百度设为首页';
  927. $result = Text::utf8($string);
  928. $expected = [25226, 30334, 24230, 35774, 20026, 39318, 39029];
  929. $this->assertSame($expected, $result);
  930. $string = '一二三周永龍';
  931. $result = Text::utf8($string);
  932. $expected = [19968, 20108, 19977, 21608, 27704, 40845];
  933. $this->assertSame($expected, $result);
  934. $string = 'ԀԂԄԆԈԊԌԎԐԒ';
  935. $result = Text::utf8($string);
  936. $expected = [1280, 1282, 1284, 1286, 1288, 1290, 1292, 1294, 1296, 1298];
  937. $this->assertSame($expected, $result);
  938. $string = 'ԁԃԅԇԉԋԍԏԐԒ';
  939. $result = Text::utf8($string);
  940. $expected = [1281, 1283, 1285, 1287, 1289, 1291, 1293, 1295, 1296, 1298];
  941. $this->assertSame($expected, $result);
  942. $string = 'ԱԲԳԴԵԶԷԸԹԺԻԼԽԾԿՀՁՂՃՄՅՆՇՈՉՊՋՌՍՎՏՐՑՒՓՔՕՖև';
  943. $result = Text::utf8($string);
  944. $expected = [1329, 1330, 1331, 1332, 1333, 1334, 1335, 1336, 1337, 1338, 1339, 1340, 1341, 1342, 1343, 1344, 1345, 1346,
  945. 1347, 1348, 1349, 1350, 1351, 1352, 1353, 1354, 1355, 1356, 1357, 1358, 1359, 1360, 1361, 1362, 1363, 1364,
  946. 1365, 1366, 1415];
  947. $this->assertSame($expected, $result);
  948. $string = 'աբգդեզէըթժիլխծկհձղճմյնշոչպջռսվտրցւփքօֆև';
  949. $result = Text::utf8($string);
  950. $expected = [1377, 1378, 1379, 1380, 1381, 1382, 1383, 1384, 1385, 1386, 1387, 1388, 1389, 1390, 1391, 1392, 1393, 1394,
  951. 1395, 1396, 1397, 1398, 1399, 1400, 1401, 1402, 1403, 1404, 1405, 1406, 1407, 1408, 1409, 1410, 1411, 1412,
  952. 1413, 1414, 1415];
  953. $this->assertSame($expected, $result);
  954. $string = 'ႠႡႢႣႤႥႦႧႨႩႪႫႬႭႮႯႰႱႲႳႴႵႶႷႸႹႺႻႼႽႾႿჀჁჂჃჄჅ';
  955. $result = Text::utf8($string);
  956. $expected = [4256, 4257, 4258, 4259, 4260, 4261, 4262, 4263, 4264, 4265, 4266, 4267, 4268, 4269, 4270, 4271, 4272, 4273,
  957. 4274, 4275, 4276, 4277, 4278, 4279, 4280, 4281, 4282, 4283, 4284, 4285, 4286, 4287, 4288, 4289, 4290, 4291,
  958. 4292, 4293];
  959. $this->assertSame($expected, $result);
  960. $string = 'ḀḂḄḆḈḊḌḎḐḒḔḖḘḚḜḞḠḢḤḦḨḪḬḮḰḲḴḶḸḺḼḾṀṂṄṆṈṊṌṎṐṒṔṖṘṚṜṞṠṢṤṦṨṪṬṮṰṲṴṶṸṺṼṾẀẂẄẆẈẊẌẎẐẒẔẖẗẘẙẚẠẢẤẦẨẪẬẮẰẲẴẶẸẺẼẾỀỂỄỆỈỊỌỎỐỒỔỖỘỚỜỞỠỢỤỦỨỪỬỮỰỲỴỶỸ';
  961. $result = Text::utf8($string);
  962. $expected = [7680, 7682, 7684, 7686, 7688, 7690, 7692, 7694, 7696, 7698, 7700, 7702, 7704, 7706, 7708, 7710, 7712, 7714,
  963. 7716, 7718, 7720, 7722, 7724, 7726, 7728, 7730, 7732, 7734, 7736, 7738, 7740, 7742, 7744, 7746, 7748, 7750,
  964. 7752, 7754, 7756, 7758, 7760, 7762, 7764, 7766, 7768, 7770, 7772, 7774, 7776, 7778, 7780, 7782, 7784, 7786,
  965. 7788, 7790, 7792, 7794, 7796, 7798, 7800, 7802, 7804, 7806, 7808, 7810, 7812, 7814, 7816, 7818, 7820, 7822,
  966. 7824, 7826, 7828, 7830, 7831, 7832, 7833, 7834, 7840, 7842, 7844, 7846, 7848, 7850, 7852, 7854, 7856,
  967. 7858, 7860, 7862, 7864, 7866, 7868, 7870, 7872, 7874, 7876, 7878, 7880, 7882, 7884, 7886, 7888, 7890, 7892,
  968. 7894, 7896, 7898, 7900, 7902, 7904, 7906, 7908, 7910, 7912, 7914, 7916, 7918, 7920, 7922, 7924, 7926, 7928];
  969. $this->assertSame($expected, $result);
  970. $string = 'ḁḃḅḇḉḋḍḏḑḓḕḗḙḛḝḟḡḣḥḧḩḫḭḯḱḳḵḷḹḻḽḿṁṃṅṇṉṋṍṏṑṓṕṗṙṛṝṟṡṣṥṧṩṫṭṯṱṳṵṷṹṻṽṿẁẃẅẇẉẋẍẏẑẓẕẖẗẘẙẚạảấầẩẫậắằẳẵặẹẻẽếềểễệỉịọỏốồổỗộớờởỡợụủứừửữựỳỵỷỹ';
  971. $result = Text::utf8($string);
  972. $expected = [7681, 7683, 7685, 7687, 7689, 7691, 7693, 7695, 7697, 7699, 7701, 7703, 7705, 7707, 7709, 7711, 7713, 7715,
  973. 7717, 7719, 7721, 7723, 7725, 7727, 7729, 7731, 7733, 7735, 7737, 7739, 7741, 7743, 7745, 7747, 7749, 7751,
  974. 7753, 7755, 7757, 7759, 7761, 7763, 7765, 7767, 7769, 7771, 7773, 7775, 7777, 7779, 7781, 7783, 7785, 7787,
  975. 7789, 7791, 7793, 7795, 7797, 7799, 7801, 7803, 7805, 7807, 7809, 7811, 7813, 7815, 7817, 7819, 7821, 7823,
  976. 7825, 7827, 7829, 7830, 7831, 7832, 7833, 7834, 7841, 7843, 7845, 7847, 7849, 7851, 7853, 7855, 7857, 7859,
  977. 7861, 7863, 7865, 7867, 7869, 7871, 7873, 7875, 7877, 7879, 7881, 7883, 7885, 7887, 7889, 7891, 7893, 7895,
  978. 7897, 7899, 7901, 7903, 7905, 7907, 7909, 7911, 7913, 7915, 7917, 7919, 7921, 7923, 7925, 7927, 7929];
  979. $this->assertSame($expected, $result);
  980. $string = 'ΩKÅℲ';
  981. $result = Text::utf8($string);
  982. $expected = [8486, 8490, 8491, 8498];
  983. $this->assertSame($expected, $result);
  984. $string = 'ωkåⅎ';
  985. $result = Text::utf8($string);
  986. $expected = [969, 107, 229, 8526];
  987. $this->assertSame($expected, $result);
  988. $string = 'ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫⅬⅭⅮⅯↃ';
  989. $result = Text::utf8($string);
  990. $expected = [8544, 8545, 8546, 8547, 8548, 8549, 8550, 8551, 8552, 8553, 8554, 8555, 8556, 8557, 8558, 8559, 8579];
  991. $this->assertSame($expected, $result);
  992. $string = 'ⅰⅱⅲⅳⅴⅵⅶⅷⅸⅹⅺⅻⅼⅽⅾⅿↄ';
  993. $result = Text::utf8($string);
  994. $expected = [8560, 8561, 8562, 8563, 8564, 8565, 8566, 8567, 8568, 8569, 8570, 8571, 8572, 8573, 8574, 8575, 8580];
  995. $this->assertSame($expected, $result);
  996. $string = 'ⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓌⓍⓎⓏ';
  997. $result = Text::utf8($string);
  998. $expected = [9398, 9399, 9400, 9401, 9402, 9403, 9404, 9405, 9406, 9407, 9408, 9409, 9410, 9411, 9412, 9413, 9414,
  999. 9415, 9416, 9417, 9418, 9419, 9420, 9421, 9422, 9423];
  1000. $this->assertSame($expected, $result);
  1001. $string = 'ⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩ';
  1002. $result = Text::utf8($string);
  1003. $expected = [9424, 9425, 9426, 9427, 9428, 9429, 9430, 9431, 9432, 9433, 9434, 9435, 9436, 9437, 9438, 9439, 9440, 9441,
  1004. 9442, 9443, 9444, 9445, 9446, 9447, 9448, 9449];
  1005. $this->assertSame($expected, $result);
  1006. $string = 'ⰀⰁⰂⰃⰄⰅⰆⰇⰈⰉⰊⰋⰌⰍⰎⰏⰐⰑⰒⰓⰔⰕⰖⰗⰘⰙⰚⰛⰜⰝⰞⰟⰠⰡⰢⰣⰤⰥⰦⰧⰨⰩⰪⰫⰬⰭⰮ';
  1007. $result = Text::utf8($string);
  1008. $expected = [11264, 11265, 11266, 11267, 11268, 11269, 11270, 11271, 11272, 11273, 11274, 11275, 11276, 11277, 11278,
  1009. 11279, 11280, 11281, 11282, 11283, 11284, 11285, 11286, 11287, 11288, 11289, 11290, 11291, 11292, 11293,
  1010. 11294, 11295, 11296, 11297, 11298, 11299, 11300, 11301, 11302, 11303, 11304, 11305, 11306, 11307, 11308,
  1011. 11309, 11310];
  1012. $this->assertSame($expected, $result);
  1013. $string = 'ⰰⰱⰲⰳⰴⰵⰶⰷⰸⰹⰺⰻⰼⰽⰾⰿⱀⱁⱂⱃⱄⱅⱆⱇⱈⱉⱊⱋⱌⱍⱎⱏⱐⱑⱒⱓⱔⱕⱖⱗⱘⱙⱚⱛⱜⱝⱞ';
  1014. $result = Text::utf8($string);
  1015. $expected = [11312, 11313, 11314, 11315, 11316, 11317, 11318, 11319, 11320, 11321, 11322, 11323, 11324, 11325, 11326, 11327,
  1016. 11328, 11329, 11330, 11331, 11332, 11333, 11334, 11335, 11336, 11337, 11338, 11339, 11340, 11341, 11342, 11343,
  1017. 11344, 11345, 11346, 11347, 11348, 11349, 11350, 11351, 11352, 11353, 11354, 11355, 11356, 11357, 11358];
  1018. $this->assertSame($expected, $result);
  1019. $string = 'ⲀⲂⲄⲆⲈⲊⲌⲎⲐⲒⲔⲖⲘⲚⲜⲞⲠⲢⲤⲦⲨⲪⲬⲮⲰⲲⲴⲶⲸⲺⲼⲾⳀⳂⳄⳆⳈⳊⳌⳎⳐⳒⳔⳖⳘⳚⳜⳞⳠⳢ';
  1020. $result = Text::utf8($string);
  1021. $expected = [11392, 11394, 11396, 11398, 11400, 11402, 11404, 11406, 11408, 11410, 11412, 11414, 11416, 11418, 11420,
  1022. 11422, 11424, 11426, 11428, 11430, 11432, 11434, 11436, 11438, 11440, 11442, 11444, 11446, 11448, 11450,
  1023. 11452, 11454, 11456, 11458, 11460, 11462, 11464, 11466, 11468, 11470, 11472, 11474, 11476, 11478, 11480,
  1024. 11482, 11484, 11486, 11488, 11490];
  1025. $this->assertSame($expected, $result);
  1026. $string = 'ⲁⲃⲅⲇⲉⲋⲍⲏⲑⲓⲕⲗⲙⲛⲝⲟⲡⲣⲥⲧⲩⲫⲭⲯⲱⲳⲵⲷⲹⲻⲽⲿⳁⳃⳅⳇⳉⳋⳍⳏⳑⳓⳕⳗⳙⳛⳝⳟⳡⳣ';
  1027. $result = Text::utf8($string);
  1028. $expected = [11393, 11395, 11397, 11399, 11401, 11403, 11405, 11407, 11409, 11411, 11413, 11415, 11417, 11419, 11421, 11423,
  1029. 11425, 11427, 11429, 11431, 11433, 11435, 11437, 11439, 11441, 11443, 11445, 11447, 11449, 11451, 11453, 11455,
  1030. 11457, 11459, 11461, 11463, 11465, 11467, 11469, 11471, 11473, 11475, 11477, 11479, 11481, 11483, 11485, 11487,
  1031. 11489, 11491];
  1032. $this->assertSame($expected, $result);
  1033. $string = 'fffiflffifflſtstﬓﬔﬕﬖﬗ';
  1034. $result = Text::utf8($string);
  1035. $expected = [64256, 64257, 64258, 64259, 64260, 64261, 64262, 64275, 64276, 64277, 64278, 64279];
  1036. $this->assertSame($expected, $result);
  1037. }
  1038. /**
  1039. * testAscii method
  1040. */
  1041. public function testAscii(): void
  1042. {
  1043. $input = [33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
  1044. 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
  1045. 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105,
  1046. 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126];
  1047. $result = Text::ascii($input);
  1048. $expected = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
  1049. $this->assertSame($expected, $result);
  1050. $input = [161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181,
  1051. 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200];
  1052. $result = Text::ascii($input);
  1053. $expected = '¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ';
  1054. $this->assertSame($expected, $result);
  1055. $input = [201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221,
  1056. 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242,
  1057. 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263,
  1058. 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
  1059. 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300];
  1060. $result = Text::ascii($input);
  1061. $expected = 'ÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬ';
  1062. $this->assertSame($expected, $result);
  1063. $input = [301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321,
  1064. 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342,
  1065. 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363,
  1066. 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384,
  1067. 385, 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400];
  1068. $expected = 'ĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐ';
  1069. $result = Text::ascii($input);
  1070. $this->assertSame($expected, $result);
  1071. $input = [401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421,
  1072. 422, 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442,
  1073. 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463,
  1074. 464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484,
  1075. 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500];
  1076. $expected = 'ƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴ';
  1077. $result = Text::ascii($input);
  1078. $this->assertSame($expected, $result);
  1079. $input = [601, 602, 603, 604, 605, 606, 607, 608, 609, 610, 611, 612, 613, 614, 615, 616, 617, 618, 619, 620, 621,
  1080. 622, 623, 624, 625, 626, 627, 628, 629, 630, 631, 632, 633, 634, 635, 636, 637, 638, 639, 640, 641, 642,
  1081. 643, 644, 645, 646, 647, 648, 649, 650, 651, 652, 653, 654, 655, 656, 657, 658, 659, 660, 661, 662, 663,
  1082. 664, 665, 666, 667, 668, 669, 670, 671, 672, 673, 674, 675, 676, 677, 678, 679, 680, 681, 682, 683, 684,
  1083. 685, 686, 687, 688, 689, 690, 691, 692, 693, 694, 695, 696, 697, 698, 699, 700];
  1084. $expected = 'əɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼ';
  1085. $result = Text::ascii($input);
  1086. $this->assertSame($expected, $result);
  1087. $input = [1024, 1025, 1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1034, 1035, 1036, 1037, 1038, 1039, 1040, 1041,
  1088. 1042, 1043, 1044, 1045, 1046, 1047, 1048, 1049, 1050, 1051];
  1089. $expected = 'ЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛ';
  1090. $result = Text::ascii($input);
  1091. $this->assertSame($expected, $result);
  1092. $input = [1052, 1053, 1054, 1055, 1056, 1057, 1058, 1059, 1060, 1061, 1062, 1063, 1064, 1065, 1066, 1067, 1068, 1069,
  1093. 1070, 1071, 1072, 1073, 1074, 1075, 1076, 1077, 1078, 1079, 1080, 1081, 1082, 1083, 1084, 1085, 1086, 1087,
  1094. 1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095, 1096, 1097, 1098, 1099, 1100];
  1095. $expected = 'МНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
  1096. $result = Text::ascii($input);
  1097. $this->assertSame($expected, $result);
  1098. $input = [1401, 1402, 1403, 1404, 1405, 1406, 1407];
  1099. $expected = 'չպջռսվտ';
  1100. $result = Text::ascii($input);
  1101. $this->assertSame($expected, $result);
  1102. $input = [1601, 1602, 1603, 1604, 1605, 1606, 1607, 1608, 1609, 1610, 1611, 1612, 1613, 1614, 1615];
  1103. $expected = 'فقكلمنهوىيًٌٍَُ';
  1104. $result = Text::ascii($input);
  1105. $this->assertSame($expected, $result);
  1106. $input = [10032, 10033, 10034, 10035, 10036, 10037, 10038, 10039, 10040, 10041, 10042, 10043, 10044,
  1107. 10045, 10046, 10047, 10048, 10049, 10050, 10051, 10052, 10053, 10054, 10055, 10056, 10057,
  1108. 10058, 10059, 10060, 10061, 10062, 10063, 10064, 10065, 10066, 10067, 10068, 10069, 10070,
  1109. 10071, 10072, 10073, 10074, 10075, 10076, 10077, 10078];
  1110. $expected = '✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞';
  1111. $result = Text::ascii($input);
  1112. $this->assertSame($expected, $result);
  1113. $input = [11904, 11905, 11906, 11907, 11908, 11909, 11910, 11911, 11912, 11913, 11914, 11915, 11916, 11917, 11918, 11919,
  1114. 11920, 11921, 11922, 11923, 11924, 11925, 11926, 11927, 11928, 11929, 11931, 11932, 11933, 11934, 11935, 11936,
  1115. 11937, 11938, 11939, 11940, 11941, 11942, 11943, 11944, 11945, 11946, 11947, 11948, 11949, 11950, 11951, 11952,
  1116. 11953, 11954, 11955, 11956, 11957, 11958, 11959, 11960, 11961, 11962, 11963, 11964, 11965, 11966, 11967, 11968,
  1117. 11969, 11970, 11971, 11972, 11973, 11974, 11975, 11976, 11977, 11978, 11979, 11980, 11981, 11982, 11983, 11984,
  1118. 11985, 11986, 11987, 11988, 11989, 11990, 11991, 11992, 11993, 11994, 11995, 11996, 11997, 11998, 11999, 12000];
  1119. $expected = '⺀⺁⺂⺃⺄⺅⺆⺇⺈⺉⺊⺋⺌⺍⺎⺏⺐⺑⺒⺓⺔⺕⺖⺗⺘⺙⺛⺜⺝⺞⺟⺠⺡⺢⺣⺤⺥⺦⺧⺨⺩⺪⺫⺬⺭⺮⺯⺰⺱⺲⺳⺴⺵⺶⺷⺸⺹⺺⺻⺼⺽⺾⺿⻀⻁⻂⻃⻄⻅⻆⻇⻈⻉⻊⻋⻌⻍⻎⻏⻐⻑⻒⻓⻔⻕⻖⻗⻘⻙⻚⻛⻜⻝⻞⻟⻠';
  1120. $result = Text::ascii($input);
  1121. $this->assertSame($expected, $result);
  1122. $input = [12101, 12102, 12103, 12104, 12105, 12106, 12107, 12108, 12109, 12110, 12111, 12112, 12113, 12114, 12115, 12116,
  1123. 12117, 12118, 12119, 12120, 12121, 12122, 12123, 12124, 12125, 12126, 12127, 12128, 12129, 12130, 12131, 12132,
  1124. 12133, 12134, 12135, 12136, 12137, 12138, 12139, 12140, 12141, 12142, 12143, 12144, 12145, 12146, 12147, 12148,
  1125. 12149, 12150, 12151, 12152, 12153, 12154, 12155, 12156, 12157, 12158, 12159];
  1126. $expected = '⽅⽆⽇⽈⽉⽊⽋⽌⽍⽎⽏⽐⽑⽒⽓⽔⽕⽖⽗⽘⽙⽚⽛⽜⽝⽞⽟⽠⽡⽢⽣⽤⽥⽦⽧⽨⽩⽪⽫⽬⽭⽮⽯⽰⽱⽲⽳⽴⽵⽶⽷⽸⽹⽺⽻⽼⽽⽾⽿';
  1127. $result = Text::ascii($input);
  1128. $this->assertSame($expected, $result);
  1129. $input = [45601, 45602, 45603, 45604, 45605, 45606, 45607, 45608, 45609, 45610, 45611, 45612, 45613, 45614, 45615, 45616,
  1130. 45617, 45618, 45619, 45620, 45621, 45622, 45623, 45624, 45625, 45626, 45627, 45628, 45629, 45630, 45631, 45632,
  1131. 45633, 45634, 45635, 45636, 45637, 45638, 45639, 45640, 45641, 45642, 45643, 45644, 45645, 45646, 45647, 45648,
  1132. 45649, 45650, 45651, 45652, 45653, 45654, 45655, 45656, 45657, 45658, 45659, 45660, 45661, 45662, 45663, 45664,
  1133. 45665, 45666, 45667, 45668, 45669, 45670, 45671, 45672, 45673, 45674, 45675, 45676, 45677, 45678, 45679, 45680,
  1134. 45681, 45682, 45683, 45684, 45685, 45686, 45687, 45688, 45689, 45690, 45691, 45692, 45693, 45694, 45695, 45696,
  1135. 45697, 45698, 45699, 45700];
  1136. $expected = '눡눢눣눤눥눦눧눨눩눪눫눬눭눮눯눰눱눲눳눴눵눶눷눸눹눺눻눼눽눾눿뉀뉁뉂뉃뉄뉅뉆뉇뉈뉉뉊뉋뉌뉍뉎뉏뉐뉑뉒뉓뉔뉕뉖뉗뉘뉙뉚뉛뉜뉝뉞뉟뉠뉡뉢뉣뉤뉥뉦뉧뉨뉩뉪뉫뉬뉭뉮뉯뉰뉱뉲뉳뉴뉵뉶뉷뉸뉹뉺뉻뉼뉽뉾뉿늀늁늂늃늄';
  1137. $result = Text::ascii($input);
  1138. $this->assertSame($expected, $result);
  1139. $input = [65136, 65137, 65138, 65139, 65140, 65141, 65142, 65143, 65144, 65145, 65146, 65147, 65148, 65149, 65150, 65151,
  1140. 65152, 65153, 65154, 65155, 65156, 65157, 65158, 65159, 65160, 65161, 65162, 65163, 65164, 65165, 65166, 65167,
  1141. 65168, 65169, 65170, 65171, 65172, 65173, 65174, 65175, 65176, 65177, 65178, 65179, 65180, 65181, 65182, 65183,
  1142. 65184, 65185, 65186, 65187, 65188, 65189, 65190, 65191, 65192, 65193, 65194, 65195, 65196, 65197, 65198, 65199,
  1143. 65200];
  1144. $expected = 'ﹰﹱﹲﹳﹴ﹵ﹶﹷﹸﹹﹺﹻﹼﹽﹾﹿﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰ';
  1145. $result = Text::ascii($input);
  1146. $this->assertSame($expected, $result);
  1147. $input = [65201, 65202, 65203, 65204, 65205, 65206, 65207, 65208, 65209, 65210, 65211, 65212, 65213, 65214, 65215, 65216,
  1148. 65217, 65218, 65219, 65220, 65221, 65222, 65223, 65224, 65225, 65226, 65227, 65228, 65229, 65230, 65231, 65232,
  1149. 65233, 65234, 65235, 65236, 65237, 65238, 65239, 65240, 65241, 65242, 65243, 65244, 65245, 65246, 65247, 65248,
  1150. 65249, 65250, 65251, 65252, 65253, 65254, 65255, 65256, 65257, 65258, 65259, 65260, 65261, 65262, 65263, 65264,
  1151. 65265, 65266, 65267, 65268, 65269, 65270, 65271, 65272, 65273, 65274, 65275, 65276];
  1152. $expected = 'ﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ';
  1153. $result = Text::ascii($input);
  1154. $this->assertSame($expected, $result);
  1155. $input = [65345, 65346, 65347, 65348, 65349, 65350, 65351, 65352, 65353, 65354, 65355, 65356, 65357, 65358, 65359, 65360,
  1156. 65361, 65362, 65363, 65364, 65365, 65366, 65367, 65368, 65369, 65370];
  1157. $expected = 'abcdefghijklmnopqrstuvwxyz';
  1158. $result = Text::ascii($input);
  1159. $this->assertSame($expected, $result);
  1160. $input = [65377, 65378, 65379, 65380, 65381, 65382, 65383, 65384, 65385, 65386, 65387, 65388, 65389, 65390, 65391, 65392,
  1161. 65393, 65394, 65395, 65396, 65397, 65398, 65399, 65400];
  1162. $expected = '。「」、・ヲァィゥェォャュョッーアイウエオカキク';
  1163. $result = Text::ascii($input);
  1164. $this->assertSame($expected, $result);
  1165. $input = [65401, 65402, 65403, 65404, 65405, 65406, 65407, 65408, 65409, 65410, 65411, 65412, 65413, 65414, 65415, 65416,
  1166. 65417, 65418, 65419, 65420, 65421, 65422, 65423, 65424, 65425, 65426, 65427, 65428, 65429, 65430, 65431, 65432,
  1167. 65433, 65434, 65435, 65436, 65437, 65438];
  1168. $expected = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
  1169. $result = Text::ascii($input);
  1170. $this->assertSame($expected, $result);
  1171. $input = [292, 275, 314, 316, 335, 44, 32, 372, 337, 345, 316, 271, 33];
  1172. $expected = 'Ĥēĺļŏ, Ŵőřļď!';
  1173. $result = Text::ascii($input);
  1174. $this->assertSame($expected, $result);
  1175. $input = [72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33];
  1176. $expected = 'Hello, World!';
  1177. $result = Text::ascii($input);
  1178. $this->assertSame($expected, $result);
  1179. $input = [168];
  1180. $expected = '¨';
  1181. $result = Text::ascii($input);
  1182. $this->assertSame($expected, $result);
  1183. $input = [191];
  1184. $expected = '¿';
  1185. $result = Text::ascii($input);
  1186. $this->assertSame($expected, $result);
  1187. $input = [269, 105, 110, 105];
  1188. $expected = 'čini';
  1189. $result = Text::ascii($input);
  1190. $this->assertSame($expected, $result);
  1191. $input = [109, 111, 263, 105];
  1192. $expected = 'moći';
  1193. $result = Text::ascii($input);
  1194. $this->assertSame($expected, $result);
  1195. $input = [100, 114, 382, 97, 118, 110, 105];
  1196. $expected = 'državni';
  1197. $result = Text::ascii($input);
  1198. $this->assertSame($expected, $result);
  1199. $input = [25226, 30334, 24230, 35774, 20026, 39318, 39029];
  1200. $expected = '把百度设为首页';
  1201. $result = Text::ascii($input);
  1202. $this->assertSame($expected, $result);
  1203. $input = [19968, 20108, 19977, 21608, 27704, 40845];
  1204. $expected = '一二三周永龍';
  1205. $result = Text::ascii($input);
  1206. $this->assertSame($expected, $result);
  1207. $input = [1280, 1282, 1284, 1286, 1288, 1290, 1292, 1294, 1296, 1298];
  1208. $expected = 'ԀԂԄԆԈԊԌԎԐԒ';
  1209. $result = Text::ascii($input);
  1210. $this->assertSame($expected, $result);
  1211. $input = [1281, 1283, 1285, 1287, 1289, 1291, 1293, 1295, 1296, 1298];
  1212. $expected = 'ԁԃԅԇԉԋԍԏԐԒ';
  1213. $result = Text::ascii($input);
  1214. $this->assertSame($expected, $result);
  1215. $input = [1329, 1330, 1331, 1332, 1333, 1334, 1335, 1336, 1337, 1338, 1339, 1340, 1341, 1342, 1343, 1344, 1345, 1346, 1347,
  1216. 1348, 1349, 1350, 1351, 1352, 1353, 1354, 1355, 1356, 1357, 1358, 1359, 1360, 1361, 1362, 1363, 1364, 1365,
  1217. 1366, 1415];
  1218. $result = Text::ascii($input);
  1219. $expected = 'ԱԲԳԴԵԶԷԸԹԺԻԼԽԾԿՀՁՂՃՄՅՆՇՈՉՊՋՌՍՎՏՐՑՒՓՔՕՖև';
  1220. $this->assertSame($expected, $result);
  1221. $input = [1377, 1378, 1379, 1380, 1381, 1382, 1383, 1384, 1385, 1386, 1387, 1388, 1389, 1390, 1391, 1392, 1393, 1394,
  1222. 1395, 1396, 1397, 1398, 1399, 1400, 1401, 1402, 1403, 1404, 1405, 1406, 1407, 1408, 1409, 1410, 1411, 1412,
  1223. 1413, 1414, 1415];
  1224. $result = Text::ascii($input);
  1225. $expected = 'աբգդեզէըթժիլխծկհձղճմյնշոչպջռսվտրցւփքօֆև';
  1226. $this->assertSame($expected, $result);
  1227. $input = [4256, 4257, 4258, 4259, 4260, 4261, 4262, 4263, 4264, 4265, 4266, 4267, 4268, 4269, 4270, 4271, 4272, 4273, 4274,
  1228. 4275, 4276, 4277, 4278, 4279, 4280, 4281, 4282, 4283, 4284, 4285, 4286, 4287, 4288, 4289, 4290, 4291, 4292, 4293];
  1229. $result = Text::ascii($input);
  1230. $expected = 'ႠႡႢႣႤႥႦႧႨႩႪႫႬႭႮႯႰႱႲႳႴႵႶႷႸႹႺႻႼႽႾႿჀჁჂჃჄჅ';
  1231. $this->assertSame($expected, $result);
  1232. $input = [7680, 7682, 7684, 7686, 7688, 7690, 7692, 7694, 7696, 7698, 7700, 7702, 7704, 7706, 7708, 7710, 7712, 7714,
  1233. 7716, 7718, 7720, 7722, 7724, 7726, 7728, 7730, 7732, 7734, 7736, 7738, 7740, 7742, 7744, 7746, 7748, 7750,
  1234. 7752, 7754, 7756, 7758, 7760, 7762, 7764, 7766, 7768, 7770, 7772, 7774, 7776, 7778, 7780, 7782, 7784, 7786,
  1235. 7788, 7790, 7792, 7794, 7796, 7798, 7800, 7802, 7804, 7806, 7808, 7810, 7812, 7814, 7816, 7818, 7820, 7822,
  1236. 7824, 7826, 7828, 7830, 7831, 7832, 7833, 7834, 7840, 7842, 7844, 7846, 7848, 7850, 7852, 7854, 7856,
  1237. 7858, 7860, 7862, 7864, 7866, 7868, 7870, 7872, 7874, 7876, 7878, 7880, 7882, 7884, 7886, 7888, 7890, 7892,
  1238. 7894, 7896, 7898, 7900, 7902, 7904, 7906, 7908, 7910, 7912, 7914, 7916, 7918, 7920, 7922, 7924, 7926, 7928];
  1239. $result = Text::ascii($input);
  1240. $expected = 'ḀḂḄḆḈḊḌḎḐḒḔḖḘḚḜḞḠḢḤḦḨḪḬḮḰḲḴḶḸḺḼḾṀṂṄṆṈṊṌṎṐṒṔṖṘṚṜṞṠṢṤṦṨṪṬṮṰṲṴṶṸṺṼṾẀẂẄẆẈẊẌẎẐẒẔẖẗẘẙẚẠẢẤẦẨẪẬẮẰẲẴẶẸẺẼẾỀỂỄỆỈỊỌỎỐỒỔỖỘỚỜỞỠỢỤỦỨỪỬỮỰỲỴỶỸ';
  1241. $this->assertSame($expected, $result);
  1242. $input = [7681, 7683, 7685, 7687, 7689, 7691, 7693, 7695, 7697, 7699, 7701, 7703, 7705, 7707, 7709, 7711, 7713, 7715,
  1243. 7717, 7719, 7721, 7723, 7725, 7727, 7729, 7731, 7733, 7735, 7737, 7739, 7741, 7743, 7745, 7747, 7749, 7751,
  1244. 7753, 7755, 7757, 7759, 7761, 7763, 7765, 7767, 7769, 7771, 7773, 7775, 7777, 7779, 7781, 7783, 7785, 7787,
  1245. 7789, 7791, 7793, 7795, 7797, 7799, 7801, 7803, 7805, 7807, 7809, 7811, 7813, 7815, 7817, 7819, 7821, 7823,
  1246. 7825, 7827, 7829, 7830, 7831, 7832, 7833, 7834, 7841, 7843, 7845, 7847, 7849, 7851, 7853, 7855, 7857, 7859,
  1247. 7861, 7863, 7865, 7867, 7869, 7871, 7873, 7875, 7877, 7879, 7881, 7883, 7885, 7887, 7889, 7891, 7893, 7895,
  1248. 7897, 7899, 7901, 7903, 7905, 7907, 7909, 7911, 7913, 7915, 7917, 7919, 7921, 7923, 7925, 7927, 7929];
  1249. $result = Text::ascii($input);
  1250. $expected = 'ḁḃḅḇḉḋḍḏḑḓḕḗḙḛḝḟḡḣḥḧḩḫḭḯḱḳḵḷḹḻḽḿṁṃṅṇṉṋṍṏṑṓṕṗṙṛṝṟṡṣṥṧṩṫṭṯṱṳṵṷṹṻṽṿẁẃẅẇẉẋẍẏẑẓẕẖẗẘẙẚạảấầẩẫậắằẳẵặẹẻẽếềểễệỉịọỏốồổỗộớờởỡợụủứừửữựỳỵỷỹ';
  1251. $this->assertSame($expected, $result);
  1252. $input = [8486, 8490, 8491, 8498];
  1253. $result = Text::ascii($input);
  1254. $expected = 'ΩKÅℲ';
  1255. $this->assertSame($expected, $result);
  1256. $input = [969, 107, 229, 8526];
  1257. $result = Text::ascii($input);
  1258. $expected = 'ωkåⅎ';
  1259. $this->assertSame($expected, $result);
  1260. $input = [8544, 8545, 8546, 8547, 8548, 8549, 8550, 8551, 8552, 8553, 8554, 8555, 8556, 8557, 8558, 8559, 8579];
  1261. $result = Text::ascii($input);
  1262. $expected = 'ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫⅬⅭⅮⅯↃ';
  1263. $this->assertSame($expected, $result);
  1264. $input = [8560, 8561, 8562, 8563, 8564, 8565, 8566, 8567, 8568, 8569, 8570, 8571, 8572, 8573, 8574, 8575, 8580];
  1265. $result = Text::ascii($input);
  1266. $expected = 'ⅰⅱⅲⅳⅴⅵⅶⅷⅸⅹⅺⅻⅼⅽⅾⅿↄ';
  1267. $this->assertSame($expected, $result);
  1268. $input = [9398, 9399, 9400, 9401, 9402, 9403, 9404, 9405, 9406, 9407, 9408, 9409, 9410, 9411, 9412, 9413, 9414,
  1269. 9415, 9416, 9417, 9418, 9419, 9420, 9421, 9422, 9423];
  1270. $result = Text::ascii($input);
  1271. $expected = 'ⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓌⓍⓎⓏ';
  1272. $this->assertSame($expected, $result);
  1273. $input = [9424, 9425, 9426, 9427, 9428, 9429, 9430, 9431, 9432, 9433, 9434, 9435, 9436, 9437, 9438, 9439, 9440, 9441,
  1274. 9442, 9443, 9444, 9445, 9446, 9447, 9448, 9449];
  1275. $result = Text::ascii($input);
  1276. $expected = 'ⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩ';
  1277. $this->assertSame($expected, $result);
  1278. $input = [11264, 11265, 11266, 11267, 11268, 11269, 11270, 11271, 11272, 11273, 11274, 11275, 11276, 11277, 11278, 11279,
  1279. 11280, 11281, 11282, 11283, 11284, 11285, 11286, 11287, 11288, 11289, 11290, 11291, 11292, 11293, 11294, 11295,
  1280. 11296, 11297, 11298, 11299, 11300, 11301, 11302, 11303, 11304, 11305, 11306, 11307, 11308, 11309, 11310];
  1281. $result = Text::ascii($input);
  1282. $expected = 'ⰀⰁⰂⰃⰄⰅⰆⰇⰈⰉⰊⰋⰌⰍⰎⰏⰐⰑⰒⰓⰔⰕⰖⰗⰘⰙⰚⰛⰜⰝⰞⰟⰠⰡⰢⰣⰤⰥⰦⰧⰨⰩⰪⰫⰬⰭⰮ';
  1283. $this->assertSame($expected, $result);
  1284. $input = [11312, 11313, 11314, 11315, 11316, 11317, 11318, 11319, 11320, 11321, 11322, 11323, 11324, 11325, 11326, 11327,
  1285. 11328, 11329, 11330, 11331, 11332, 11333, 11334, 11335, 11336, 11337, 11338, 11339, 11340, 11341, 11342, 11343,
  1286. 11344, 11345, 11346, 11347, 11348, 11349, 11350, 11351, 11352, 11353, 11354, 11355, 11356, 11357, 11358];
  1287. $result = Text::ascii($input);
  1288. $expected = 'ⰰⰱⰲⰳⰴⰵⰶⰷⰸⰹⰺⰻⰼⰽⰾⰿⱀⱁⱂⱃⱄⱅⱆⱇⱈⱉⱊⱋⱌⱍⱎⱏⱐⱑⱒⱓⱔⱕⱖⱗⱘⱙⱚⱛⱜⱝⱞ';
  1289. $this->assertSame($expected, $result);
  1290. $input = [11392, 11394, 11396, 11398, 11400, 11402, 11404, 11406, 11408, 11410, 11412, 11414, 11416, 11418, 11420,
  1291. 11422, 11424, 11426, 11428, 11430, 11432, 11434, 11436, 11438, 11440, 11442, 11444, 11446, 11448, 11450,
  1292. 11452, 11454, 11456, 11458, 11460, 11462, 11464, 11466, 11468, 11470, 11472, 11474, 11476, 11478, 11480,
  1293. 11482, 11484, 11486, 11488, 11490];
  1294. $result = Text::ascii($input);
  1295. $expected = 'ⲀⲂⲄⲆⲈⲊⲌⲎⲐⲒⲔⲖⲘⲚⲜⲞⲠⲢⲤⲦⲨⲪⲬⲮⲰⲲⲴⲶⲸⲺⲼⲾⳀⳂⳄⳆⳈⳊⳌⳎⳐⳒⳔⳖⳘⳚⳜⳞⳠⳢ';
  1296. $this->assertSame($expected, $result);
  1297. $input = [11393, 11395, 11397, 11399, 11401, 11403, 11405, 11407, 11409, 11411, 11413, 11415, 11417, 11419, 11421, 11423,
  1298. 11425, 11427, 11429, 11431, 11433, 11435, 11437, 11439, 11441, 11443, 11445, 11447, 11449, 11451, 11453, 11455,
  1299. 11457, 11459, 11461, 11463, 11465, 11467, 11469, 11471, 11473, 11475, 11477, 11479, 11481, 11483, 11485, 11487,
  1300. 11489, 11491];
  1301. $result = Text::ascii($input);
  1302. $expected = 'ⲁⲃⲅⲇⲉⲋⲍⲏⲑⲓⲕⲗⲙⲛⲝⲟⲡⲣⲥⲧⲩⲫⲭⲯⲱⲳⲵⲷⲹⲻⲽⲿⳁⳃⳅⳇⳉⳋⳍⳏⳑⳓⳕⳗⳙⳛⳝⳟⳡⳣ';
  1303. $this->assertSame($expected, $result);
  1304. $input = [64256, 64257, 64258, 64259, 64260, 64261, 64262, 64275, 64276, 64277, 64278, 64279];
  1305. $result = Text::ascii($input);
  1306. $expected = 'fffiflffifflſtstﬓﬔﬕﬖﬗ';
  1307. $this->assertSame($expected, $result);
  1308. }
  1309. /**
  1310. * testparseFileSize
  1311. *
  1312. * @param mixed $expected
  1313. */
  1314. #[DataProvider('filesizes')]
  1315. public function testParseFileSize(array $params, $expected): void
  1316. {
  1317. $result = Text::parseFileSize($params['size'], $params['default']);
  1318. $this->assertSame($expected, $result);
  1319. }
  1320. /**
  1321. * testparseFileSizeException
  1322. */
  1323. public function testParseFileSizeException(): void
  1324. {
  1325. $this->expectException(InvalidArgumentException::class);
  1326. Text::parseFileSize('bogus', false);
  1327. }
  1328. /**
  1329. * filesizes dataprovider
  1330. *
  1331. * @return array
  1332. */
  1333. public static function filesizes(): array
  1334. {
  1335. return [
  1336. [['size' => '512B', 'default' => false], 512],
  1337. [['size' => '1KB', 'default' => false], 1024],
  1338. [['size' => '1.5KB', 'default' => false], 1536],
  1339. [['size' => '1MB', 'default' => false], 1048576],
  1340. [['size' => '1mb', 'default' => false], 1048576],
  1341. [['size' => '1.5MB', 'default' => false], 1572864],
  1342. [['size' => '1GB', 'default' => false], 1073741824],
  1343. [['size' => '1.5GB', 'default' => false], 1610612736],
  1344. [['size' => '1K', 'default' => false], 1024],
  1345. [['size' => '1.5K', 'default' => false], 1536],
  1346. [['size' => '1M', 'default' => false], 1048576],
  1347. [['size' => '1m', 'default' => false], 1048576],
  1348. [['size' => '1.5M', 'default' => false], 1572864],
  1349. [['size' => '1G', 'default' => false], 1073741824],
  1350. [['size' => '1.5G', 'default' => false], 1610612736],
  1351. [['size' => '512', 'default' => 'Unknown type'], 512],
  1352. [['size' => '2VB', 'default' => 'Unknown type'], 'Unknown type'],
  1353. ];
  1354. }
  1355. /**
  1356. * Test getting/setting default transliterator.
  1357. */
  1358. public function testGetSetTransliterator(): void
  1359. {
  1360. $this->assertNull(Text::getTransliterator());
  1361. $transliterator = Transliterator::createFromRules('
  1362. $nonletter = [:^Letter:];
  1363. $nonletter → \'*\';
  1364. ::Latin-ASCII;
  1365. ');
  1366. $this->assertInstanceOf(Transliterator::class, $transliterator);
  1367. Text::setTransliterator($transliterator);
  1368. $this->assertSame($transliterator, Text::getTransliterator());
  1369. }
  1370. /**
  1371. * Test getting/setting default transliterator id.
  1372. */
  1373. public function testGetSetTransliteratorId(): void
  1374. {
  1375. $defaultTransliteratorId = 'Any-Latin; Latin-ASCII; [\u0080-\u7fff] remove';
  1376. $this->assertSame($defaultTransliteratorId, Text::getTransliteratorId());
  1377. $expected = 'Latin-ASCII;[\u0080-\u7fff] remove';
  1378. Text::setTransliteratorId($expected);
  1379. $this->assertSame($expected, Text::getTransliteratorId());
  1380. $this->assertInstanceOf(Transliterator::class, Text::getTransliterator());
  1381. $this->assertSame($expected, Text::getTransliterator()->id);
  1382. Text::setTransliteratorId($defaultTransliteratorId);
  1383. }
  1384. /**
  1385. * Data provider for testTransliterate()
  1386. *
  1387. * @return array
  1388. */
  1389. public static function transliterateInputProvider(): array
  1390. {
  1391. return [
  1392. [
  1393. 'Foo Bar: Not just for breakfast any-more', null,
  1394. 'Foo Bar: Not just for breakfast any-more',
  1395. ],
  1396. [
  1397. 'A æ Übérmensch på høyeste nivå! И я люблю PHP! ест. fi ¦', null,
  1398. 'A ae Ubermensch pa hoyeste niva! I a lublu PHP! est. fi ',
  1399. ],
  1400. [
  1401. 'Äpfel Über Öl grün ärgert groß öko',
  1402. transliterator_create_from_rules('
  1403. $AE = [Ä {A \u0308}];
  1404. $OE = [Ö {O \u0308}];
  1405. $UE = [Ü {U \u0308}];
  1406. [ä {a \u0308}] → ae;
  1407. [ö {o \u0308}] → oe;
  1408. [ü {u \u0308}] → ue;
  1409. {$AE} [:Lowercase:] → Ae;
  1410. {$OE} [:Lowercase:] → Oe;
  1411. {$UE} [:Lowercase:] → Ue;
  1412. $AE → AE;
  1413. $OE → OE;
  1414. $UE → UE;
  1415. ::Latin-ASCII;
  1416. '),
  1417. 'Aepfel Ueber Oel gruen aergert gross oeko',
  1418. ],
  1419. [
  1420. 'La langue française est un attribut de souveraineté en France', null,
  1421. 'La langue francaise est un attribut de souverainete en France',
  1422. ],
  1423. [
  1424. '!@$#exciting stuff! - what !@-# was that?', null,
  1425. '!@$#exciting stuff! - what !@-# was that?',
  1426. ],
  1427. [
  1428. 'controller/action/りんご/1', null,
  1429. 'controller/action/ringo/1',
  1430. ],
  1431. [
  1432. 'の話が出たので大丈夫かなあと', null,
  1433. 'no huaga chutanode da zhang fukanaato',
  1434. ],
  1435. [
  1436. 'posts/view/한국어/page:1/sort:asc', null,
  1437. 'posts/view/hangug-eo/page:1/sort:asc',
  1438. ],
  1439. [
  1440. "non\xc2\xa0breaking\xc2\xa0space", null,
  1441. 'non breaking space',
  1442. ],
  1443. ];
  1444. }
  1445. /**
  1446. * testTransliterate method
  1447. *
  1448. * @param string $string String
  1449. * @param \Transliterator|string|null $transliterator Transliterator
  1450. * @param String $expected Expected string
  1451. */
  1452. #[DataProvider('transliterateInputProvider')]
  1453. public function testTransliterate($string, $transliterator, $expected): void
  1454. {
  1455. $result = Text::transliterate($string, $transliterator);
  1456. $this->assertSame($expected, $result);
  1457. }
  1458. /**
  1459. * @return array
  1460. */
  1461. public static function slugInputProvider(): array
  1462. {
  1463. return [
  1464. [
  1465. 'Foo Bar: Not just for breakfast any-more', [],
  1466. 'Foo-Bar-Not-just-for-breakfast-any-more',
  1467. ],
  1468. [
  1469. 'Foo Bar: Not just for breakfast any-more', ['replacement' => '_'],
  1470. 'Foo_Bar_Not_just_for_breakfast_any_more',
  1471. ],
  1472. [
  1473. 'Foo Bar: Not just for breakfast any-more', ['replacement' => '+'],
  1474. 'Foo+Bar+Not+just+for+breakfast+any+more',
  1475. ],
  1476. [
  1477. 'A æ Übérmensch på høyeste nivå! И я люблю PHP! есть. fi ¦', [],
  1478. 'A-ae-Ubermensch-pa-hoyeste-niva-I-a-lublu-PHP-est-fi',
  1479. ],
  1480. [
  1481. 'A æ Übérmensch på høyeste nivå! И я люблю PHP! есть. fi ¦', ['transliteratorId' => 'Latin-ASCII'],
  1482. 'A-ae-Ubermensch-pa-hoyeste-niva-И-я-люблю-PHP-есть-fi',
  1483. ],
  1484. [
  1485. 'Äpfel Über Öl grün ärgert groß öko', [],
  1486. 'Apfel-Uber-Ol-grun-argert-gross-oko',
  1487. ],
  1488. [
  1489. 'The truth - and- more- news', [],
  1490. 'The-truth-and-more-news',
  1491. ],
  1492. [
  1493. 'The truth: and more news', [],
  1494. 'The-truth-and-more-news',
  1495. ],
  1496. [
  1497. 'La langue française est un attribut de souveraineté en France', [],
  1498. 'La-langue-francaise-est-un-attribut-de-souverainete-en-France',
  1499. ],
  1500. [
  1501. '!@$#exciting stuff! - what !@-# was that?', [],
  1502. 'exciting-stuff-what-was-that',
  1503. ],
  1504. [
  1505. '20% of profits went to me!', [],
  1506. '20-of-profits-went-to-me',
  1507. ],
  1508. [
  1509. '#this melts your face1#2#3', [],
  1510. 'this-melts-your-face1-2-3',
  1511. ],
  1512. [
  1513. 'controller/action/りんご/1', ['transliteratorId' => false],
  1514. 'controller-action-りんご-1',
  1515. ],
  1516. [
  1517. 'の話が出たので大丈夫かなあと', ['transliteratorId' => false],
  1518. 'の話が出たので大丈夫かなあと',
  1519. ],
  1520. [
  1521. 'posts/view/한국어/page:1/sort:asc', ['transliteratorId' => false],
  1522. 'posts-view-한국어-page-1-sort-asc',
  1523. ],
  1524. [
  1525. "non\xc2\xa0breaking\xc2\xa0space", [],
  1526. 'non-breaking-space',
  1527. ],
  1528. [
  1529. 'Foo Bar: Not just for breakfast any-more', ['replacement' => ''],
  1530. 'FooBarNotjustforbreakfastanymore',
  1531. ],
  1532. [
  1533. 'clean!_me.tar.gz', ['preserve' => '.'],
  1534. 'clean-me.tar.gz',
  1535. ],
  1536. [
  1537. 'cl#ean(me', [],
  1538. 'cl-ean-me',
  1539. ],
  1540. [
  1541. 'cl#e|an(me.jpg', ['preserve' => '.'],
  1542. 'cl-e-an-me.jpg',
  1543. ],
  1544. [
  1545. 'Foo Bar: Not just for breakfast any-more', ['preserve' => ' '],
  1546. 'Foo Bar- Not just for breakfast any-more',
  1547. ],
  1548. [
  1549. 'Foo Bar: Not just for (breakfast) any-more', ['preserve' => ' ()'],
  1550. 'Foo Bar- Not just for (breakfast) any-more',
  1551. ],
  1552. [
  1553. 'Foo Bar: Not just for breakfast any-more', ['replacement' => null],
  1554. 'FooBarNotjustforbreakfastanymore',
  1555. ],
  1556. [
  1557. 'Foo Bar: Not just for breakfast any-more', ['replacement' => false],
  1558. 'FooBarNotjustforbreakfastanymore',
  1559. ],
  1560. ];
  1561. }
  1562. /**
  1563. * testSlug method
  1564. *
  1565. * @param string $string String
  1566. * @param array $options Options
  1567. * @param String $expected Expected string
  1568. */
  1569. #[DataProvider('slugInputProvider')]
  1570. public function testSlug($string, $options, $expected): void
  1571. {
  1572. $result = Text::slug($string, $options);
  1573. $this->assertSame($expected, $result);
  1574. }
  1575. /**
  1576. * Text truncateByWidth method
  1577. */
  1578. public function testTruncateByWidth(): void
  1579. {
  1580. $this->assertSame('<p>あい…', Text::truncateByWidth('<p>あいうえお</p>', 8));
  1581. $this->assertSame('<p>あい...</p>', Text::truncateByWidth('<p>あいうえお</p>', 8, ['html' => true, 'ellipsis' => '...']));
  1582. }
  1583. /**
  1584. * Test _strlen method
  1585. */
  1586. public function testStrlen(): void
  1587. {
  1588. $method = new ReflectionMethod(Text::class, '_strlen');
  1589. $strlen = function () use ($method) {
  1590. return $method->invokeArgs(null, func_get_args());
  1591. };
  1592. $text = 'データベースアクセス &amp; ORM';
  1593. $this->assertSame(20, $strlen($text, []));
  1594. $this->assertSame(16, $strlen($text, ['html' => true]));
  1595. $this->assertSame(30, $strlen($text, ['trimWidth' => true]));
  1596. $this->assertSame(26, $strlen($text, ['html' => true, 'trimWidth' => true]));
  1597. $text = '&undefined;';
  1598. $this->assertSame(11, $strlen($text, []));
  1599. $this->assertSame(11, $strlen($text, ['trimWidth' => true]));
  1600. $this->assertSame(11, $strlen($text, ['html' => true]));
  1601. $this->assertSame(11, $strlen($text, ['html' => true, 'trimWidth' => true]));
  1602. }
  1603. /**
  1604. * Test _substr method
  1605. */
  1606. public function testSubstr(): void
  1607. {
  1608. $method = new ReflectionMethod(Text::class, '_substr');
  1609. $substr = function () use ($method) {
  1610. return $method->invokeArgs(null, func_get_args());
  1611. };
  1612. $text = 'データベースアクセス &amp; ORM';
  1613. $this->assertSame('アクセス', $substr($text, 6, 4, []));
  1614. $this->assertSame('アクセス', $substr($text, 6, 8, ['trimWidth' => true]));
  1615. $this->assertSame('アクセス', $substr($text, 6, 4, ['html' => true]));
  1616. $this->assertSame(' &amp; ', $substr($text, 10, 7, []));
  1617. $this->assertSame(' &amp; ', $substr($text, 10, 7, ['trimWidth' => true]));
  1618. $this->assertSame(' &amp; ', $substr($text, 10, 3, ['html' => true]));
  1619. $this->assertSame(' &amp; ', $substr($text, -10, 7, []));
  1620. $this->assertSame(' &amp; ', $substr($text, -10, 7, ['trimWidth' => true]));
  1621. $this->assertSame(' &amp; ', $substr($text, -6, 3, ['html' => true]));
  1622. $this->assertSame(' &amp; ', $substr($text, -10, -3, []));
  1623. $this->assertSame(' &amp; ', $substr($text, -10, -3, ['trimWidth' => true]));
  1624. $this->assertSame(' &amp; ', $substr($text, -6, -3, ['html' => true]));
  1625. $this->assertSame('ORM', $substr($text, -3, 1000, []));
  1626. $this->assertSame('ORM', $substr($text, -3, 1000, ['trimWidth' => true]));
  1627. $this->assertSame('ORM', $substr($text, -3, 1000, ['html' => true]));
  1628. $this->assertSame('ORM', $substr($text, -3, null, []));
  1629. $this->assertSame('ORM', $substr($text, -3, null, ['trimWidth' => true]));
  1630. $this->assertSame('ORM', $substr($text, -3, null, ['html' => true]));
  1631. $this->assertSame('データ', $substr($text, -1000, 3, []));
  1632. $this->assertSame('データ', $substr($text, -1000, 6, ['trimWidth' => true]));
  1633. $this->assertSame('データ', $substr($text, -1000, 3, ['html' => true]));
  1634. $this->assertSame('', $substr($text, 0, 0, []));
  1635. $this->assertSame('', $substr($text, 0, 0, ['trimWidth' => true]));
  1636. $this->assertSame('', $substr($text, 0, 0, ['html' => true]));
  1637. $this->assertSame('', $substr($text, 1000, 1, []));
  1638. $this->assertSame('', $substr($text, 1000, 1, ['trimWidth' => true]));
  1639. $this->assertSame('', $substr($text, 1000, 1, ['html' => true]));
  1640. $this->assertSame('', $substr($text, 0, -1000, []));
  1641. $this->assertSame('', $substr($text, 0, -1000, ['trimWidth' => true]));
  1642. $this->assertSame('', $substr($text, 0, -1000, ['html' => true]));
  1643. // ABCDE
  1644. $text = '&#65;&#66;&#67;&#68;&#69;';
  1645. $this->assertSame('&#66;&#67;&#68;', $substr($text, 1, 3, ['html' => true]));
  1646. $this->assertSame('&#66;&#67;&#68;', $substr($text, 1, 3, ['html' => true, 'trimWidth' => true]));
  1647. $this->assertSame('&#66;&#67;&#68;', $substr($text, -4, -1, ['html' => true]));
  1648. $this->assertSame('&#66;&#67;&#68;', $substr($text, -4, -1, ['html' => true, 'trimWidth' => true]));
  1649. // あいうえお
  1650. $text = '&#x3042;&#x3044;&#x3046;&#x3048;&#x304a;';
  1651. $this->assertSame('&#x3044;&#x3046;&#x3048;', $substr($text, 1, 3, ['html' => true]));
  1652. $this->assertSame('&#x3044;&#x3046;&#x3048;', $substr($text, 1, 6, ['html' => true, 'trimWidth' => true]));
  1653. $this->assertSame('&#x3044;&#x3046;&#x3048;', $substr($text, -4, -1, ['html' => true]));
  1654. $this->assertSame('&#x3044;&#x3046;&#x3048;', $substr($text, -4, -1, ['html' => true, 'trimWidth' => true]));
  1655. $this->assertSame('&#x3044;&#x3046;&#x3048;', $substr($text, -4, -2, ['html' => true, 'trimWidth' => true]));
  1656. }
  1657. }