comparison core/modules/search/tests/src/Functional/SearchTokenizerTest.php @ 4:a9cd425dd02b

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:11:55 +0000
parents c75dbcec494b
children
comparison
equal deleted inserted replaced
3:307d7a7fd348 4:a9cd425dd02b
1 <?php 1 <?php
2 2
3 namespace Drupal\Tests\search\Functional; 3 namespace Drupal\Tests\search\Functional;
4 4
5 use Drupal\Component\Utility\Unicode; 5 use Drupal\Tests\BrowserTestBase;
6 6
7 /** 7 /**
8 * Tests that CJK tokenizer works as intended. 8 * Tests that CJK tokenizer works as intended.
9 * 9 *
10 * @group search 10 * @group search
11 */ 11 */
12 class SearchTokenizerTest extends SearchTestBase { 12 class SearchTokenizerTest extends BrowserTestBase {
13
14 /**
15 * {@inheritdoc}
16 */
17 protected static $modules = ['search'];
13 18
14 /** 19 /**
15 * Verifies that strings of CJK characters are tokenized. 20 * Verifies that strings of CJK characters are tokenized.
16 * 21 *
17 * The search_simplify() function does special things with numbers, symbols, 22 * The search_simplify() function does special things with numbers, symbols,
93 } 98 }
94 99
95 // Merge into a string and tokenize. 100 // Merge into a string and tokenize.
96 $string = implode('', $chars); 101 $string = implode('', $chars);
97 $out = trim(search_simplify($string)); 102 $out = trim(search_simplify($string));
98 $expected = Unicode::strtolower(implode(' ', $chars)); 103 $expected = mb_strtolower(implode(' ', $chars));
99 104
100 // Verify that the output matches what we expect. 105 // Verify that the output matches what we expect.
101 $this->assertEqual($out, $expected, 'CJK tokenizer worked on all supplied CJK characters'); 106 $this->assertEqual($out, $expected, 'CJK tokenizer worked on all supplied CJK characters');
102 } 107 }
103 108
123 } 128 }
124 129
125 /** 130 /**
126 * Like PHP chr() function, but for unicode characters. 131 * Like PHP chr() function, but for unicode characters.
127 * 132 *
128 * chr() only works for ASCII characters up to character 255. This function 133 * Function chr() only works for ASCII characters up to character 255. This
129 * converts a number to the corresponding unicode character. Adapted from 134 * function converts a number to the corresponding unicode character. Adapted
130 * functions supplied in comments on several functions on php.net. 135 * from functions supplied in comments on several functions on php.net.
131 */ 136 */
132 public function code2utf($num) { 137 public function code2utf($num) {
133 if ($num < 128) { 138 if ($num < 128) {
134 return chr($num); 139 return chr($num);
135 } 140 }