]> git.openstreetmap.org Git - nominatim.git/blob - test/php/Nominatim/SearchContextTest.php
adapt phpunit tests to new SearchContext class
[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     protected function setUp()
14     {
15         $this->oCtx = new SearchContext();
16     }
17
18     public function testHasNearPoint()
19     {
20         $this->assertFalse($this->oCtx->hasNearPoint());
21         $this->oCtx->setNearPoint(0, 0);
22         $this->assertTrue($this->oCtx->hasNearPoint());
23     }
24
25     public function testNearRadius()
26     {
27         $this->oCtx->setNearPoint(1, 1);
28         $this->assertEquals(0.1, $this->oCtx->nearRadius());
29         $this->oCtx->setNearPoint(1, 1, 0.338);
30         $this->assertEquals(0.338, $this->oCtx->nearRadius());
31     }
32
33     public function testWithinSQL()
34     {
35         $this->oCtx->setNearPoint(0.1, 23, 1);
36
37         $this->assertEquals(
38             'ST_DWithin(foo, ST_SetSRID(ST_Point(23,0.1),4326), 1.000000)',
39             $this->oCtx->withinSQL('foo')
40         );
41     }
42
43     public function testDistanceSQL()
44     {
45         $this->oCtx->setNearPoint(0.1, 23, 1);
46
47         $this->assertEquals(
48             'ST_Distance(ST_SetSRID(ST_Point(23,0.1),4326), foo)',
49             $this->oCtx->distanceSQL('foo')
50         );
51     }
52 }