]> git.openstreetmap.org Git - nominatim.git/blob - test/php/Nominatim/SearchContextTest.php
use namespaces for PHPUnit classes
[nominatim.git] / test / php / Nominatim / SearchContextTest.php
1 <?php
2
3 namespace Nominatim;
4
5 @define('CONST_BasePath', '../../');
6
7 require_once '../../lib/SearchContext.php';
8
9 class SearchContextTest extends \PHPUnit\Framework\TestCase
10 {
11     private $oCtx;
12
13
14     protected function setUp()
15     {
16         $this->oCtx = new SearchContext();
17     }
18
19     public function testHasNearPoint()
20     {
21         $this->assertFalse($this->oCtx->hasNearPoint());
22         $this->oCtx->setNearPoint(0, 0);
23         $this->assertTrue($this->oCtx->hasNearPoint());
24     }
25
26     public function testNearRadius()
27     {
28         $this->oCtx->setNearPoint(1, 1);
29         $this->assertEquals(0.1, $this->oCtx->nearRadius());
30         $this->oCtx->setNearPoint(1, 1, 0.338);
31         $this->assertEquals(0.338, $this->oCtx->nearRadius());
32     }
33
34     public function testWithinSQL()
35     {
36         $this->oCtx->setNearPoint(0.1, 23, 1);
37
38         $this->assertEquals(
39             'ST_DWithin(foo, ST_SetSRID(ST_Point(23,0.1),4326), 1.000000)',
40             $this->oCtx->withinSQL('foo')
41         );
42     }
43
44     public function testDistanceSQL()
45     {
46         $this->oCtx->setNearPoint(0.1, 23, 1);
47
48         $this->assertEquals(
49             'ST_Distance(ST_SetSRID(ST_Point(23,0.1),4326), foo)',
50             $this->oCtx->distanceSQL('foo')
51         );
52     }
53
54     public function testSetViewboxFromBox()
55     {
56         $viewbox = array(30, 20, 40, 50);
57         $this->oCtx->setViewboxFromBox($viewbox, true);
58         $this->assertEquals(
59             'ST_SetSRID(ST_MakeBox2D(ST_Point(30.000000,20.000000),ST_Point(40.000000,50.000000)),4326)',
60             $this->oCtx->sqlViewboxSmall
61         );
62         // height: 10
63         // width: 30
64         $this->assertEquals(
65             'ST_SetSRID(ST_MakeBox2D(ST_Point(50.000000,80.000000),ST_Point(20.000000,-10.000000)),4326)',
66             $this->oCtx->sqlViewboxLarge
67         );
68
69
70         $viewbox = array(-1.5, -2, 1.5, 2);
71         $this->oCtx->setViewboxFromBox($viewbox, true);
72         $this->assertEquals(
73             'ST_SetSRID(ST_MakeBox2D(ST_Point(-1.500000,-2.000000),ST_Point(1.500000,2.000000)),4326)',
74             $this->oCtx->sqlViewboxSmall
75         );
76         // height: 3
77         // width: 4
78         $this->assertEquals(
79             'ST_SetSRID(ST_MakeBox2D(ST_Point(4.500000,6.000000),ST_Point(-4.500000,-6.000000)),4326)',
80             $this->oCtx->sqlViewboxLarge
81         );
82     }
83 }