From: Sarah Hoffmann Date: Thu, 26 Apr 2018 20:29:54 +0000 (+0200) Subject: Merge remote-tracking branch 'upstream/master' X-Git-Tag: deploy~336 X-Git-Url: https://git.openstreetmap.org/nominatim.git/commitdiff_plain/9454761cca4bb3a2b0fa997797054d67078a2fcc?hp=b66004c3c554c87886afa170f9065be249a3d9d4 Merge remote-tracking branch 'upstream/master' --- diff --git a/lib/cmd.php b/lib/cmd.php index 1edf5dfd..28d56f2e 100644 --- a/lib/cmd.php +++ b/lib/cmd.php @@ -134,7 +134,7 @@ function info($sMsg) echo date('Y-m-d H:i:s == ').$sMsg."\n"; } -$aWarnings = []; +$aWarnings = array(); function warn($sMsg) diff --git a/nominatim/CMakeLists.txt b/nominatim/CMakeLists.txt index 726ec4cc..b391a342 100644 --- a/nominatim/CMakeLists.txt +++ b/nominatim/CMakeLists.txt @@ -1,12 +1,12 @@ add_executable(nominatim export.c geometry.cpp import.c index.c input.c nominatim.c postgresql.c sprompt.c) -include(CheckIncludeFile) -CHECK_INCLUDE_FILE(byteswap.h HAVE_BYTESWAP_H) -CHECK_INCLUDE_FILE(sys/endian.h HAVE_SYS_ENDIAN_H) -if(HAVE_BYTESWAP_H) - target_compile_definitions(nominatim PRIVATE HAVE_BYTESWAP_H) -endif(HAVE_BYTESWAP_H) -if(HAVE_SYS_ENDIAN_H) - target_compile_definitions(nominatim PRIVATE HAVE_SYS_ENDIAN_H) -endif(HAVE_SYS_ENDIAN_H) + +CHECK_SYMBOL_EXISTS(bswap_32 "byteswap.h" HAVE_BYTESWAP) +CHECK_SYMBOL_EXISTS(bswap32 "sys/endian.h" HAVE_SYS_ENDIAN) + +target_compile_definitions(nominatim + PRIVATE HAVE_BYTESWAP=$ + PRIVATE HAVE_SYS_ENDIAN=$ +) + target_link_libraries(nominatim ${LIBXML2_LIBRARIES} ${ZLIB_LIBRARIES} ${BZIP2_LIBRARIES} ${PostgreSQL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) diff --git a/nominatim/postgresql.h b/nominatim/postgresql.h index 7050fca4..f30e7308 100644 --- a/nominatim/postgresql.h +++ b/nominatim/postgresql.h @@ -7,20 +7,32 @@ #define PG_OID_INT8 20 #define PG_OID_INT4 23 -#if defined(HAVE_BYTESWAP_H) +#if HAVE_BYTESWAP #include -#elif defined(HAVE_SYS_ENDIAN_H) +#define PG_BSWAP32(x) bswap_32(x) +#define PG_BSWAP64(x) bswap_64(x) +#elif HAVE_SYS_ENDIAN #include +#define PG_BSWAP32(x) bswap32(x) +#define PG_BSWAP64(x) bswap64(x) +#else +#error "No appropriate byteswap found for your system." #endif -#if __BYTE_ORDER == __BIG_ENDIAN -#define PGint16(x) (x) +#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) +#define PGint32(x) (x) +#define PGint64(x) (x) +#elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) +#define PGint32(x) PG_BSWAP32(x) +#define PGint64(x) PG_BSWAP64(x) +#elif defined(_BYTE_ORDER) && (_BYTE_ORDER == _BIG_ENDIAN) #define PGint32(x) (x) #define PGint64(x) (x) +#elif defined(_BYTE_ORDER) && (_BYTE_ORDER == _LITTLE_ENDIAN) +#define PGint32(x) PG_BSWAP32(x) +#define PGint64(x) PG_BSWAP64(x) #else -#define PGint16(x) __bswap_16 (x) -#define PGint32(x) __bswap_32 (x) -#define PGint64(x) __bswap_64 (x) +#error "Cannot determine byte order." #endif const char *build_conninfo(const char *db, const char *username, const char *password, const char *host, const char *port); diff --git a/phpcs.xml b/phpcs.xml index 6b4abc39..09360731 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -126,6 +126,8 @@ 0 + + diff --git a/sql/functions.sql b/sql/functions.sql index 396487b1..305365d1 100644 --- a/sql/functions.sql +++ b/sql/functions.sql @@ -1234,6 +1234,7 @@ DECLARE relation_members TEXT[]; relMember RECORD; linkedplacex RECORD; + addr_item RECORD; search_diameter FLOAT; search_prevdiameter FLOAT; search_maxrank INTEGER; @@ -1766,44 +1767,43 @@ BEGIN parent_place_id_rank = 0; - -- convert isin to array of tokenids + -- convert address store to array of tokenids --DEBUG: RAISE WARNING 'Starting address search'; isin_tokens := '{}'::int[]; IF NEW.address IS NOT NULL THEN - isin := avals(NEW.address); - IF array_upper(isin, 1) IS NOT NULL THEN - FOR i IN 1..array_upper(isin, 1) LOOP - -- TODO further split terms with comma and semicolon - address_street_word_id := get_name_id(make_standard_name(isin[i])); + FOR addr_item IN SELECT * FROM each(NEW.address) + LOOP + IF addr_item.key IN ('city', 'tiger:county', 'state', 'suburb', 'province', 'district', 'region', 'county', 'municipality', 'hamlet', 'village', 'subdistrict', 'town', 'neighbourhood', 'quarter', 'parish') THEN + address_street_word_id := get_name_id(make_standard_name(addr_item.value)); IF address_street_word_id IS NOT NULL AND NOT(ARRAY[address_street_word_id] <@ isin_tokens) THEN - nameaddress_vector := array_merge(nameaddress_vector, ARRAY[address_street_word_id]); isin_tokens := isin_tokens || address_street_word_id; END IF; - - -- merge word into address vector - address_street_word_id := get_word_id(make_standard_name(isin[i])); + address_street_word_id := get_word_id(make_standard_name(addr_item.value)); IF address_street_word_id IS NOT NULL THEN nameaddress_vector := array_merge(nameaddress_vector, ARRAY[address_street_word_id]); END IF; - END LOOP; - END IF; - END IF; + END IF; + IF addr_item.key = 'is_in' THEN + -- is_in items need splitting + isin := regexp_split_to_array(addr_item.value, E'[;,]'); + IF array_upper(isin, 1) IS NOT NULL THEN + FOR i IN 1..array_upper(isin, 1) LOOP + address_street_word_id := get_name_id(make_standard_name(isin[i])); + IF address_street_word_id IS NOT NULL AND NOT(ARRAY[address_street_word_id] <@ isin_tokens) THEN + isin_tokens := isin_tokens || address_street_word_id; + END IF; - -- %NOTIGERDATA% IF 0 THEN - -- for the USA we have an additional address table. Merge in zip codes from there too - IF NEW.rank_search = 26 AND NEW.country_code = 'us' THEN - FOR location IN SELECT distinct postcode from location_property_tiger where parent_place_id = NEW.place_id LOOP - address_street_word_id := get_name_id(make_standard_name(location.postcode)); - nameaddress_vector := array_merge(nameaddress_vector, ARRAY[address_street_word_id]); - isin_tokens := isin_tokens || address_street_word_id; - - -- also merge in the single word version - address_street_word_id := get_word_id(make_standard_name(location.postcode)); - nameaddress_vector := array_merge(nameaddress_vector, ARRAY[address_street_word_id]); + -- merge word into address vector + address_street_word_id := get_word_id(make_standard_name(isin[i])); + IF address_street_word_id IS NOT NULL THEN + nameaddress_vector := array_merge(nameaddress_vector, ARRAY[address_street_word_id]); + END IF; + END LOOP; + END IF; + END IF; END LOOP; END IF; - --DEBUG: RAISE WARNING 'Tiger postcodes collected'; - -- %NOTIGERDATA% END IF; + nameaddress_vector := array_merge(nameaddress_vector, isin_tokens); -- RAISE WARNING 'ISIN: %', isin_tokens; @@ -1884,40 +1884,6 @@ BEGIN END LOOP; --DEBUG: RAISE WARNING 'address computed'; - -- try using the isin value to find parent places - IF array_upper(isin_tokens, 1) IS NOT NULL THEN - FOR i IN 1..array_upper(isin_tokens, 1) LOOP ---RAISE WARNING ' getNearestNamedFeature: % % % %',NEW.partition, place_centroid, search_maxrank, isin_tokens[i]; - IF NOT ARRAY[isin_tokens[i]] <@ nameaddress_vector THEN - - FOR location IN SELECT * from getNearestNamedFeature(NEW.partition, place_centroid, search_maxrank, isin_tokens[i]) LOOP - ---RAISE WARNING ' ISIN: %',location; - - IF location.rank_search > 4 THEN - nameaddress_vector := array_merge(nameaddress_vector, location.keywords::integer[]); - INSERT INTO place_addressline (place_id, address_place_id, fromarea, isaddress, distance, cached_rank_address) - VALUES (NEW.place_id, location.place_id, false, NOT address_havelevel[location.rank_address], location.distance, location.rank_address); - IF NEW.postcode is null AND location.postcode is not null - AND NOT address_havelevel[location.rank_address] THEN - NEW.postcode := location.postcode; - END IF; - - address_havelevel[location.rank_address] := true; - - IF location.rank_address > parent_place_id_rank THEN - NEW.parent_place_id = location.place_id; - parent_place_id_rank = location.rank_address; - END IF; - END IF; - END LOOP; - - END IF; - - END LOOP; - END IF; - --DEBUG: RAISE WARNING 'isin tokens processed'; - -- for long ways we should add search terms for the entire length IF st_length(NEW.geometry) > 0.05 THEN diff --git a/sql/indices.src.sql b/sql/indices.src.sql index cf5c4bc1..61af8900 100644 --- a/sql/indices.src.sql +++ b/sql/indices.src.sql @@ -19,8 +19,6 @@ CREATE INDEX idx_location_area_country_place_id ON location_area_country USING B CREATE INDEX idx_osmline_parent_place_id ON location_property_osmline USING BTREE (parent_place_id) {ts:search-index}; -CREATE INDEX idx_search_name_country_centroid ON search_name_country USING GIST (centroid) {ts:address-index}; - DROP INDEX IF EXISTS place_id_idx; CREATE UNIQUE INDEX idx_place_osm_unique on place using btree(osm_id,osm_type,class,type) {ts:address-index}; diff --git a/sql/partition-functions.src.sql b/sql/partition-functions.src.sql index 32b5f0a1..cc11cf96 100644 --- a/sql/partition-functions.src.sql +++ b/sql/partition-functions.src.sql @@ -84,38 +84,6 @@ END $$ LANGUAGE plpgsql; -create or replace function getNearestNamedFeature(in_partition INTEGER, point GEOMETRY, maxrank INTEGER, isin_token INTEGER) RETURNS setof nearfeature AS $$ -DECLARE - r nearfeature%rowtype; -BEGIN - --- start - IF in_partition = -partition- THEN - FOR r IN - SELECT place_id, name_vector, address_rank, search_rank, - ST_Distance(centroid, point) as distance, null as isguess - FROM search_name_-partition- - WHERE name_vector @> ARRAY[isin_token] - AND search_rank < maxrank - UNION ALL - SELECT place_id, name_vector, address_rank, search_rank, - ST_Distance(centroid, point) as distance, null as isguess - FROM search_name_country - WHERE name_vector @> ARRAY[isin_token] - AND search_rank < maxrank - ORDER BY distance ASC limit 1 - LOOP - RETURN NEXT r; - END LOOP; - RETURN; - END IF; --- end - - RAISE EXCEPTION 'Unknown partition %', in_partition; -END -$$ -LANGUAGE plpgsql; - create or replace function getNearestNamedRoadFeature(in_partition INTEGER, point GEOMETRY, isin_token INTEGER[]) RETURNS setof nearfeature AS $$ DECLARE @@ -185,15 +153,6 @@ BEGIN INSERT INTO search_name (place_id, search_rank, address_rank, importance, country_code, name_vector, nameaddress_vector, centroid) values (in_place_id, in_rank_search, in_rank_address, in_importance, in_country_code, in_name_vector, in_nameaddress_vector, in_centroid); - IF in_rank_search <= 4 THEN - DELETE FROM search_name_country WHERE place_id = in_place_id; - IF in_rank_address > 0 THEN - INSERT INTO search_name_country (place_id, search_rank, address_rank, name_vector, centroid) - values (in_place_id, in_rank_search, in_rank_address, in_name_vector, in_geometry); - END IF; - RETURN TRUE; - END IF; - -- start IF in_partition = -partition- THEN DELETE FROM search_name_-partition- values WHERE place_id = in_place_id; @@ -216,7 +175,6 @@ DECLARE BEGIN DELETE from search_name WHERE place_id = in_place_id; - DELETE from search_name_country WHERE place_id = in_place_id; -- start IF in_partition = -partition- THEN diff --git a/sql/partition-tables.src.sql b/sql/partition-tables.src.sql index d8f02e10..61ed5281 100644 --- a/sql/partition-tables.src.sql +++ b/sql/partition-tables.src.sql @@ -38,10 +38,6 @@ CREATE TABLE search_name_blank ( CREATE TABLE location_area_country () INHERITS (location_area_large) {ts:address-data}; CREATE INDEX idx_location_area_country_geometry ON location_area_country USING GIST (geometry) {ts:address-index}; -CREATE TABLE search_name_country () INHERITS (search_name_blank) {ts:address-data}; -CREATE INDEX idx_search_name_country_place_id ON search_name_country USING BTREE (place_id) {ts:address-index}; -CREATE INDEX idx_search_name_country_name_vector ON search_name_country USING GIN (name_vector) WITH (fastupdate = off) {ts:address-index}; - -- start CREATE TABLE location_area_large_-partition- () INHERITS (location_area_large) {ts:address-data}; CREATE INDEX idx_location_area_large_-partition-_place_id ON location_area_large_-partition- USING BTREE (place_id) {ts:address-index}; diff --git a/test/bdd/db/import/search_name.feature b/test/bdd/db/import/search_name.feature index 86bdea9b..cf3ce4dd 100644 --- a/test/bdd/db/import/search_name.feature +++ b/test/bdd/db/import/search_name.feature @@ -23,3 +23,57 @@ Feature: Creation of search terms Then search_name contains | object | name_vector | nameaddress_vector | | N1 | foo | the road | + + Scenario: Some addr: tags are added to address when the name exists + Given the scene roads-with-pois + And the places + | osm | class | type | name | geometry | + | N1 | place | state | new york | 80 80 | + | N1 | place | city | bonn | 81 81 | + | N1 | place | suburb | smalltown| 80 81 | + And the named places + | osm | class | type | addr+city | addr+state | addr+suburb | geometry | + | W1 | highway | service | bonn | New York | Smalltown | :w-north | + When importing + Then search_name contains + | object | nameaddress_vector | + | W1 | bonn, new york, smalltown | + + Scenario: A known addr:* tag is not added if the name is unknown + Given the scene roads-with-pois + And the places + | osm | class | type | name | addr+city | geometry | + | W1 | highway | residential | Road | Nandu | :w-north | + When importing + Then search_name contains not + | object | nameaddress_vector | + | W1 | nandu | + + Scenario: addr:postcode is not added to the address terms + Given the scene roads-with-pois + And the places + | osm | class | type | name+ref | geometry | + | N1 | place | state | 12345 | 80 80 | + And the named places + | osm | class | type | addr+postcode | geometry | + | W1 | highway | residential | 12345 | :w-north | + When importing + Then search_name contains not + | object | nameaddress_vector | + | W1 | 12345 | + + Scenario: is_in is split and added to the address search terms + Given the scene roads-with-pois + And the places + | osm | class | type | name | geometry | + | N1 | place | state | new york | 80 80 | + | N1 | place | city | bonn | 81 81 | + | N1 | place | suburb | smalltown| 80 81 | + And the named places + | osm | class | type | addr+is_in | geometry | + | W1 | highway | service | bonn, New York, Smalltown | :w-north | + When importing + Then search_name contains + | object | nameaddress_vector | + | W1 | bonn, new york, smalltown | + diff --git a/test/bdd/steps/db_ops.py b/test/bdd/steps/db_ops.py index 87babdad..80f92222 100644 --- a/test/bdd/steps/db_ops.py +++ b/test/bdd/steps/db_ops.py @@ -427,8 +427,8 @@ def check_placex_contents(context, exact): context.db.commit() -@then("search_name contains") -def check_search_name_contents(context): +@then("search_name contains(?P not)?") +def check_search_name_contents(context, exclude): cur = context.db.cursor(cursor_factory=psycopg2.extras.DictCursor) for row in context.table: @@ -446,11 +446,16 @@ def check_search_name_contents(context): FROM word, (SELECT unnest(%s) as term) t WHERE word_token = make_standard_name(t.term)""", (terms,)) - ok_(subcur.rowcount >= len(terms), - "No word entry found for " + row[h]) + if not exclude: + ok_(subcur.rowcount >= len(terms), + "No word entry found for " + row[h]) for wid in subcur: - assert_in(wid[0], res[h], - "Missing term for %s/%s: %s" % (pid, h, wid[1])) + if exclude: + assert_not_in(wid[0], res[h], + "Found term for %s/%s: %s" % (pid, h, wid[1])) + else: + assert_in(wid[0], res[h], + "Missing term for %s/%s: %s" % (pid, h, wid[1])) else: assert_db_column(res, h, row[h], context) diff --git a/test/php/Nominatim/LibTest.php b/test/php/Nominatim/LibTest.php index ee6f94f2..533188ad 100644 --- a/test/php/Nominatim/LibTest.php +++ b/test/php/Nominatim/LibTest.php @@ -70,9 +70,9 @@ class LibTest extends \PHPUnit_Framework_TestCase ); $this->assertEquals( array( - ['', 0, 2], - ['', 0.12558103905863, 1.9960534568565], - ['', 0.25066646712861, 1.984229402629] + array('', 0, 2), + array('', 0.12558103905863, 1.9960534568565), + array('', 0.25066646712861, 1.984229402629) ), array_splice($aPoints, 0, 3) ); @@ -96,9 +96,9 @@ class LibTest extends \PHPUnit_Framework_TestCase ); $this->assertEquals( array( - [10, 21], - [10.062790519529, 20.998026728428], - [10.125333233564, 20.992114701314] + array(10, 21), + array(10.062790519529, 20.998026728428), + array(10.125333233564, 20.992114701314) ), array_splice($aPoints, 0, 3) ); @@ -106,11 +106,11 @@ class LibTest extends \PHPUnit_Framework_TestCase // POLYGON $this->assertEquals( array( - ['30', '10'], - ['40', '40'], - ['20', '40'], - ['10', '20'], - ['30', '10'] + array('30', '10'), + array('40', '40'), + array('20', '40'), + array('10', '20'), + array('30', '10') ), geometryText2Points('POLYGON((30 10, 40 40, 20 40, 10 20, 30 10))', $fRadius) ); @@ -118,10 +118,10 @@ class LibTest extends \PHPUnit_Framework_TestCase // MULTIPOLYGON $this->assertEquals( array( - ['30', '20'], // first polygon only - ['45', '40'], - ['10', '40'], - ['30', '20'], + array('30', '20'), // first polygon only + array('45', '40'), + array('10', '40'), + array('30', '20'), ), geometryText2Points('MULTIPOLYGON(((30 20, 45 40, 10 40, 30 20)),((15 5, 40 10, 10 20, 5 10, 15 5)))', $fRadius) ); @@ -190,15 +190,15 @@ class LibTest extends \PHPUnit_Framework_TestCase private function closestHouseNumberEvenOddOther($startnumber, $endnumber, $fraction, $aExpected) { - foreach (['even', 'odd', 'other'] as $itype) { + foreach (array('even', 'odd', 'other') as $itype) { $this->assertEquals( $aExpected[$itype], - closestHouseNumber([ + closestHouseNumber(array( 'startnumber' => $startnumber, 'endnumber' => $endnumber, 'fraction' => $fraction, 'interpolationtype' => $itype - ]), + )), "$startnumber => $endnumber, $fraction, $itype" ); } @@ -206,14 +206,14 @@ class LibTest extends \PHPUnit_Framework_TestCase public function testClosestHouseNumber() { - $this->closestHouseNumberEvenOddOther(50, 100, 0.5, ['even' => 76, 'odd' => 75, 'other' => 75]); + $this->closestHouseNumberEvenOddOther(50, 100, 0.5, array('even' => 76, 'odd' => 75, 'other' => 75)); // upper bound - $this->closestHouseNumberEvenOddOther(50, 100, 1.5, ['even' => 100, 'odd' => 100, 'other' => 100]); + $this->closestHouseNumberEvenOddOther(50, 100, 1.5, array('even' => 100, 'odd' => 100, 'other' => 100)); // lower bound - $this->closestHouseNumberEvenOddOther(50, 100, -0.5, ['even' => 50, 'odd' => 50, 'other' => 50]); + $this->closestHouseNumberEvenOddOther(50, 100, -0.5, array('even' => 50, 'odd' => 50, 'other' => 50)); // fraction 0 - $this->closestHouseNumberEvenOddOther(50, 100, 0, ['even' => 50, 'odd' => 51, 'other' => 50]); + $this->closestHouseNumberEvenOddOther(50, 100, 0, array('even' => 50, 'odd' => 51, 'other' => 50)); // start == end - $this->closestHouseNumberEvenOddOther(50, 50, 0.5, ['even' => 50, 'odd' => 50, 'other' => 50]); + $this->closestHouseNumberEvenOddOther(50, 50, 0.5, array('even' => 50, 'odd' => 50, 'other' => 50)); } } diff --git a/test/php/Nominatim/ParameterParserTest.php b/test/php/Nominatim/ParameterParserTest.php index 4265cffb..0cbc60c5 100644 --- a/test/php/Nominatim/ParameterParserTest.php +++ b/test/php/Nominatim/ParameterParserTest.php @@ -18,13 +18,13 @@ class ParameterParserTest extends \PHPUnit_Framework_TestCase public function testGetBool() { - $oParams = new ParameterParser([ + $oParams = new ParameterParser(array( 'bool1' => '1', 'bool2' => '0', 'bool3' => 'true', 'bool4' => 'false', 'bool5' => '' - ]); + )); $this->assertSame(false, $oParams->getBool('non-exists')); $this->assertSame(true, $oParams->getBool('non-exists', true)); @@ -38,11 +38,11 @@ class ParameterParserTest extends \PHPUnit_Framework_TestCase public function testGetInt() { - $oParams = new ParameterParser([ + $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)); @@ -56,25 +56,25 @@ class ParameterParserTest extends \PHPUnit_Framework_TestCase public function testGetIntWithNonNumber() { $this->setExpectedException(Exception::class, "Integer number expected for parameter 'int4'"); - (new ParameterParser(['int4' => 'a']))->getInt('int4'); + (new ParameterParser(array('int4' => 'a')))->getInt('int4'); } public function testGetIntWithEmpytString() { $this->setExpectedException(Exception::class, "Integer number expected for parameter 'int5'"); - (new ParameterParser(['int5' => '']))->getInt('int5'); + (new ParameterParser(array('int5' => '')))->getInt('int5'); } public function testGetFloat() { - $oParams = new ParameterParser([ + $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)); @@ -86,30 +86,30 @@ class ParameterParserTest extends \PHPUnit_Framework_TestCase public function testGetFloatWithEmptyString() { $this->setExpectedException(Exception::class, "Floating-point number expected for parameter 'float4'"); - (new ParameterParser(['float4' => '']))->getFloat('float4'); + (new ParameterParser(array('float4' => '')))->getFloat('float4'); } public function testGetFloatWithTextString() { $this->setExpectedException(Exception::class, "Floating-point number expected for parameter 'float5'"); - (new ParameterParser(['float5' => 'a']))->getFloat('float5'); + (new ParameterParser(array('float5' => 'a')))->getFloat('float5'); } public function testGetFloatWithInvalidNumber() { $this->setExpectedException(Exception::class, "Floating-point number expected for parameter 'float6'"); - (new ParameterParser(['float6' => '-55.']))->getFloat('float6'); + (new ParameterParser(array('float6' => '-55.')))->getFloat('float6'); } public function testGetString() { - $oParams = new ParameterParser([ + $oParams = new ParameterParser(array( 'str1' => 'abc', 'str2' => '', 'str3' => '0' - ]); + )); $this->assertSame(false, $oParams->getString('non-exists')); $this->assertSame('default', $oParams->getString('non-exists', 'default')); @@ -121,41 +121,41 @@ class ParameterParserTest extends \PHPUnit_Framework_TestCase public function testGetSet() { - $oParams = new ParameterParser([ + $oParams = new ParameterParser(array( 'val1' => 'foo', 'val2' => '', 'val3' => 0 - ]); + )); - $this->assertSame(false, $oParams->getSet('non-exists', ['foo', 'bar'])); - $this->assertSame('default', $oParams->getSet('non-exists', ['foo', 'bar'], 'default')); - $this->assertSame('foo', $oParams->getSet('val1', ['foo', 'bar'])); + $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', ['foo', 'bar'])); - $this->assertSame(0, $oParams->getSet('val3', ['foo', 'bar'])); + $this->assertSame(false, $oParams->getSet('val2', array('foo', 'bar'))); + $this->assertSame(0, $oParams->getSet('val3', array('foo', 'bar'))); } public function testGetSetWithValueNotInSet() { $this->setExpectedException(Exception::class, "Parameter 'val4' must be one of: foo, bar"); - (new ParameterParser(['val4' => 'faz']))->getSet('val4', ['foo', 'bar']); + (new ParameterParser(array('val4' => 'faz')))->getSet('val4', array('foo', 'bar')); } public function testGetStringList() { - $oParams = new ParameterParser([ + $oParams = new ParameterParser(array( 'list1' => ',a,b,c,,c,d', 'list2' => 'a', 'list3' => '', 'list4' => '0' - ]); + )); $this->assertSame(false, $oParams->getStringList('non-exists')); - $this->assertSame(['a', 'b'], $oParams->getStringList('non-exists', ['a', 'b'])); - $this->assertSame(['a', 'b', 'c', 'c', 'd'], $oParams->getStringList('list1')); - $this->assertSame(['a'], $oParams->getStringList('list2')); + $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')); } @@ -163,8 +163,8 @@ class ParameterParserTest extends \PHPUnit_Framework_TestCase public function testGetPreferredLanguages() { - $oParams = new ParameterParser(['accept-language' => '']); - $this->assertSame([ + $oParams = new ParameterParser(array('accept-language' => '')); + $this->assertSame(array( 'short_name:default' => 'short_name:default', 'name:default' => 'name:default', 'short_name' => 'short_name', @@ -174,10 +174,10 @@ class ParameterParserTest extends \PHPUnit_Framework_TestCase 'official_name' => 'official_name', 'ref' => 'ref', 'type' => 'type' - ], $oParams->getPreferredLanguages('default')); + ), $oParams->getPreferredLanguages('default')); - $oParams = new ParameterParser(['accept-language' => 'de,en']); - $this->assertSame([ + $oParams = new ParameterParser(array('accept-language' => 'de,en')); + $this->assertSame(array( 'short_name:de' => 'short_name:de', 'name:de' => 'name:de', 'short_name:en' => 'short_name:en', @@ -190,10 +190,10 @@ class ParameterParserTest extends \PHPUnit_Framework_TestCase 'official_name' => 'official_name', 'ref' => 'ref', 'type' => 'type' - ], $oParams->getPreferredLanguages('default')); + ), $oParams->getPreferredLanguages('default')); - $oParams = new ParameterParser(['accept-language' => 'fr-ca,fr;q=0.8,en-ca;q=0.5,en;q=0.3']); - $this->assertSame([ + $oParams = new ParameterParser(array('accept-language' => 'fr-ca,fr;q=0.8,en-ca;q=0.5,en;q=0.3')); + $this->assertSame(array( 'short_name:fr-ca' => 'short_name:fr-ca', 'name:fr-ca' => 'name:fr-ca', 'short_name:fr' => 'short_name:fr', @@ -212,6 +212,6 @@ class ParameterParserTest extends \PHPUnit_Framework_TestCase 'official_name' => 'official_name', 'ref' => 'ref', 'type' => 'type', - ], $oParams->getPreferredLanguages('default')); + ), $oParams->getPreferredLanguages('default')); } } diff --git a/vagrant/install-on-travis-ci.sh b/vagrant/install-on-travis-ci.sh index 05681ae3..ef9f03c4 100755 --- a/vagrant/install-on-travis-ci.sh +++ b/vagrant/install-on-travis-ci.sh @@ -20,7 +20,7 @@ sudo apt-get install -y -qq libboost-dev libboost-system-dev \ sudo apt-get install -y -qq python3-dev python3-pip python3-psycopg2 php5-cgi -pip3 install --quiet behave nose pytidylib psycopg2 +pip3 install --quiet behave nose pytidylib psycopg2-binary # Travis uses phpenv to support multiple PHP versions. We need to make sure # these packages get installed to the phpenv-set PHP (below /home/travis/.phpenv/), diff --git a/website/lookup.php b/website/lookup.php index b9cc88f7..71c93715 100755 --- a/website/lookup.php +++ b/website/lookup.php @@ -63,7 +63,7 @@ $sQuery = join(',', $aCleanedQueryParts); // we initialize these to avoid warnings in our logfile $sViewBox = ''; $bShowPolygons = ''; -$aExcludePlaceIDs = []; +$aExcludePlaceIDs = array(); $sMoreURL = ''; include(CONST_BasePath.'/lib/template/search-'.$sOutputFormat.'.php'); diff --git a/website/reverse.php b/website/reverse.php index 822081ef..0251c8c8 100755 --- a/website/reverse.php +++ b/website/reverse.php @@ -62,7 +62,7 @@ if (isset($aPlace)) { $aPlace = array_merge($aPlace, $aOutlineResult); } } else { - $aPlace = []; + $aPlace = array(); } logEnd($oDB, $hLog, sizeof($aPlace)?1:0);