TextTest.php 92 KB

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