From 06683edaae8bfa517e488375d710ca6532336725 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Sun, 15 Sep 2024 11:26:49 +0200 Subject: [PATCH] remove PHP tests --- .github/workflows/ci-tests.yml | 93 ------- test/Makefile | 8 +- test/php/Nominatim/AddressDetailsTest.php | 118 --------- test/php/Nominatim/ClassTypesTest.php | 102 ------- test/php/Nominatim/DBTest.php | 228 ---------------- test/php/Nominatim/DatabaseErrorTest.php | 39 --- test/php/Nominatim/DebugTest.php | 209 --------------- test/php/Nominatim/LibTest.php | 94 ------- test/php/Nominatim/ParameterParserTest.php | 248 ------------------ test/php/Nominatim/ResultTest.php | 43 --- test/php/Nominatim/SearchContextTest.php | 89 ------- test/php/Nominatim/ShellTest.php | 128 --------- test/php/Nominatim/SimpleWordListTest.php | 136 ---------- test/php/Nominatim/StatusTest.php | 81 ------ test/php/Nominatim/TokenListTest.php | 60 ----- test/php/Nominatim/tokenizer.php | 25 -- test/php/bootstrap.php | 14 - .../address_details_10_downing_street.json | 217 --------------- test/php/phpunit.xml | 26 -- 19 files changed, 2 insertions(+), 1956 deletions(-) delete mode 100644 test/php/Nominatim/AddressDetailsTest.php delete mode 100644 test/php/Nominatim/ClassTypesTest.php delete mode 100644 test/php/Nominatim/DBTest.php delete mode 100644 test/php/Nominatim/DatabaseErrorTest.php delete mode 100644 test/php/Nominatim/DebugTest.php delete mode 100644 test/php/Nominatim/LibTest.php delete mode 100644 test/php/Nominatim/ParameterParserTest.php delete mode 100644 test/php/Nominatim/ResultTest.php delete mode 100644 test/php/Nominatim/SearchContextTest.php delete mode 100644 test/php/Nominatim/ShellTest.php delete mode 100644 test/php/Nominatim/SimpleWordListTest.php delete mode 100644 test/php/Nominatim/StatusTest.php delete mode 100644 test/php/Nominatim/TokenListTest.php delete mode 100644 test/php/Nominatim/tokenizer.php delete mode 100644 test/php/bootstrap.php delete mode 100644 test/php/fixtures/address_details_10_downing_street.json delete mode 100644 test/php/phpunit.xml diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml index 1cfaf616..21d506ae 100644 --- a/.github/workflows/ci-tests.yml +++ b/.github/workflows/ci-tests.yml @@ -131,99 +131,6 @@ jobs: working-directory: Nominatim if: matrix.flavour != 'oldstuff' - legacy-test: - needs: create-archive - runs-on: ubuntu-20.04 - - strategy: - matrix: - postgresql: ["13", "16"] - - steps: - - uses: actions/download-artifact@v4 - with: - name: full-source - - - name: Unpack Nominatim - run: tar xf nominatim-src.tar.bz2 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: '7.4' - - - uses: ./Nominatim/.github/actions/setup-postgresql - with: - postgresql-version: ${{ matrix.postgresql }} - postgis-version: 3 - - - name: Install Postgresql server dev - run: sudo apt-get install postgresql-server-dev-$PGVER - env: - PGVER: ${{ matrix.postgresql }} - - - uses: ./Nominatim/.github/actions/build-nominatim - with: - cmake-args: -DBUILD_MODULE=on - - - name: Install test prerequisites - run: sudo apt-get install -y -qq python3-behave - - - name: BDD tests (legacy tokenizer) - run: | - export PATH=$GITHUB_WORKSPACE/build/osm2pgsql:$PATH - python3 -m behave -DREMOVE_TEMPLATE=1 -DSERVER_MODULE_PATH=$GITHUB_WORKSPACE/build/module -DAPI_ENGINE=php -DTOKENIZER=legacy --format=progress3 - working-directory: Nominatim/test/bdd - - - php-test: - needs: create-archive - runs-on: ubuntu-22.04 - - steps: - - uses: actions/download-artifact@v4 - with: - name: full-source - - - name: Unpack Nominatim - run: tar xf nominatim-src.tar.bz2 - - - uses: ./Nominatim/.github/actions/setup-postgresql - with: - postgresql-version: 15 - postgis-version: 3 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: 8.1 - tools: phpunit:9, phpcs, composer - ini-values: opcache.jit=disable - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: PHP linting - run: phpcs --report-width=120 . - working-directory: Nominatim - - - name: PHP unit tests - run: phpunit ./ - working-directory: Nominatim/test/php - - - uses: ./Nominatim/.github/actions/build-nominatim - with: - flavour: 'ubuntu-22' - - - name: Install test prerequisites - run: sudo apt-get install -y -qq python3-behave - - - name: BDD tests (php) - run: | - export PATH=$GITHUB_WORKSPACE/build/osm2pgsql:$PATH - python3 -m behave -DREMOVE_TEMPLATE=1 -DAPI_ENGINE=php --format=progress3 - working-directory: Nominatim/test/bdd - - install: runs-on: ubuntu-latest needs: create-archive diff --git a/test/Makefile b/test/Makefile index 5f78eeac..9768ebd7 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,14 +1,10 @@ -all: bdd php python -no-test-db: bdd-no-test-db php +all: bdd python bdd: cd bdd && behave -DREMOVE_TEMPLATE=1 -php: - cd php && phpunit ./ - python: pytest python -.PHONY: bdd php no-test-db python +.PHONY: bdd python diff --git a/test/php/Nominatim/AddressDetailsTest.php b/test/php/Nominatim/AddressDetailsTest.php deleted file mode 100644 index 2041dcb4..00000000 --- a/test/php/Nominatim/AddressDetailsTest.php +++ /dev/null @@ -1,118 +0,0 @@ -oDbStub = $this->getMockBuilder(\DB::class) - ->setMethods(array('getAll')) - ->getMock(); - $this->oDbStub->method('getAll') - ->willReturn($data); - } - - public function testGetLocaleAddress() - { - $oAD = new AddressDetails($this->oDbStub, 194663412, 10, 'en'); - $expected = join(', ', array( - '10 Downing Street', - '10', - 'Downing Street', - 'St. James\'s', - 'Covent Garden', - 'Westminster', - 'London', - 'Greater London', - 'England', - 'SW1A 2AA', - 'United Kingdom' - )); - $this->assertEquals($expected, $oAD->getLocaleAddress()); - } - - public function testGetAddressDetails() - { - $oAD = new AddressDetails($this->oDbStub, 194663412, 10, 'en'); - $this->assertEquals(18, count($oAD->getAddressDetails(true))); - $this->assertEquals(12, count($oAD->getAddressDetails(false))); - } - - public function testGetAddressNames() - { - $oAD = new AddressDetails($this->oDbStub, 194663412, 10, 'en'); - $expected = array( - 'tourism' => '10 Downing Street', - 'house_number' => '10', - 'road' => 'Downing Street', - 'neighbourhood' => 'St. James\'s', - 'suburb' => 'Covent Garden', - 'city' => 'London', - 'state_district' => 'Greater London', - 'state' => 'England', - 'ISO3166-2-lvl4' => 'GB-ENG', - 'ISO3166-2-lvl6' => 'GB-LND', - 'postcode' => 'SW1A 2AA', - 'country' => 'United Kingdom', - 'country_code' => 'gb' - ); - - $this->assertEquals($expected, $oAD->getAddressNames()); - } - - public function testGetAdminLevels() - { - $oAD = new AddressDetails($this->oDbStub, 194663412, 10, 'en'); - $expected = array( - 'level8' => 'Westminster', - 'level6' => 'London', - 'level5' => 'Greater London', - 'level4' => 'England', - 'level2' => 'United Kingdom' - ); - $this->assertEquals($expected, $oAD->getAdminLevels()); - } - - public function testDebugInfo() - { - $oAD = new AddressDetails($this->oDbStub, 194663412, 10, 'en'); - $this->assertTrue(is_array($oAD->debugInfo())); - $this->assertEquals(18, count($oAD->debugInfo())); - } -} diff --git a/test/php/Nominatim/ClassTypesTest.php b/test/php/Nominatim/ClassTypesTest.php deleted file mode 100644 index d2900d82..00000000 --- a/test/php/Nominatim/ClassTypesTest.php +++ /dev/null @@ -1,102 +0,0 @@ - 'boundary', 'type' => 'administrative', - 'rank_address' => '4', 'place_type' => 'city'); - $this->assertEquals('city', ClassTypes\getLabelTag($aPlace)); - - $aPlace = array('class' => 'boundary', 'type' => 'administrative', - 'rank_address' => '10'); - $this->assertEquals('state_district', ClassTypes\getLabelTag($aPlace)); - - $aPlace = array('class' => 'boundary', 'type' => 'administrative'); - $this->assertEquals('administrative', ClassTypes\getLabelTag($aPlace)); - - $aPlace = array('class' => 'place', 'type' => 'hamlet', 'rank_address' => '20'); - $this->assertEquals('hamlet', ClassTypes\getLabelTag($aPlace)); - - $aPlace = array('class' => 'highway', 'type' => 'residential', - 'rank_address' => '26'); - $this->assertEquals('road', ClassTypes\getLabelTag($aPlace)); - - $aPlace = array('class' => 'place', 'type' => 'house_number', - 'rank_address' => '30'); - $this->assertEquals('house_number', ClassTypes\getLabelTag($aPlace)); - - $aPlace = array('class' => 'amenity', 'type' => 'prison', - 'rank_address' => '30'); - $this->assertEquals('amenity', ClassTypes\getLabelTag($aPlace)); - } - - public function testGetLabel() - { - $aPlace = array('class' => 'boundary', 'type' => 'administrative', - 'rank_address' => '4', 'place_type' => 'city'); - $this->assertEquals('City', ClassTypes\getLabel($aPlace)); - - $aPlace = array('class' => 'boundary', 'type' => 'administrative', - 'rank_address' => '10'); - $this->assertEquals('State District', ClassTypes\getLabel($aPlace)); - - $aPlace = array('class' => 'boundary', 'type' => 'administrative'); - $this->assertEquals('Administrative', ClassTypes\getLabel($aPlace)); - - $aPlace = array('class' => 'amenity', 'type' => 'prison'); - $this->assertEquals('Prison', ClassTypes\getLabel($aPlace)); - - $aPlace = array('class' => 'amenity', 'type' => 'foobar'); - $this->assertNull(ClassTypes\getLabel($aPlace)); - } - - public function testGetBoundaryLabel() - { - $this->assertEquals('City', ClassTypes\getBoundaryLabel(8, null)); - $this->assertEquals('Administrative', ClassTypes\getBoundaryLabel(18, null)); - $this->assertEquals('None', ClassTypes\getBoundaryLabel(18, null, 'None')); - $this->assertEquals('State', ClassTypes\getBoundaryLabel(4, 'de', 'None')); - $this->assertEquals('County', ClassTypes\getBoundaryLabel(4, 'se', 'None')); - $this->assertEquals('Municipality', ClassTypes\getBoundaryLabel(7, 'se', 'None')); - } - - public function testGetDefRadius() - { - $aResult = array('class' => '', 'type' => ''); - $this->assertEquals(0.00005, ClassTypes\getDefRadius($aResult)); - - $aResult = array('class' => 'place', 'type' => 'country'); - $this->assertEquals(7, ClassTypes\getDefRadius($aResult)); - } - - public function testGetIcon() - { - $aResult = array('class' => '', 'type' => ''); - $this->assertNull(ClassTypes\getIcon($aResult)); - - $aResult = array('class' => 'place', 'type' => 'airport'); - $this->assertEquals('transport_airport2', ClassTypes\getIcon($aResult)); - } - - public function testGetImportance() - { - $aResult = array('class' => '', 'type' => ''); - $this->assertNull(ClassTypes\getImportance($aResult)); - - $aResult = array('class' => 'place', 'type' => 'airport'); - $this->assertGreaterThan(0, ClassTypes\getImportance($aResult)); - } -} diff --git a/test/php/Nominatim/DBTest.php b/test/php/Nominatim/DBTest.php deleted file mode 100644 index 1c6f7637..00000000 --- a/test/php/Nominatim/DBTest.php +++ /dev/null @@ -1,228 +0,0 @@ -connection = $oConnection; - } -} - -// phpcs:ignore PSR1.Classes.ClassDeclaration.MultipleClasses -class DBTest extends \PHPUnit\Framework\TestCase -{ - public function testReusingConnection() - { - $oDB = new NominatimSubClassedDB(''); - $oDB->setConnection('anything'); - $this->assertTrue($oDB->connect()); - } - - public function testCheckConnection() - { - $oDB = new \Nominatim\DB(''); - $this->assertFalse($oDB->checkConnection()); - } - - public function testErrorHandling() - { - $this->expectException(DatabaseError::class); - $this->expectExceptionMessage('Failed to establish database connection'); - - $oDB = new \Nominatim\DB('pgsql:dbname=abc'); - $oDB->connect(); - } - - public function testErrorHandling2() - { - $this->expectException(DatabaseError::class); - $this->expectExceptionMessage('Database query failed'); - - $oPDOStub = $this->getMockBuilder(PDO::class) - ->setMethods(array('query', 'quote')) - ->getMock(); - - $oPDOStub->method('query') - ->will($this->returnCallback(function ($sVal) { - return "'$sVal'"; - })); - - $oPDOStub->method('query') - ->will($this->returnCallback(function () { - throw new \PDOException('ERROR: syntax error at or near "FROM"'); - })); - - $oDB = new NominatimSubClassedDB(''); - $oDB->setConnection($oPDOStub); - $oDB->getOne('SELECT name FROM'); - } - - public function testGetPostgresVersion() - { - $oDBStub = $this->getMockBuilder(\Nominatim\DB::class) - ->disableOriginalConstructor() - ->setMethods(array('getOne')) - ->getMock(); - - $oDBStub->method('getOne') - ->willReturn('100006'); - - $this->assertEquals(10, $oDBStub->getPostgresVersion()); - } - - public function testGetPostgisVersion() - { - $oDBStub = $this->getMockBuilder(\Nominatim\DB::class) - ->disableOriginalConstructor() - ->setMethods(array('getOne')) - ->getMock(); - - $oDBStub->method('getOne') - ->willReturn('2.4.4'); - - $this->assertEquals(2.4, $oDBStub->getPostgisVersion()); - } - - public function testParseDSN() - { - $this->assertEquals( - array(), - \Nominatim\DB::parseDSN('') - ); - $this->assertEquals( - array( - 'database' => 'db1', - 'hostspec' => 'machine1' - ), - \Nominatim\DB::parseDSN('pgsql:dbname=db1;host=machine1') - ); - $this->assertEquals( - array( - 'database' => 'db1', - 'hostspec' => 'machine1', - 'port' => '1234', - 'username' => 'john', - 'password' => 'secret' - ), - \Nominatim\DB::parseDSN('pgsql:dbname=db1;host=machine1;port=1234;user=john;password=secret') - ); - } - - public function testGenerateDSN() - { - $this->assertEquals( - 'pgsql:', - \Nominatim\DB::generateDSN(array()) - ); - $this->assertEquals( - 'pgsql:host=machine1;dbname=db1', - \Nominatim\DB::generateDSN(\Nominatim\DB::parseDSN('pgsql:host=machine1;dbname=db1')) - ); - } - - public function testAgainstDatabase() - { - $unit_test_dsn = getenv('UNIT_TEST_DSN') != false ? - getenv('UNIT_TEST_DSN') : - 'pgsql:dbname=nominatim_unit_tests'; - - ## Create the database. - { - $aDSNParsed = \Nominatim\DB::parseDSN($unit_test_dsn); - $sDbname = $aDSNParsed['database']; - $aDSNParsed['database'] = 'postgres'; - - $oDB = new \Nominatim\DB(\Nominatim\DB::generateDSN($aDSNParsed)); - $oDB->connect(); - $oDB->exec('DROP DATABASE IF EXISTS ' . $sDbname); - $oDB->exec('CREATE DATABASE ' . $sDbname); - } - - $oDB = new \Nominatim\DB($unit_test_dsn); - $oDB->connect(); - - $this->assertTrue( - $oDB->checkConnection($sDbname) - ); - - # Tables, Indices - { - $oDB->exec('CREATE TABLE table1 (id integer, city varchar, country varchar)'); - - $this->assertTrue($oDB->tableExists('table1')); - $this->assertFalse($oDB->tableExists('table99')); - $this->assertFalse($oDB->tableExists(null)); - } - - # select queries - { - $oDB->exec( - "INSERT INTO table1 VALUES (1, 'Berlin', 'Germany'), (2, 'Paris', 'France')" - ); - - $this->assertEquals( - array( - array('city' => 'Berlin'), - array('city' => 'Paris') - ), - $oDB->getAll('SELECT city FROM table1') - ); - $this->assertEquals( - array(), - $oDB->getAll('SELECT city FROM table1 WHERE id=999') - ); - - - $this->assertEquals( - array('id' => 1, 'city' => 'Berlin', 'country' => 'Germany'), - $oDB->getRow('SELECT * FROM table1 WHERE id=1') - ); - $this->assertEquals( - false, - $oDB->getRow('SELECT * FROM table1 WHERE id=999') - ); - - - $this->assertEquals( - array('Berlin', 'Paris'), - $oDB->getCol('SELECT city FROM table1') - ); - $this->assertEquals( - array(), - $oDB->getCol('SELECT city FROM table1 WHERE id=999') - ); - - $this->assertEquals( - 'Berlin', - $oDB->getOne('SELECT city FROM table1 WHERE id=1') - ); - $this->assertEquals( - null, - $oDB->getOne('SELECT city FROM table1 WHERE id=999') - ); - - $this->assertEquals( - array('Berlin' => 'Germany', 'Paris' => 'France'), - $oDB->getAssoc('SELECT city, country FROM table1') - ); - $this->assertEquals( - array(), - $oDB->getAssoc('SELECT city, country FROM table1 WHERE id=999') - ); - } - } -} diff --git a/test/php/Nominatim/DatabaseErrorTest.php b/test/php/Nominatim/DatabaseErrorTest.php deleted file mode 100644 index e24049ca..00000000 --- a/test/php/Nominatim/DatabaseErrorTest.php +++ /dev/null @@ -1,39 +0,0 @@ -getMockBuilder(PDOException::class) - ->setMethods(array('getMessage')) - ->getMock(); - - $oSqlStub->method('getMessage') - ->willReturn('Unknown table.'); - - $oErr = new DatabaseError('Sql error', 123, null, $oSqlStub); - $this->assertEquals('Sql error', $oErr->getMessage()); - $this->assertEquals(123, $oErr->getCode()); - $this->assertEquals('Unknown table.', $oErr->getSqlError()); - } - - public function testSqlObjectDump() - { - $oErr = new DatabaseError('Sql error', 123, null, array('one' => 'two')); - $this->assertStringContainsString('two', $oErr->getSqlDebugDump()); - } -} diff --git a/test/php/Nominatim/DebugTest.php b/test/php/Nominatim/DebugTest.php deleted file mode 100644 index 84e8f215..00000000 --- a/test/php/Nominatim/DebugTest.php +++ /dev/null @@ -1,209 +0,0 @@ -oWithDebuginfo = $this->getMockBuilder(\GeococdeMock::class) - ->setMethods(array('debugInfo')) - ->getMock(); - $this->oWithDebuginfo->method('debugInfo') - ->willReturn(array('key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3')); - - - $this->oWithToString = $this->getMockBuilder(\SomeMock::class) - ->setMethods(array('__toString')) - ->getMock(); - $this->oWithToString->method('__toString')->willReturn('me as string'); - } - - public function testPrintVar() - { - $this->expectOutputString(<<Var0: -
Var1:  True
-
Var2:  False
-
Var3:  0
-
Var4:  'String'
-
Var5:  0 => 'one'
-       1 => 'two'
-       2 => 'three'
-
Var6:  'key' => 'value'
-       'key2' => 'value2'
-
Var7:  me as string
-
Var8:  'value', 'value2'
- -EOT - ); - - Debug::printVar('Var0', null); - Debug::printVar('Var1', true); - Debug::printVar('Var2', false); - Debug::printVar('Var3', 0); - Debug::printVar('Var4', 'String'); - Debug::printVar('Var5', array('one', 'two', 'three')); - Debug::printVar('Var6', array('key' => 'value', 'key2' => 'value2')); - Debug::printVar('Var7', $this->oWithToString); - Debug::printVar('Var8', Debug::fmtArrayVals(array('key' => 'value', 'key2' => 'value2'))); - } - - - public function testDebugArray() - { - $this->expectOutputString(<<Arr0: 'null' -
Arr1:  'key1' => 'val1'
-       'key2' => 'val2'
-       'key3' => 'val3'
- -EOT - ); - - Debug::printDebugArray('Arr0', null); - Debug::printDebugArray('Arr1', $this->oWithDebuginfo); - } - - - public function testPrintDebugTable() - { - $this->expectOutputString(<<Table1: - -
-Table2: - -
-Table3: - - - - - - - - - - - - - -
01
'one'
'two'
'three'
'four'
-Table4: - - - - - - - - - - - -
key1key2key3
'val1'
'val2'
'val3'
- -EOT - ); - - Debug::printDebugTable('Table1', null); - - Debug::printDebugTable('Table2', array()); - - // Numeric headers - Debug::printDebugTable('Table3', array(array('one', 'two'), array('three', 'four'))); - - // Associate array - Debug::printDebugTable('Table4', array($this->oWithDebuginfo)); - } - - public function testPrintGroupTable() - { - $this->expectOutputString(<<Table1: - -
-Table2: - -
-Table3: - - - - - - - - - - - - - - - - - - - - - -
Groupkey1key2
group1
'val1'
'val2'
group1
'one'
'two'
group2
'val1'
'val2'
-Table4: - - - - - - - - - - - - - - - - - - - -
Groupkey1key2key3
group1
'val1'
'val2'
'val3'
group1
'val1'
'val2'
'val3'
- -EOT - ); - - Debug::printGroupTable('Table1', null); - Debug::printGroupTable('Table2', array()); - - // header are taken from first group item, thus no key3 gets printed - $aGroups = array( - 'group1' => array( - array('key1' => 'val1', 'key2' => 'val2'), - array('key1' => 'one', 'key2' => 'two', 'unknown' => 1), - ), - 'group2' => array( - array('key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3'), - ) - ); - Debug::printGroupTable('Table3', $aGroups); - - $aGroups = array( - 'group1' => array($this->oWithDebuginfo, $this->oWithDebuginfo), - ); - Debug::printGroupTable('Table4', $aGroups); - } -} diff --git a/test/php/Nominatim/LibTest.php b/test/php/Nominatim/LibTest.php deleted file mode 100644 index 5d711240..00000000 --- a/test/php/Nominatim/LibTest.php +++ /dev/null @@ -1,94 +0,0 @@ -assertSame("'St. John's'", addQuotes("St. John's")); - $this->assertSame("''", addQuotes('')); - } - - public function testParseLatLon() - { - // no coordinates expected - $this->assertFalse(parseLatLon('')); - $this->assertFalse(parseLatLon('abc')); - $this->assertFalse(parseLatLon('12 34')); - - // coordinates expected - $this->assertNotNull(parseLatLon('0.0 -0.0')); - - $aRes = parseLatLon(' abc 12.456 -78.90 def '); - $this->assertEquals($aRes[1], 12.456); - $this->assertEquals($aRes[2], -78.90); - $this->assertEquals($aRes[0], ' 12.456 -78.90 '); - - $aRes = parseLatLon(' [12.456,-78.90] '); - $this->assertEquals($aRes[1], 12.456); - $this->assertEquals($aRes[2], -78.90); - $this->assertEquals($aRes[0], ' [12.456,-78.90] '); - - $aRes = parseLatLon(' -12.456,-78.90 '); - $this->assertEquals($aRes[1], -12.456); - $this->assertEquals($aRes[2], -78.90); - $this->assertEquals($aRes[0], ' -12.456,-78.90 '); - - // http://en.wikipedia.org/wiki/Geographic_coordinate_conversion - // these all represent the same location - $aQueries = array( - '40 26.767 N 79 58.933 W', - '40° 26.767′ N 79° 58.933′ W', - "40° 26.767' N 79° 58.933' W", - "40° 26.767' - N 79° 58.933' W", - 'N 40 26.767, W 79 58.933', - 'N 40°26.767′, W 79°58.933′', - ' N 40°26.767′, W 79°58.933′', - "N 40°26.767', W 79°58.933'", - - '40 26 46 N 79 58 56 W', - '40° 26′ 46″ N 79° 58′ 56″ W', - '40° 26′ 46.00″ N 79° 58′ 56.00″ W', - '40°26′46″N 79°58′56″W', - 'N 40 26 46 W 79 58 56', - 'N 40° 26′ 46″, W 79° 58′ 56″', - 'N 40° 26\' 46", W 79° 58\' 56"', - 'N 40° 26\' 46", W 79° 58\' 56"', - - '40.446 -79.982', - '40.446,-79.982', - '40.446° N 79.982° W', - 'N 40.446° W 79.982°', - - '[40.446 -79.982]', - '[40.446, -79.982]', - ' 40.446 , -79.982 ', - ' 40.446 , -79.982 ', - ' 40.446 , -79.982 ', - ' 40.446 , -79.982 ', - ); - - - foreach ($aQueries as $sQuery) { - $aRes = parseLatLon($sQuery); - $this->assertEqualsWithDelta(40.446, $aRes[1], 0.01, 'degrees decimal ' . $sQuery); - $this->assertEqualsWithDelta(-79.982, $aRes[2], 0.01, 'degrees decimal ' . $sQuery); - $this->assertEquals($sQuery, $aRes[0]); - } - } -} diff --git a/test/php/Nominatim/ParameterParserTest.php b/test/php/Nominatim/ParameterParserTest.php deleted file mode 100644 index 82716d4d..00000000 --- a/test/php/Nominatim/ParameterParserTest.php +++ /dev/null @@ -1,248 +0,0 @@ - '1', - 'bool2' => '0', - 'bool3' => 'true', - 'bool4' => 'false', - 'bool5' => '' - )); - - $this->assertSame(false, $oParams->getBool('non-exists')); - $this->assertSame(true, $oParams->getBool('non-exists', true)); - $this->assertSame(true, $oParams->getBool('bool1')); - $this->assertSame(false, $oParams->getBool('bool2')); - $this->assertSame(true, $oParams->getBool('bool3')); - $this->assertSame(true, $oParams->getBool('bool4')); - $this->assertSame(false, $oParams->getBool('bool5')); - } - - - public function testGetInt() - { - $oParams = new ParameterParser(array( - 'int1' => '5', - 'int2' => '-1', - 'int3' => 0 - )); - - $this->assertSame(false, $oParams->getInt('non-exists')); - $this->assertSame(999, $oParams->getInt('non-exists', 999)); - $this->assertSame(5, $oParams->getInt('int1')); - - $this->assertSame(-1, $oParams->getInt('int2')); - $this->assertSame(0, $oParams->getInt('int3')); - } - - - public function testGetIntWithNonNumber() - { - $this->expectException(\Exception::class); - $this->expectExceptionMessage("Integer number expected for parameter 'int4'"); - - (new ParameterParser(array('int4' => 'a')))->getInt('int4'); - } - - - public function testGetIntWithEmpytString() - { - $this->expectException(\Exception::class); - $this->expectExceptionMessage("Integer number expected for parameter 'int5'"); - - (new ParameterParser(array('int5' => '')))->getInt('int5'); - } - - - public function testGetFloat() - { - - $oParams = new ParameterParser(array( - 'float1' => '1.0', - 'float2' => '-5', - 'float3' => 0 - )); - - $this->assertSame(false, $oParams->getFloat('non-exists')); - $this->assertSame(999, $oParams->getFloat('non-exists', 999)); - $this->assertSame(1.0, $oParams->getFloat('float1')); - $this->assertSame(-5.0, $oParams->getFloat('float2')); - $this->assertSame(0.0, $oParams->getFloat('float3')); - } - - public function testGetFloatWithEmptyString() - { - $this->expectException(\Exception::class); - $this->expectExceptionMessage("Floating-point number expected for parameter 'float4'"); - - (new ParameterParser(array('float4' => '')))->getFloat('float4'); - } - - public function testGetFloatWithTextString() - { - $this->expectException(\Exception::class); - $this->expectExceptionMessage("Floating-point number expected for parameter 'float5'"); - - (new ParameterParser(array('float5' => 'a')))->getFloat('float5'); - } - - - public function testGetFloatWithInvalidNumber() - { - $this->expectException(\Exception::class); - $this->expectExceptionMessage("Floating-point number expected for parameter 'float6'"); - - (new ParameterParser(array('float6' => '-55.')))->getFloat('float6'); - } - - - public function testGetString() - { - $oParams = new ParameterParser(array( - 'str1' => 'abc', - 'str2' => '', - 'str3' => '0' - )); - - $this->assertSame(false, $oParams->getString('non-exists')); - $this->assertSame('default', $oParams->getString('non-exists', 'default')); - $this->assertSame('abc', $oParams->getString('str1')); - $this->assertSame(false, $oParams->getStringList('str2')); - $this->assertSame(false, $oParams->getStringList('str3')); // sadly PHP magic treats 0 as false when returned - } - - - public function testGetSet() - { - $oParams = new ParameterParser(array( - 'val1' => 'foo', - 'val2' => '', - 'val3' => 0 - )); - - $this->assertSame(false, $oParams->getSet('non-exists', array('foo', 'bar'))); - $this->assertSame('default', $oParams->getSet('non-exists', array('foo', 'bar'), 'default')); - $this->assertSame('foo', $oParams->getSet('val1', array('foo', 'bar'))); - - $this->assertSame(false, $oParams->getSet('val2', array('foo', 'bar'))); - $this->assertSame(false, $oParams->getSet('val3', array('foo', 'bar'))); - } - - - public function testGetSetWithValueNotInSet() - { - $this->expectException(\Exception::class); - $this->expectExceptionMessage("Parameter 'val4' must be one of: foo, bar"); - - (new ParameterParser(array('val4' => 'faz')))->getSet('val4', array('foo', 'bar')); - } - - - public function testGetStringList() - { - $oParams = new ParameterParser(array( - 'list1' => ',a,b,c,,c,d', - 'list2' => 'a', - 'list3' => '', - 'list4' => '0' - )); - - $this->assertSame(false, $oParams->getStringList('non-exists')); - $this->assertSame(array('a', 'b'), $oParams->getStringList('non-exists', array('a', 'b'))); - $this->assertSame(array('a', 'b', 'c', 'c', 'd'), $oParams->getStringList('list1')); - $this->assertSame(array('a'), $oParams->getStringList('list2')); - $this->assertSame(false, $oParams->getStringList('list3')); - $this->assertSame(false, $oParams->getStringList('list4')); - } - - - public function testGetPreferredLanguages() - { - $oParams = new ParameterParser(array('accept-language' => '')); - $this->assertSame(array( - 'name:default' => 'name:default', - '_place_name:default' => '_place_name:default', - 'name' => 'name', - '_place_name' => '_place_name' - ), array_slice($oParams->getPreferredLanguages('default'), 0, 4)); - - $oParams = new ParameterParser(array('accept-language' => 'de,en')); - $this->assertSame(array( - 'name:de' => 'name:de', - '_place_name:de' => '_place_name:de', - 'name:en' => 'name:en', - '_place_name:en' => '_place_name:en', - 'name' => 'name', - '_place_name' => '_place_name' - ), array_slice($oParams->getPreferredLanguages('default'), 0, 6)); - - $oParams = new ParameterParser(array('accept-language' => 'fr-ca,fr;q=0.8,en-ca;q=0.5,en;q=0.3')); - $this->assertSame(array( - 'name:fr-ca' => 'name:fr-ca', - '_place_name:fr-ca' => '_place_name:fr-ca', - 'name:fr' => 'name:fr', - '_place_name:fr' => '_place_name:fr', - 'name:en-ca' => 'name:en-ca', - '_place_name:en-ca' => '_place_name:en-ca', - 'name:en' => 'name:en', - '_place_name:en' => '_place_name:en', - 'name' => 'name', - '_place_name' => '_place_name' - ), array_slice($oParams->getPreferredLanguages('default'), 0, 10)); - - $oParams = new ParameterParser(array('accept-language' => 'ja_rm,zh_pinyin')); - $this->assertSame(array( - 'name:ja_rm' => 'name:ja_rm', - '_place_name:ja_rm' => '_place_name:ja_rm', - 'name:zh_pinyin' => 'name:zh_pinyin', - '_place_name:zh_pinyin' => '_place_name:zh_pinyin', - 'name:ja' => 'name:ja', - '_place_name:ja' => '_place_name:ja', - 'name:zh' => 'name:zh', - '_place_name:zh' => '_place_name:zh', - 'name' => 'name', - '_place_name' => '_place_name' - ), array_slice($oParams->getPreferredLanguages('default'), 0, 10)); - } - - public function testHasSetAny() - { - $oParams = new ParameterParser(array( - 'one' => '', - 'two' => 0, - 'three' => '0', - 'four' => '1', - 'five' => 'anystring' - )); - $this->assertFalse($oParams->hasSetAny(array())); - $this->assertFalse($oParams->hasSetAny(array(''))); - $this->assertFalse($oParams->hasSetAny(array('unknown'))); - $this->assertFalse($oParams->hasSetAny(array('one', 'two', 'three'))); - $this->assertTrue($oParams->hasSetAny(array('one', 'four'))); - $this->assertTrue($oParams->hasSetAny(array('four'))); - $this->assertTrue($oParams->hasSetAny(array('five'))); - } -} diff --git a/test/php/Nominatim/ResultTest.php b/test/php/Nominatim/ResultTest.php deleted file mode 100644 index 8b95105e..00000000 --- a/test/php/Nominatim/ResultTest.php +++ /dev/null @@ -1,43 +0,0 @@ -iResultRank = $iResultRank; - - return $oResult; -} - - -class ResultTest extends \PHPUnit\Framework\TestCase -{ - public function testSplitResults() - { - $aSplitResults = Result::splitResults(array( - mkRankedResult(1, 2), - mkRankedResult(2, 0), - mkRankedResult(3, 0), - mkRankedResult(4, 2), - mkRankedResult(5, 1) - )); - - - $aHead = array_keys($aSplitResults['head']); - $aTail = array_keys($aSplitResults['tail']); - - $this->assertEquals($aHead, array(2, 3)); - $this->assertEquals($aTail, array(1, 4, 5)); - } -} diff --git a/test/php/Nominatim/SearchContextTest.php b/test/php/Nominatim/SearchContextTest.php deleted file mode 100644 index b5ef1a7a..00000000 --- a/test/php/Nominatim/SearchContextTest.php +++ /dev/null @@ -1,89 +0,0 @@ -oCtx = new SearchContext(); - } - - public function testHasNearPoint() - { - $this->assertFalse($this->oCtx->hasNearPoint()); - $this->oCtx->setNearPoint(0, 0); - $this->assertTrue($this->oCtx->hasNearPoint()); - } - - public function testNearRadius() - { - $this->oCtx->setNearPoint(1, 1); - $this->assertEquals(0.1, $this->oCtx->nearRadius()); - $this->oCtx->setNearPoint(1, 1, 0.338); - $this->assertEquals(0.338, $this->oCtx->nearRadius()); - } - - public function testWithinSQL() - { - $this->oCtx->setNearPoint(0.1, 23, 1); - - $this->assertEquals( - 'ST_DWithin(foo, ST_SetSRID(ST_Point(23,0.1),4326), 1.000000)', - $this->oCtx->withinSQL('foo') - ); - } - - public function testDistanceSQL() - { - $this->oCtx->setNearPoint(0.1, 23, 1); - - $this->assertEquals( - 'ST_Distance(ST_SetSRID(ST_Point(23,0.1),4326), foo)', - $this->oCtx->distanceSQL('foo') - ); - } - - public function testSetViewboxFromBox() - { - $viewbox = array(30, 20, 40, 50); - $this->oCtx->setViewboxFromBox($viewbox, true); - $this->assertEquals( - 'ST_SetSRID(ST_MakeBox2D(ST_Point(30.000000,20.000000),ST_Point(40.000000,50.000000)),4326)', - $this->oCtx->sqlViewboxSmall - ); - // height: 10 - // width: 30 - $this->assertEquals( - 'ST_SetSRID(ST_MakeBox2D(ST_Point(50.000000,80.000000),ST_Point(20.000000,-10.000000)),4326)', - $this->oCtx->sqlViewboxLarge - ); - - - $viewbox = array(-1.5, -2, 1.5, 2); - $this->oCtx->setViewboxFromBox($viewbox, true); - $this->assertEquals( - 'ST_SetSRID(ST_MakeBox2D(ST_Point(-1.500000,-2.000000),ST_Point(1.500000,2.000000)),4326)', - $this->oCtx->sqlViewboxSmall - ); - // height: 3 - // width: 4 - $this->assertEquals( - 'ST_SetSRID(ST_MakeBox2D(ST_Point(4.500000,6.000000),ST_Point(-4.500000,-6.000000)),4326)', - $this->oCtx->sqlViewboxLarge - ); - } -} diff --git a/test/php/Nominatim/ShellTest.php b/test/php/Nominatim/ShellTest.php deleted file mode 100644 index 82219498..00000000 --- a/test/php/Nominatim/ShellTest.php +++ /dev/null @@ -1,128 +0,0 @@ -expectException('ArgumentCountError'); - $this->expectExceptionMessage('Too few arguments to function'); - $oCmd = new \Nominatim\Shell(); - - - $oCmd = new \Nominatim\Shell('wc', '-l', 'file.txt'); - $this->assertSame( - "wc -l 'file.txt'", - $oCmd->escapedCmd() - ); - } - - public function testaddParams() - { - $oCmd = new \Nominatim\Shell('grep'); - $oCmd->addParams('-a', 'abc') - ->addParams(10); - - $this->assertSame( - 'grep -a abc 10', - $oCmd->escapedCmd(), - 'no escaping needed, chained' - ); - - $oCmd = new \Nominatim\Shell('grep'); - $oCmd->addParams(); - $oCmd->addParams(null); - $oCmd->addParams(''); - - $this->assertEmpty($oCmd->aParams); - $this->assertSame('grep', $oCmd->escapedCmd(), 'empty params'); - - $oCmd = new \Nominatim\Shell('echo', '-n', 0); - $this->assertSame( - 'echo -n 0', - $oCmd->escapedCmd(), - 'zero param' - ); - - $oCmd = new \Nominatim\Shell('/path with space/do.php'); - $oCmd->addParams('-a', ' b '); - $oCmd->addParams('--flag'); - $oCmd->addParams('two words'); - $oCmd->addParams('v=1'); - - $this->assertSame( - "'/path with space/do.php' -a ' b ' --flag 'two words' 'v=1'", - $oCmd->escapedCmd(), - 'escape whitespace' - ); - - $oCmd = new \Nominatim\Shell('grep'); - $oCmd->addParams(';', '|more&', '2>&1'); - - $this->assertSame( - "grep ';' '|more&' '2>&1'", - $oCmd->escapedCmd(), - 'escape shell characters' - ); - } - - public function testaddEnvPair() - { - $oCmd = new \Nominatim\Shell('date'); - - $oCmd->addEnvPair('one', 'two words') - ->addEnvPair('null', null) - ->addEnvPair(null, 'null') - ->addEnvPair('empty', '') - ->addEnvPair('', 'empty'); - - $this->assertEquals( - array('one' => 'two words', 'empty' => ''), - $oCmd->aEnv - ); - - $oCmd->addEnvPair('one', 'overwrite'); - $this->assertEquals( - array('one' => 'overwrite', 'empty' => ''), - $oCmd->aEnv - ); - } - - public function testClone() - { - $oCmd = new \Nominatim\Shell('wc', '-l', 'file.txt'); - $oCmd2 = clone $oCmd; - $oCmd->addParams('--flag'); - $oCmd2->addParams('--flag2'); - - $this->assertSame( - "wc -l 'file.txt' --flag", - $oCmd->escapedCmd() - ); - - $this->assertSame( - "wc -l 'file.txt' --flag2", - $oCmd2->escapedCmd() - ); - } - - public function testRun() - { - $oCmd = new \Nominatim\Shell('echo'); - - $this->assertSame(0, $oCmd->run()); - - // var_dump($sStdout); - } -} diff --git a/test/php/Nominatim/SimpleWordListTest.php b/test/php/Nominatim/SimpleWordListTest.php deleted file mode 100644 index 69cb5180..00000000 --- a/test/php/Nominatim/SimpleWordListTest.php +++ /dev/null @@ -1,136 +0,0 @@ -aTokens = array_flip($aTokens); - } - - public function containsAny($sTerm) - { - return isset($this->aTokens[$sTerm]); - } -} - -// phpcs:ignore PSR1.Classes.ClassDeclaration.MultipleClasses -class SimpleWordListTest extends \PHPUnit\Framework\TestCase -{ - - - private function serializeSets($aSets) - { - $aParts = array(); - foreach ($aSets as $aSet) { - $aParts[] = '(' . join('|', $aSet) . ')'; - } - return join(',', $aParts); - } - - - public function testEmptyPhrase() - { - $oList = new SimpleWordList(''); - $this->assertNull($oList->getWordSets(new TokensFullSet())); - } - - - public function testSingleWordPhrase() - { - $oList = new SimpleWordList('a'); - - $this->assertEquals( - '(a)', - $this->serializeSets($oList->getWordSets(new TokensFullSet())) - ); - } - - - public function testMultiWordPhrase() - { - $oList = new SimpleWordList('a b'); - $this->assertEquals( - '(a b),(a|b)', - $this->serializeSets($oList->getWordSets(new TokensFullSet())) - ); - - $oList = new SimpleWordList('a b c'); - $this->assertEquals( - '(a b c),(a b|c),(a|b c),(a|b|c)', - $this->serializeSets($oList->getWordSets(new TokensFullSet())) - ); - - $oList = new SimpleWordList('a b c d'); - $this->assertEquals( - '(a b c d),(a b c|d),(a b|c d),(a|b c d),(a b|c|d),(a|b c|d),(a|b|c d),(a|b|c|d)', - $this->serializeSets($oList->getWordSets(new TokensFullSet())) - ); - } - - public function testCmpByArraylen() - { - // Array elements are phrases, we want to sort so longest phrases are first - $aList1 = array('hackney', 'bridge', 'london', 'england'); - $aList2 = array('hackney', 'london', 'bridge'); - $aList3 = array('bridge', 'hackney', 'london', 'england'); - - $this->assertEquals(0, \Nominatim\SimpleWordList::cmpByArraylen($aList1, $aList1)); - - // list2 "wins". Less array elements - $this->assertEquals(1, \Nominatim\SimpleWordList::cmpByArraylen($aList1, $aList2)); - $this->assertEquals(-1, \Nominatim\SimpleWordList::cmpByArraylen($aList2, $aList3)); - - // list1 "wins". Same number of array elements but longer first element - $this->assertEquals(-1, \Nominatim\SimpleWordList::cmpByArraylen($aList1, $aList3)); - } - - public function testMaxWordSets() - { - $aWords = array_fill(0, 4, 'a'); - $oList = new SimpleWordList(join(' ', $aWords)); - $this->assertEquals(8, count($oList->getWordSets(new TokensFullSet()))); - - $aWords = array_fill(0, 18, 'a'); - $oList = new SimpleWordList(join(' ', $aWords)); - $this->assertEquals(100, count($oList->getWordSets(new TokensFullSet()))); - } - - - public function testPartialTokensShortTerm() - { - $oList = new SimpleWordList('a b c d'); - $this->assertEquals( - '(a|b c d),(a|b c|d)', - $this->serializeSets($oList->getWordSets(new TokensPartialSet(array('a', 'b', 'd', 'b c', 'b c d')))) - ); - } - - - public function testPartialTokensLongTerm() - { - $aWords = array_fill(0, 18, 'a'); - $oList = new SimpleWordList(join(' ', $aWords)); - $this->assertEquals(80, count($oList->getWordSets(new TokensPartialSet(array('a', 'a a a a a'))))); - } -} diff --git a/test/php/Nominatim/StatusTest.php b/test/php/Nominatim/StatusTest.php deleted file mode 100644 index 5f8bac64..00000000 --- a/test/php/Nominatim/StatusTest.php +++ /dev/null @@ -1,81 +0,0 @@ -expectException(\Exception::class); - $this->expectExceptionMessage('No database'); - $this->expectExceptionCode(700); - - $oDB = null; - $oStatus = new Status($oDB); - $this->assertEquals('No database', $oStatus->status()); - } - - public function testNoDatabaseConnectionFail() - { - $this->expectException(\Exception::class); - $this->expectExceptionMessage('Database connection failed'); - $this->expectExceptionCode(700); - - $oDbStub = $this->getMockBuilder(Nominatim\DB::class) - ->setMethods(array('connect')) - ->getMock(); - - $oDbStub->method('connect') - ->will($this->returnCallback(function () { - throw new \Nominatim\DatabaseError('psql connection problem', 500, null, 'unknown database'); - })); - - - $oStatus = new Status($oDbStub); - $this->assertEquals('No database', $oStatus->status()); - } - - public function testOK() - { - $oDbStub = $this->getMockBuilder(Nominatim\DB::class) - ->setMethods(array('connect', 'getOne')) - ->getMock(); - - $oDbStub->method('getOne') - ->will($this->returnCallback(function ($sql) { - if (preg_match("/make_standard_name\('(\w+)'\)/", $sql, $aMatch)) return $aMatch[1]; - if (preg_match('/SELECT word_id, word_token/', $sql)) return 1234; - })); - - $oStatus = new Status($oDbStub); - $this->assertNull($oStatus->status()); - } - - public function testDataDate() - { - $oDbStub = $this->getMockBuilder(Nominatim\DB::class) - ->setMethods(array('getOne')) - ->getMock(); - - $oDbStub->method('getOne') - ->willReturn(1519430221); - - $oStatus = new Status($oDbStub); - $this->assertEquals(1519430221, $oStatus->dataDate()); - } -} diff --git a/test/php/Nominatim/TokenListTest.php b/test/php/Nominatim/TokenListTest.php deleted file mode 100644 index 57e3c58f..00000000 --- a/test/php/Nominatim/TokenListTest.php +++ /dev/null @@ -1,60 +0,0 @@ -oNormalizer = $this->getMockBuilder(\MockNormalizer::class) - ->setMethods(array('transliterate')) - ->getMock(); - $this->oNormalizer->method('transliterate') - ->will($this->returnCallback(function ($text) { - return strtolower($text); - })); - } - - private function wordResult($aFields) - { - $aRow = array( - 'word_id' => null, - 'word_token' => null, - 'word' => null, - 'class' => null, - 'type' => null, - 'country_code' => null, - 'count' => 0 - ); - return array_merge($aRow, $aFields); - } - - public function testList() - { - $TL = new TokenList; - - $this->assertEquals(0, $TL->count()); - - $TL->addToken('word1', 'token1'); - $TL->addToken('word1', 'token2'); - - $this->assertEquals(1, $TL->count()); - - $this->assertTrue($TL->contains('word1')); - $this->assertEquals(array('token1', 'token2'), $TL->get('word1')); - - $this->assertFalse($TL->contains('unknownword')); - $this->assertEquals(array(), $TL->get('unknownword')); - } -} diff --git a/test/php/Nominatim/tokenizer.php b/test/php/Nominatim/tokenizer.php deleted file mode 100644 index 923e0a22..00000000 --- a/test/php/Nominatim/tokenizer.php +++ /dev/null @@ -1,25 +0,0 @@ -oDB =& $oDB; - } - - public function checkStatus() - { - } -} diff --git a/test/php/bootstrap.php b/test/php/bootstrap.php deleted file mode 100644 index 7d254511..00000000 --- a/test/php/bootstrap.php +++ /dev/null @@ -1,14 +0,0 @@ - - - - - ../../lib-php/ - - - - - - - ./Nominatim - - - -- 2.39.5