TextTest.php 99 KB

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