5 @define('CONST_BasePath', '../../');
7 require_once '../../lib/SearchContext.php';
9 class SearchContextTest extends \PHPUnit_Framework_TestCase
14 protected function setUp()
16 $this->oCtx = new SearchContext();
19 public function testHasNearPoint()
21 $this->assertFalse($this->oCtx->hasNearPoint());
22 $this->oCtx->setNearPoint(0, 0);
23 $this->assertTrue($this->oCtx->hasNearPoint());
26 public function testNearRadius()
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());
34 public function testWithinSQL()
36 $this->oCtx->setNearPoint(0.1, 23, 1);
39 'ST_DWithin(foo, ST_SetSRID(ST_Point(23,0.1),4326), 1.000000)',
40 $this->oCtx->withinSQL('foo')
44 public function testDistanceSQL()
46 $this->oCtx->setNearPoint(0.1, 23, 1);
49 'ST_Distance(ST_SetSRID(ST_Point(23,0.1),4326), foo)',
50 $this->oCtx->distanceSQL('foo')
54 public function testSetViewboxFromBox()
56 $viewbox = array(30, 20, 40, 50);
57 $this->oCtx->setViewboxFromBox($viewbox, true);
59 'ST_SetSRID(ST_MakeBox2D(ST_Point(30.000000,20.000000),ST_Point(40.000000,50.000000)),4326)',
60 $this->oCtx->sqlViewboxSmall
65 'ST_SetSRID(ST_MakeBox2D(ST_Point(50.000000,80.000000),ST_Point(20.000000,-10.000000)),4326)',
66 $this->oCtx->sqlViewboxLarge
70 $viewbox = array(-1.5, -2, 1.5, 2);
71 $this->oCtx->setViewboxFromBox($viewbox, true);
73 'ST_SetSRID(ST_MakeBox2D(ST_Point(-1.500000,-2.000000),ST_Point(1.500000,2.000000)),4326)',
74 $this->oCtx->sqlViewboxSmall
79 'ST_SetSRID(ST_MakeBox2D(ST_Point(4.500000,6.000000),ST_Point(-4.500000,-6.000000)),4326)',
80 $this->oCtx->sqlViewboxLarge