3 * SPDX-License-Identifier: GPL-2.0-only
5 * This file is part of Nominatim. (https://nominatim.org)
7 * Copyright (C) 2022 by the Nominatim developer community.
8 * For a full list of authors see the git log.
13 require_once(CONST_LibDir.'/SearchContext.php');
15 class SearchContextTest extends \PHPUnit\Framework\TestCase
20 protected function setUp(): void
22 $this->oCtx = new SearchContext();
25 public function testHasNearPoint()
27 $this->assertFalse($this->oCtx->hasNearPoint());
28 $this->oCtx->setNearPoint(0, 0);
29 $this->assertTrue($this->oCtx->hasNearPoint());
32 public function testNearRadius()
34 $this->oCtx->setNearPoint(1, 1);
35 $this->assertEquals(0.1, $this->oCtx->nearRadius());
36 $this->oCtx->setNearPoint(1, 1, 0.338);
37 $this->assertEquals(0.338, $this->oCtx->nearRadius());
40 public function testWithinSQL()
42 $this->oCtx->setNearPoint(0.1, 23, 1);
45 'ST_DWithin(foo, ST_SetSRID(ST_Point(23,0.1),4326), 1.000000)',
46 $this->oCtx->withinSQL('foo')
50 public function testDistanceSQL()
52 $this->oCtx->setNearPoint(0.1, 23, 1);
55 'ST_Distance(ST_SetSRID(ST_Point(23,0.1),4326), foo)',
56 $this->oCtx->distanceSQL('foo')
60 public function testSetViewboxFromBox()
62 $viewbox = array(30, 20, 40, 50);
63 $this->oCtx->setViewboxFromBox($viewbox, true);
65 'ST_SetSRID(ST_MakeBox2D(ST_Point(30.000000,20.000000),ST_Point(40.000000,50.000000)),4326)',
66 $this->oCtx->sqlViewboxSmall
71 'ST_SetSRID(ST_MakeBox2D(ST_Point(50.000000,80.000000),ST_Point(20.000000,-10.000000)),4326)',
72 $this->oCtx->sqlViewboxLarge
76 $viewbox = array(-1.5, -2, 1.5, 2);
77 $this->oCtx->setViewboxFromBox($viewbox, true);
79 'ST_SetSRID(ST_MakeBox2D(ST_Point(-1.500000,-2.000000),ST_Point(1.500000,2.000000)),4326)',
80 $this->oCtx->sqlViewboxSmall
85 'ST_SetSRID(ST_MakeBox2D(ST_Point(4.500000,6.000000),ST_Point(-4.500000,-6.000000)),4326)',
86 $this->oCtx->sqlViewboxLarge