TextTest.php 98 KB

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