TextTest.php 101 KB

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