]> git.openstreetmap.org Git - nominatim.git/blob - test/php/Nominatim/TokenListTest.php
Merge remote-tracking branch 'upstream/master'
[nominatim.git] / test / php / Nominatim / TokenListTest.php
1 <?php
2
3 namespace Nominatim;
4
5 require_once(CONST_LibDir.'/TokenList.php');
6
7
8 class TokenTest extends \PHPUnit\Framework\TestCase
9 {
10     protected function setUp(): void
11     {
12         $this->oNormalizer = $this->getMockBuilder(\MockNormalizer::class)
13                                   ->setMethods(array('transliterate'))
14                                   ->getMock();
15         $this->oNormalizer->method('transliterate')
16                           ->will($this->returnCallback(function ($text) {
17                               return strtolower($text);
18                           }));
19     }
20
21     private function wordResult($aFields)
22     {
23         $aRow = array(
24                  'word_id' => null,
25                  'word_token' => null,
26                  'word' => null,
27                  'class' => null,
28                  'type' => null,
29                  'country_code' => null,
30                  'count' => 0
31                 );
32         return array_merge($aRow, $aFields);
33     }
34
35     public function testList()
36     {
37         $TL = new TokenList;
38
39         $this->assertEquals(0, $TL->count());
40
41         $TL->addToken('word1', 'token1');
42         $TL->addToken('word1', 'token2');
43
44         $this->assertEquals(1, $TL->count());
45
46         $this->assertTrue($TL->contains('word1'));
47         $this->assertEquals(array('token1', 'token2'), $TL->get('word1'));
48
49         $this->assertFalse($TL->contains('unknownword'));
50         $this->assertEquals(array(), $TL->get('unknownword'));
51     }
52 }