]> git.openstreetmap.org Git - nominatim.git/blobdiff - test/php/Nominatim/SearchContextTest.php
remove PHP frontend
[nominatim.git] / test / php / Nominatim / SearchContextTest.php
index a40d0716aa25a9f635b6b1919f4a2342a88b4ab3..b5ef1a7a420d798eae5fcddabe30cf74b6fca0fb 100644 (file)
@@ -1,16 +1,23 @@
 <?php
+/**
+ * SPDX-License-Identifier: GPL-2.0-only
+ *
+ * This file is part of Nominatim. (https://nominatim.org)
+ *
+ * Copyright (C) 2022 by the Nominatim developer community.
+ * For a full list of authors see the git log.
+ */
 
 namespace Nominatim;
 
-@define('CONST_BasePath', '../../');
+require_once(CONST_LibDir.'/SearchContext.php');
 
-require_once '../../lib/SearchContext.php';
-
-class SearchContextTest extends \PHPUnit_Framework_TestCase
+class SearchContextTest extends \PHPUnit\Framework\TestCase
 {
     private $oCtx;
 
-    protected function setUp()
+
+    protected function setUp(): void
     {
         $this->oCtx = new SearchContext();
     }
@@ -49,4 +56,34 @@ class SearchContextTest extends \PHPUnit_Framework_TestCase
             $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
+        );
+    }
 }