1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\Locator\Tests; |
4
|
|
|
|
5
|
|
|
use Dynamic\Locator\Location; |
6
|
|
|
use Dynamic\Locator\Locator; |
7
|
|
|
|
8
|
|
|
use Dynamic\Locator\LocatorController; |
9
|
|
|
use SilverStripe\Core\Config\Config; |
10
|
|
|
use SilverStripe\Core\Injector\Injector; |
11
|
|
|
use SilverStripe\Dev\SapphireTest; |
12
|
|
|
use SilverStripe\Forms\FieldList; |
13
|
|
|
use SilverStripe\ORM\ArrayList; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class LocatorTest |
17
|
|
|
*/ |
18
|
|
|
class LocatorTest extends SapphireTest |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
protected static $fixture_file = '../fixtures.yml'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* |
25
|
|
|
*/ |
26
|
|
|
public function testGetCMSFields() |
27
|
|
|
{ |
28
|
|
|
$locator = Injector::inst()->get(Locator::class); |
29
|
|
|
$fields = $locator->getCMSFields(); |
30
|
|
|
$this->assertInstanceOf(FieldList::class, $fields); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* |
35
|
|
|
*/ |
36
|
|
|
public function testGetRadii() |
37
|
|
|
{ |
38
|
|
|
$locator = Injector::inst()->get(Locator::class); |
39
|
|
|
|
40
|
|
|
// no config options |
41
|
|
|
Config::modify()->remove(Locator::class, 'radius_array'); |
42
|
|
|
$radii = $locator->getRadii(); |
43
|
|
|
$this->assertInstanceOf(ArrayList::class, $radii); |
44
|
|
|
|
45
|
|
|
// custom config options |
46
|
|
|
Config::modify()->set(Locator::class, 'radius_array', array( |
47
|
|
|
'0' => '100', |
48
|
|
|
'1' => '500', |
49
|
|
|
'2' => '1000', |
50
|
|
|
)); |
51
|
|
|
$radii = $locator->getRadii(); |
52
|
|
|
$this->assertInstanceOf(ArrayList::class, $radii); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* |
57
|
|
|
*/ |
58
|
|
|
public function testGetLimit() |
59
|
|
|
{ |
60
|
|
|
$locator = Injector::inst()->get(Locator::class); |
61
|
|
|
|
62
|
|
|
// no config options |
63
|
|
|
$limit = $locator->getLimit(); |
64
|
|
|
$this->assertEquals(-1, $limit); |
65
|
|
|
|
66
|
|
|
// custom config options |
67
|
|
|
Config::modify()->set(Locator::class, 'limit', 10); |
68
|
|
|
$limit = $locator->getLimit(); |
69
|
|
|
$this->assertEquals(10, $limit); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* |
74
|
|
|
*/ |
75
|
|
|
public function testGetShowRadius() |
76
|
|
|
{ |
77
|
|
|
$locator = Injector::inst()->get(Locator::class); |
78
|
|
|
|
79
|
|
|
// no config options |
80
|
|
|
$limit = $locator->getShowRadius(); |
81
|
|
|
$this->assertTrue($limit); |
82
|
|
|
|
83
|
|
|
// custom config options |
84
|
|
|
Config::modify()->set(Locator::class, 'show_radius', false); |
85
|
|
|
$limit = $locator->getShowRadius(); |
86
|
|
|
$this->assertFalse($limit); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* |
91
|
|
|
*/ |
92
|
|
|
public function testGetCategories() |
93
|
|
|
{ |
94
|
|
|
$locator = Injector::inst()->get(Locator::class); |
95
|
|
|
$catNum = count($locator->getCategories()); |
96
|
|
|
$this->assertEquals(0, $catNum); |
97
|
|
|
|
98
|
|
|
$locator = $this->objFromFixture(Locator::class, 'locator1'); |
99
|
|
|
$catNum = count($locator->getCategories()); |
100
|
|
|
$this->assertEquals(1, $catNum); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* |
105
|
|
|
*/ |
106
|
|
|
public function testGetInfoWindowTemplate() |
107
|
|
|
{ |
108
|
|
|
$locator = Injector::inst()->get(Locator::class); |
109
|
|
|
$template = $locator->getInfoWindowTemplate(); |
110
|
|
|
$this->assertTrue(is_string($template)); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* |
115
|
|
|
*/ |
116
|
|
|
public function testGetListTemplate() |
117
|
|
|
{ |
118
|
|
|
$locator = Injector::inst()->get(Locator::class); |
119
|
|
|
$template = $locator->getListTemplate(); |
120
|
|
|
$this->assertTrue(is_string($template)); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* |
125
|
|
|
*/ |
126
|
|
|
public function testLocations() |
127
|
|
|
{ |
128
|
|
|
$filter = Config::inst()->get(LocatorController::class, 'base_filter'); |
129
|
|
|
$filterAny = Config::inst()->get(LocatorController::class, 'base_filter_any'); |
130
|
|
|
$exclude = Config::inst()->get(LocatorController::class, 'base_exclude'); |
131
|
|
|
$locations = Locator::get_locations($filter, $filterAny, $exclude); |
132
|
|
|
$locations2 = Location::get()->filter($filter)->filterAny($filterAny)->exclude($exclude); |
133
|
|
|
$this->assertEquals($locations->count(), $locations2->count()); |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|