]> git.openstreetmap.org Git - nominatim.git/blob - test/php/Nominatim/TokenListTest.php
Install scripts: remove version from /var/run/php-fpm filenames
[nominatim.git] / test / php / Nominatim / TokenListTest.php
1 <?php
2 /**
3  * SPDX-License-Identifier: GPL-2.0-only
4  *
5  * This file is part of Nominatim. (https://nominatim.org)
6  *
7  * Copyright (C) 2022 by the Nominatim developer community.
8  * For a full list of authors see the git log.
9  */
10
11 namespace Nominatim;
12
13 require_once(CONST_LibDir.'/TokenList.php');
14
15
16 class TokenListTest extends \PHPUnit\Framework\TestCase
17 {
18     protected function setUp(): void
19     {
20         $this->oNormalizer = $this->getMockBuilder(\MockNormalizer::class)
21                                   ->setMethods(array('transliterate'))
22                                   ->getMock();
23         $this->oNormalizer->method('transliterate')
24                           ->will($this->returnCallback(function ($text) {
25                               return strtolower($text);
26                           }));
27     }
28
29     private function wordResult($aFields)
30     {
31         $aRow = array(
32                  'word_id' => null,
33                  'word_token' => null,
34                  'word' => null,
35                  'class' => null,
36                  'type' => null,
37                  'country_code' => null,
38                  'count' => 0
39                 );
40         return array_merge($aRow, $aFields);
41     }
42
43     public function testList()
44     {
45         $TL = new TokenList;
46
47         $this->assertEquals(0, $TL->count());
48
49         $TL->addToken('word1', 'token1');
50         $TL->addToken('word1', 'token2');
51
52         $this->assertEquals(1, $TL->count());
53
54         $this->assertTrue($TL->contains('word1'));
55         $this->assertEquals(array('token1', 'token2'), $TL->get('word1'));
56
57         $this->assertFalse($TL->contains('unknownword'));
58         $this->assertEquals(array(), $TL->get('unknownword'));
59     }
60 }