TextTest.php 100 KB

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