1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\Locator\Tests; |
4
|
|
|
|
5
|
|
|
use Dynamic\Locator\Location; |
6
|
|
|
use Dynamic\Locator\LocationCategory; |
7
|
|
|
use Dynamic\Locator\Locator; |
8
|
|
|
use Dynamic\Locator\LocatorController; |
9
|
|
|
use Dynamic\SilverStripeGeocoder\GoogleGeocoder; |
10
|
|
|
use SilverStripe\Core\Config\Config; |
11
|
|
|
use SilverStripe\Core\Injector\Injector; |
12
|
|
|
use SilverStripe\Dev\FunctionalTest; |
13
|
|
|
use SilverStripe\Forms\FieldList; |
14
|
|
|
use SilverStripe\Forms\Form; |
15
|
|
|
use SilverStripe\ORM\ArrayList; |
16
|
|
|
use SilverStripe\ORM\FieldType\DBHTMLText; |
17
|
|
|
use SilverStripe\View\ViewableData; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class LocatorTest |
21
|
|
|
*/ |
22
|
|
|
class LocatorTest extends FunctionalTest |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected static $fixture_file = '../fixtures.yml'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* |
31
|
|
|
*/ |
32
|
|
|
public function testGetCMSFields() |
33
|
|
|
{ |
34
|
|
|
/** @var Locator $locator */ |
35
|
|
|
$locator = Injector::inst()->create(Locator::class); |
36
|
|
|
$this->assertInstanceOf(FieldList::class, $locator->getCMSFields()); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* |
41
|
|
|
*/ |
42
|
|
|
public function testLocations() |
43
|
|
|
{ |
44
|
|
|
$filter = Config::inst()->get(LocatorController::class, 'base_filter'); |
45
|
|
|
$filterAny = Config::inst()->get(LocatorController::class, 'base_filter_any'); |
46
|
|
|
$exclude = Config::inst()->get(LocatorController::class, 'base_exclude'); |
47
|
|
|
$locations = Locator::get_locations($filter, $filterAny, $exclude); |
48
|
|
|
$locations2 = Location::get()->filter($filter)->filterAny($filterAny)->exclude($exclude); |
49
|
|
|
$this->assertEquals($locations->count(), $locations2->count()); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* |
54
|
|
|
*/ |
55
|
|
|
public function testGetAllCategories() |
56
|
|
|
{ |
57
|
|
|
$this->assertEquals(Locator::get_all_categories()->count(), 4); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* |
62
|
|
|
*/ |
63
|
|
|
public function testGetPageCategories() |
64
|
|
|
{ |
65
|
|
|
$locator = $this->objFromFixture(Locator::class, 'locator1'); |
66
|
|
|
$this->assertEquals($locator->getPageCategories()->count(), 1); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* |
71
|
|
|
*/ |
72
|
|
|
public function testLocator_categories_by_locator() |
73
|
|
|
{ |
74
|
|
|
$categories = Locator::locator_categories_by_locator(0); |
75
|
|
|
$this->assertFalse($categories); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* |
80
|
|
|
*/ |
81
|
|
|
public function testLocatorCategoriesByLocator() |
82
|
|
|
{ |
83
|
|
|
|
84
|
|
|
$locator = $this->objFromFixture(Locator::class, 'locator1'); |
85
|
|
|
$this->assertEquals(Locator::locator_categories_by_locator($locator->ID)->count(), 1); |
86
|
|
|
|
87
|
|
|
$newLocator = Locator::create(); |
88
|
|
|
$newLocator->Title = 'Locator 2'; |
89
|
|
|
$newLocator->write(); |
90
|
|
|
|
91
|
|
|
$this->assertEquals(Locator::locator_categories_by_locator($newLocator->ID)->count(), 0); |
92
|
|
|
|
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* |
97
|
|
|
*/ |
98
|
|
|
public function testGetRadii() |
99
|
|
|
{ |
100
|
|
|
/** @var Locator $locator */ |
101
|
|
|
$locator = Injector::inst()->create(Locator::class); |
102
|
|
|
$radii = [ |
103
|
|
|
'0' => '5', |
104
|
|
|
'1' => '10', |
105
|
|
|
'2' => '15', |
106
|
|
|
'3' => '100', |
107
|
|
|
]; |
108
|
|
|
Config::modify()->set(Locator::class, 'radii', $radii); |
109
|
|
|
$this->assertEquals($radii, $locator->getRadii()); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* |
114
|
|
|
*/ |
115
|
|
|
public function testGetRadiiArrayList() |
116
|
|
|
{ |
117
|
|
|
/** @var Locator $locator */ |
118
|
|
|
$locator = Injector::inst()->create(Locator::class); |
119
|
|
|
$this->assertInstanceOf(ArrayList::class, $locator->getRadiiArrayList()); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* |
124
|
|
|
*/ |
125
|
|
|
public function testGetLimit() |
126
|
|
|
{ |
127
|
|
|
/** @var Locator $locator */ |
128
|
|
|
$locator = Injector::inst()->create(Locator::class); |
129
|
|
|
$this->assertEquals(50, $locator->getLimit()); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* |
134
|
|
|
*/ |
135
|
|
|
public function testGetShowRadius() |
136
|
|
|
{ |
137
|
|
|
/** @var Locator $locator */ |
138
|
|
|
$locator = Injector::inst()->create(Locator::class); |
139
|
|
|
$this->assertTrue($locator->getShowRadius()); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* |
144
|
|
|
*/ |
145
|
|
|
public function testGetUsedCategories() |
146
|
|
|
{ |
147
|
|
|
/** @var Locator $locator */ |
148
|
|
|
$locator = $this->objFromFixture(Locator::class, 'locator1'); |
149
|
|
|
|
150
|
|
|
$categories = $locator->getUsedCategories()->toArray(); |
151
|
|
|
$this->assertEquals(1, count($categories)); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* |
156
|
|
|
*/ |
157
|
|
|
public function testGetInfoWindowTemplate() |
158
|
|
|
{ |
159
|
|
|
/** @var Locator $object */ |
160
|
|
|
$object = Injector::inst()->create(Locator::class); |
161
|
|
|
$template = $object->getInfoWindowTemplate(); |
162
|
|
|
// get rid of cache ending |
163
|
|
|
$template = preg_replace('/\?.*$/', '', $template); |
164
|
|
|
$this->assertStringEndsWith('client/infowindow-description.html', $template); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* |
169
|
|
|
*/ |
170
|
|
|
public function testGetListTemplate() |
171
|
|
|
{ |
172
|
|
|
/** @var Locator $object */ |
173
|
|
|
$object = Injector::inst()->create(Locator::class); |
174
|
|
|
$template = $object->getListTemplate(); |
175
|
|
|
// get rid of cache ending |
176
|
|
|
$template = preg_replace('/\?.*$/', '', $template); |
177
|
|
|
$this->assertStringEndsWith('client/location-list-description.html', $template); |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
|