TextTest.php 106 KB

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