summaryrefslogtreecommitdiff
path: root/vendor/ruflin/elastica/test/lib/Elastica/Test/Filter/GeoBoundingBoxTest.php
blob: 8fdde965b9f3592941cb0e0a9d91ed4ee9b6a12b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
namespace Elastica\Test\Filter;

use Elastica\Filter\GeoBoundingBox;
use Elastica\Test\Base as BaseTest;

class GeoBoundingBoxTest extends BaseTest
{
    /**
     * @group unit
     */
    public function testAddCoordinates()
    {
        $key = 'pin.location';
        $coords = array('40.73, -74.1', '40.01, -71.12');
        $filter = new GeoBoundingBox($key, array('1,2', '3,4'));

        $filter->addCoordinates($key, $coords);
        $expectedArray = array('top_left' => $coords[0], 'bottom_right' => $coords[1]);
        $this->assertEquals($expectedArray, $filter->getParam($key));

        $returnValue = $filter->addCoordinates($key, $coords);
        $this->assertInstanceOf('Elastica\Filter\GeoBoundingBox', $returnValue);
    }

    /**
     * @group unit
     * @expectedException \Elastica\Exception\InvalidException
     */
    public function testAddCoordinatesInvalidException()
    {
        $filter = new GeoBoundingBox('foo', array());
    }

    /**
     * @group unit
     */
    public function testToArray()
    {
        $key = 'pin.location';
        $coords = array('40.73, -74.1', '40.01, -71.12');
        $filter = new GeoBoundingBox($key, $coords);

        $expectedArray = array(
            'geo_bounding_box' => array(
                $key => array(
                    'top_left' => $coords[0],
                    'bottom_right' => $coords[1],
                ),
            ),
        );

        $this->assertEquals($expectedArray, $filter->toArray());
    }
}