Passed
Pull Request — master (#223)
by Nic
02:42
created
src/Model/Location.php 2 patches
Indentation   +252 added lines, -252 removed lines patch added patch discarded remove patch
@@ -28,256 +28,256 @@
 block discarded – undo
28 28
  */
29 29
 class Location extends DataObject implements PermissionProvider
30 30
 {
31
-    /**
32
-     * @var string
33
-     */
34
-    private static $singular_name = 'Location';
35
-
36
-    /**
37
-     * @var string
38
-     */
39
-    private static $plural_name = 'Locations';
40
-
41
-    /**
42
-     * @var array
43
-     */
44
-    private static $db = [
45
-        'Title' => 'Varchar(255)',
46
-        'Featured' => 'Boolean',
47
-        'Website' => 'Varchar(255)',
48
-        'Phone' => 'Varchar(40)',
49
-        'Email' => 'Varchar(255)',
50
-        'Fax' => 'Varchar(45)',
51
-        'Import_ID' => 'Int',
52
-    ];
53
-
54
-    private static $many_many = [
55
-        'Categories' => LocationCategory::class,
56
-    ];
57
-
58
-    /**
59
-     * @var string
60
-     */
61
-    private static $table_name = 'Location';
62
-
63
-    /**
64
-     * @var array
65
-     */
66
-    private static $casting = [
67
-        'distance' => 'Decimal(9,3)',
68
-    ];
69
-
70
-    /**
71
-     * @var string
72
-     */
73
-    private static $default_sort = 'Title';
74
-
75
-    /**
76
-     * api access via Restful Server module
77
-     *
78
-     * @var bool
79
-     */
80
-    private static $api_access = true;
81
-
82
-    /**
83
-     * search fields for Model Admin
84
-     *
85
-     * @var array
86
-     */
87
-    private static $searchable_fields = [
88
-        'Title',
89
-        'Address',
90
-        'City',
91
-        'State',
92
-        'PostalCode',
93
-        'Country',
94
-        'Website',
95
-        'Phone',
96
-        'Email',
97
-        'Featured',
98
-    ];
99
-
100
-    /**
101
-     * columns for grid field
102
-     *
103
-     * @var array
104
-     */
105
-    private static $summary_fields = [
106
-        'Title',
107
-        'Address',
108
-        'Address2',
109
-        'City',
110
-        'State',
111
-        'PostalCode',
112
-        'CountryCode',
113
-        'Phone' => 'Phone',
114
-        'Fax' => 'Fax',
115
-        'Email' => 'Email',
116
-        'Website' => 'Website',
117
-        'Featured',
118
-        'CategoryList',
119
-        'Lat',
120
-        'Lng',
121
-        'Import_ID',
122
-    ];
123
-
124
-    /**
125
-     * Coords status for $summary_fields
126
-     *
127
-     * @return string
128
-     */
129
-    public function getCoords()
130
-    {
131
-        return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false';
132
-    }
133
-
134
-    /**
135
-     * @return string
136
-     */
137
-    public function getCategoryList()
138
-    {
139
-        if ($this->Categories()->count()) {
140
-            return implode(', ', $this->Categories()->column('Name'));
141
-        }
142
-
143
-        return '';
144
-    }
145
-
146
-    /**
147
-     * @return bool|string
148
-     */
149
-    public function getCountryCode()
150
-    {
151
-        if ($this->Country) {
152
-            return strtoupper($this->Country);
153
-        }
154
-
155
-        return false;
156
-    }
157
-
158
-    /**
159
-     * custom labels for fields
160
-     *
161
-     * @param bool $includerelations
162
-     * @return array|string
163
-     */
164
-    public function fieldLabels($includerelations = true)
165
-    {
166
-        $labels = parent::fieldLabels($includerelations);
167
-        $labels['Title'] = 'Name';
168
-        $labels['Address2'] = 'Address 2';
169
-        $labels['PostalCode'] = 'Postal Code';
170
-        $labels['Categories.Name'] = 'Categories';
171
-        $labels['Featured.NiceAsBoolean'] = 'Featured';
172
-
173
-        return $labels;
174
-    }
175
-
176
-    /**
177
-     * @return FieldList
178
-     */
179
-    public function getCMSFields()
180
-    {
181
-        $this->beforeUpdateCMSFields(function ($fields) {
182
-            $fields->removeByName([
183
-                'Import_ID',
184
-                'LinkTracking',
185
-                'FileTracking',
186
-            ]);
187
-
188
-            $fields->dataFieldByName('Website')
189
-                ->setAttribute('placeholder', 'http://');
190
-
191
-            $fields->replaceField('Email', EmailField::create('Email'));
192
-
193
-            $featured = $fields->dataFieldByName('Featured')
194
-                ->setDescription('Location will display near the top of the results list');
195
-            $fields->insertAfter(
196
-                'Fax',
197
-                $featured
198
-            );
199
-
200
-            if ($this->ID) {
201
-                $categories = $fields->dataFieldByName('Categories');
202
-                $config = $categories->getConfig();
203
-                $config->removeComponentsByType([
204
-                    GridFieldAddExistingAutocompleter::class,
205
-                ])
206
-                    ->addComponents([
207
-                        new GridFieldAddExistingSearchButton(),
208
-                    ]);
209
-            }
210
-        });
211
-
212
-        $fields = parent::getCMSFields();
213
-
214
-        // allow to be extended via DataExtension
215
-        $this->extend('updateLocationFields', $fields);
216
-
217
-        return $fields;
218
-    }
219
-
220
-    /**
221
-     * @param null $member
222
-     * @param array $context
223
-     * @return bool
224
-     */
225
-    public function canView($member = null, $context = [])
226
-    {
227
-        return true;
228
-    }
229
-
230
-    /**
231
-     * @param null $member
232
-     * @param array $context
233
-     * @return bool|int
234
-     */
235
-    public function canEdit($member = null, $context = [])
236
-    {
237
-        return Permission::check('Location_EDIT', 'any', $member);
238
-    }
239
-
240
-    /**
241
-     * @param null $member
242
-     * @param array $context
243
-     * @return bool|int
244
-     */
245
-    public function canDelete($member = null, $context = [])
246
-    {
247
-        return Permission::check('Location_DELETE', 'any', $member);
248
-    }
249
-
250
-    /**
251
-     * @param null $member
252
-     * @param array $context
253
-     * @return bool|int
254
-     */
255
-    public function canCreate($member = null, $context = [])
256
-    {
257
-        return Permission::check('Location_CREATE', 'any', $member);
258
-    }
259
-
260
-    /**
261
-     * @return array
262
-     */
263
-    public function providePermissions()
264
-    {
265
-        return [
266
-            'Location_EDIT' => 'Edit a Location',
267
-            'Location_DELETE' => 'Delete a Location',
268
-            'Location_CREATE' => 'Create a Location',
269
-        ];
270
-    }
271
-
272
-    /**
273
-     * @return string
274
-     */
275
-    public function getWebsiteURL()
276
-    {
277
-        $url = $this->Website;
278
-
279
-        $this->extend('updateWebsiteURL', $url);
280
-
281
-        return $url;
282
-    }
31
+	/**
32
+	 * @var string
33
+	 */
34
+	private static $singular_name = 'Location';
35
+
36
+	/**
37
+	 * @var string
38
+	 */
39
+	private static $plural_name = 'Locations';
40
+
41
+	/**
42
+	 * @var array
43
+	 */
44
+	private static $db = [
45
+		'Title' => 'Varchar(255)',
46
+		'Featured' => 'Boolean',
47
+		'Website' => 'Varchar(255)',
48
+		'Phone' => 'Varchar(40)',
49
+		'Email' => 'Varchar(255)',
50
+		'Fax' => 'Varchar(45)',
51
+		'Import_ID' => 'Int',
52
+	];
53
+
54
+	private static $many_many = [
55
+		'Categories' => LocationCategory::class,
56
+	];
57
+
58
+	/**
59
+	 * @var string
60
+	 */
61
+	private static $table_name = 'Location';
62
+
63
+	/**
64
+	 * @var array
65
+	 */
66
+	private static $casting = [
67
+		'distance' => 'Decimal(9,3)',
68
+	];
69
+
70
+	/**
71
+	 * @var string
72
+	 */
73
+	private static $default_sort = 'Title';
74
+
75
+	/**
76
+	 * api access via Restful Server module
77
+	 *
78
+	 * @var bool
79
+	 */
80
+	private static $api_access = true;
81
+
82
+	/**
83
+	 * search fields for Model Admin
84
+	 *
85
+	 * @var array
86
+	 */
87
+	private static $searchable_fields = [
88
+		'Title',
89
+		'Address',
90
+		'City',
91
+		'State',
92
+		'PostalCode',
93
+		'Country',
94
+		'Website',
95
+		'Phone',
96
+		'Email',
97
+		'Featured',
98
+	];
99
+
100
+	/**
101
+	 * columns for grid field
102
+	 *
103
+	 * @var array
104
+	 */
105
+	private static $summary_fields = [
106
+		'Title',
107
+		'Address',
108
+		'Address2',
109
+		'City',
110
+		'State',
111
+		'PostalCode',
112
+		'CountryCode',
113
+		'Phone' => 'Phone',
114
+		'Fax' => 'Fax',
115
+		'Email' => 'Email',
116
+		'Website' => 'Website',
117
+		'Featured',
118
+		'CategoryList',
119
+		'Lat',
120
+		'Lng',
121
+		'Import_ID',
122
+	];
123
+
124
+	/**
125
+	 * Coords status for $summary_fields
126
+	 *
127
+	 * @return string
128
+	 */
129
+	public function getCoords()
130
+	{
131
+		return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false';
132
+	}
133
+
134
+	/**
135
+	 * @return string
136
+	 */
137
+	public function getCategoryList()
138
+	{
139
+		if ($this->Categories()->count()) {
140
+			return implode(', ', $this->Categories()->column('Name'));
141
+		}
142
+
143
+		return '';
144
+	}
145
+
146
+	/**
147
+	 * @return bool|string
148
+	 */
149
+	public function getCountryCode()
150
+	{
151
+		if ($this->Country) {
152
+			return strtoupper($this->Country);
153
+		}
154
+
155
+		return false;
156
+	}
157
+
158
+	/**
159
+	 * custom labels for fields
160
+	 *
161
+	 * @param bool $includerelations
162
+	 * @return array|string
163
+	 */
164
+	public function fieldLabels($includerelations = true)
165
+	{
166
+		$labels = parent::fieldLabels($includerelations);
167
+		$labels['Title'] = 'Name';
168
+		$labels['Address2'] = 'Address 2';
169
+		$labels['PostalCode'] = 'Postal Code';
170
+		$labels['Categories.Name'] = 'Categories';
171
+		$labels['Featured.NiceAsBoolean'] = 'Featured';
172
+
173
+		return $labels;
174
+	}
175
+
176
+	/**
177
+	 * @return FieldList
178
+	 */
179
+	public function getCMSFields()
180
+	{
181
+		$this->beforeUpdateCMSFields(function ($fields) {
182
+			$fields->removeByName([
183
+				'Import_ID',
184
+				'LinkTracking',
185
+				'FileTracking',
186
+			]);
187
+
188
+			$fields->dataFieldByName('Website')
189
+				->setAttribute('placeholder', 'http://');
190
+
191
+			$fields->replaceField('Email', EmailField::create('Email'));
192
+
193
+			$featured = $fields->dataFieldByName('Featured')
194
+				->setDescription('Location will display near the top of the results list');
195
+			$fields->insertAfter(
196
+				'Fax',
197
+				$featured
198
+			);
199
+
200
+			if ($this->ID) {
201
+				$categories = $fields->dataFieldByName('Categories');
202
+				$config = $categories->getConfig();
203
+				$config->removeComponentsByType([
204
+					GridFieldAddExistingAutocompleter::class,
205
+				])
206
+					->addComponents([
207
+						new GridFieldAddExistingSearchButton(),
208
+					]);
209
+			}
210
+		});
211
+
212
+		$fields = parent::getCMSFields();
213
+
214
+		// allow to be extended via DataExtension
215
+		$this->extend('updateLocationFields', $fields);
216
+
217
+		return $fields;
218
+	}
219
+
220
+	/**
221
+	 * @param null $member
222
+	 * @param array $context
223
+	 * @return bool
224
+	 */
225
+	public function canView($member = null, $context = [])
226
+	{
227
+		return true;
228
+	}
229
+
230
+	/**
231
+	 * @param null $member
232
+	 * @param array $context
233
+	 * @return bool|int
234
+	 */
235
+	public function canEdit($member = null, $context = [])
236
+	{
237
+		return Permission::check('Location_EDIT', 'any', $member);
238
+	}
239
+
240
+	/**
241
+	 * @param null $member
242
+	 * @param array $context
243
+	 * @return bool|int
244
+	 */
245
+	public function canDelete($member = null, $context = [])
246
+	{
247
+		return Permission::check('Location_DELETE', 'any', $member);
248
+	}
249
+
250
+	/**
251
+	 * @param null $member
252
+	 * @param array $context
253
+	 * @return bool|int
254
+	 */
255
+	public function canCreate($member = null, $context = [])
256
+	{
257
+		return Permission::check('Location_CREATE', 'any', $member);
258
+	}
259
+
260
+	/**
261
+	 * @return array
262
+	 */
263
+	public function providePermissions()
264
+	{
265
+		return [
266
+			'Location_EDIT' => 'Edit a Location',
267
+			'Location_DELETE' => 'Delete a Location',
268
+			'Location_CREATE' => 'Create a Location',
269
+		];
270
+	}
271
+
272
+	/**
273
+	 * @return string
274
+	 */
275
+	public function getWebsiteURL()
276
+	{
277
+		$url = $this->Website;
278
+
279
+		$this->extend('updateWebsiteURL', $url);
280
+
281
+		return $url;
282
+	}
283 283
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -178,7 +178,7 @@
 block discarded – undo
178 178
      */
179 179
     public function getCMSFields()
180 180
     {
181
-        $this->beforeUpdateCMSFields(function ($fields) {
181
+        $this->beforeUpdateCMSFields(function($fields) {
182 182
             $fields->removeByName([
183 183
                 'Import_ID',
184 184
                 'LinkTracking',
Please login to merge, or discard this patch.
src/form/LocatorForm.php 1 patch
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -18,88 +18,88 @@
 block discarded – undo
18 18
  */
19 19
 class LocatorForm extends Form
20 20
 {
21
-    /**
22
-     * LocatorForm constructor.
23
-     * @param Controller $controller
24
-     * @param string $name
25
-     */
26
-    public function __construct(Controller $controller, $name)
27
-    {
21
+	/**
22
+	 * LocatorForm constructor.
23
+	 * @param Controller $controller
24
+	 * @param string $name
25
+	 */
26
+	public function __construct(Controller $controller, $name)
27
+	{
28 28
 
29
-        $fields = FieldList::create(
30
-            TextField::create('Address')
31
-                ->setTitle('')
32
-                ->setAttribute('placeholder', 'address or zip code')
33
-        );
29
+		$fields = FieldList::create(
30
+			TextField::create('Address')
31
+				->setTitle('')
32
+				->setAttribute('placeholder', 'address or zip code')
33
+		);
34 34
 
35
-        $pageCategories = Locator::locator_categories_by_locator($controller->data()->ID);
36
-        if ($pageCategories && $pageCategories->count() > 0) {
37
-            $categories = false;
38
-        } else {
39
-            $categories = Locator::get_all_categories();
40
-            if ($categories->count() < 1) {
41
-                $categories = false;
42
-            }
43
-        }
35
+		$pageCategories = Locator::locator_categories_by_locator($controller->data()->ID);
36
+		if ($pageCategories && $pageCategories->count() > 0) {
37
+			$categories = false;
38
+		} else {
39
+			$categories = Locator::get_all_categories();
40
+			if ($categories->count() < 1) {
41
+				$categories = false;
42
+			}
43
+		}
44 44
 
45
-        if ($categories) {
46
-            $categoriesField = DropdownField::create('CategoryID')
47
-                ->setTitle('')
48
-                ->setEmptyString('all categories')
49
-                ->setSource($categories->map());
50
-            $fields->push($categoriesField);
51
-        }
45
+		if ($categories) {
46
+			$categoriesField = DropdownField::create('CategoryID')
47
+				->setTitle('')
48
+				->setEmptyString('all categories')
49
+				->setSource($categories->map());
50
+			$fields->push($categoriesField);
51
+		}
52 52
 
53
-        if ($controller->getShowRadius()) {
54
-            $radiusArray = array_values($controller->getRadii());
55
-            $this->extend('overrideRadiusArray', $radiusArray);
56
-            $fields->push(DropdownField::create('Radius', '', ArrayLib::valuekey($radiusArray))
57
-                ->setEmptyString('radius'));
58
-        }
53
+		if ($controller->getShowRadius()) {
54
+			$radiusArray = array_values($controller->getRadii());
55
+			$this->extend('overrideRadiusArray', $radiusArray);
56
+			$fields->push(DropdownField::create('Radius', '', ArrayLib::valuekey($radiusArray))
57
+				->setEmptyString('radius'));
58
+		}
59 59
 
60
-        $actions = FieldList::create(
61
-            FormAction::create('doFilterLocations')
62
-                ->setTitle('Search')
63
-        );
60
+		$actions = FieldList::create(
61
+			FormAction::create('doFilterLocations')
62
+				->setTitle('Search')
63
+		);
64 64
 
65
-        $validator = $this->getValidator();
65
+		$validator = $this->getValidator();
66 66
 
67
-        parent::__construct($controller, $name, $fields, $actions, $validator);
68
-    }
67
+		parent::__construct($controller, $name, $fields, $actions, $validator);
68
+	}
69 69
 
70
-    /**
71
-     * @return null|RequiredFields|\SilverStripe\Forms\Validator
72
-     */
73
-    public function getValidator()
74
-    {
75
-        $validator = parent::getValidator();
76
-        if (empty($validator)) {
77
-            if (!$this->validator instanceof RequiredFields) {
78
-                $this->setValidator(RequiredFields::create('Address'));
79
-            }
80
-            $validator = $this->validator;
81
-        }
82
-        $this->extend('updateRequiredFields', $validator);
83
-        return $validator;
84
-    }
70
+	/**
71
+	 * @return null|RequiredFields|\SilverStripe\Forms\Validator
72
+	 */
73
+	public function getValidator()
74
+	{
75
+		$validator = parent::getValidator();
76
+		if (empty($validator)) {
77
+			if (!$this->validator instanceof RequiredFields) {
78
+				$this->setValidator(RequiredFields::create('Address'));
79
+			}
80
+			$validator = $this->validator;
81
+		}
82
+		$this->extend('updateRequiredFields', $validator);
83
+		return $validator;
84
+	}
85 85
 
86
-    /**
87
-     * @return FieldList
88
-     */
89
-    public function Fields()
90
-    {
91
-        $fields = parent::Fields();
92
-        $this->extend('updateLocatorFormFields', $fields);
93
-        return $fields;
94
-    }
86
+	/**
87
+	 * @return FieldList
88
+	 */
89
+	public function Fields()
90
+	{
91
+		$fields = parent::Fields();
92
+		$this->extend('updateLocatorFormFields', $fields);
93
+		return $fields;
94
+	}
95 95
 
96
-    /**
97
-     * @return \SilverStripe\Forms\FieldList
98
-     */
99
-    public function Actions()
100
-    {
101
-        $actions = parent::Actions();
102
-        $this->extend('updateLocatorActions', $actions);
103
-        return $actions;
104
-    }
96
+	/**
97
+	 * @return \SilverStripe\Forms\FieldList
98
+	 */
99
+	public function Actions()
100
+	{
101
+		$actions = parent::Actions();
102
+		$this->extend('updateLocatorActions', $actions);
103
+		return $actions;
104
+	}
105 105
 }
Please login to merge, or discard this patch.
tests/Model/LocationCategoryTest.php 1 patch
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -13,69 +13,69 @@
 block discarded – undo
13 13
  */
14 14
 class LocationCategoryTest extends SapphireTest
15 15
 {
16
-    /**
17
-     * @var string
18
-     */
19
-    protected static $fixture_file = 'categoryfixture.yml';
16
+	/**
17
+	 * @var string
18
+	 */
19
+	protected static $fixture_file = 'categoryfixture.yml';
20 20
 
21
-    /**
22
-     *
23
-     */
24
-    public function testGetCMSFields()
25
-    {
26
-        $object = $this->objFromFixture(LocationCategory::class, 'service');
27
-        $fieldset = $object->getCMSFields();
28
-        $this->assertInstanceOf(FieldList::class, $fieldset);
29
-    }
21
+	/**
22
+	 *
23
+	 */
24
+	public function testGetCMSFields()
25
+	{
26
+		$object = $this->objFromFixture(LocationCategory::class, 'service');
27
+		$fieldset = $object->getCMSFields();
28
+		$this->assertInstanceOf(FieldList::class, $fieldset);
29
+	}
30 30
 
31
-    /**
32
-     *
33
-     */
34
-    public function testCanView()
35
-    {
36
-        $object = $this->objFromFixture(LocationCategory::class, 'service');
37
-        $this->assertTrue($object->canView());
38
-    }
31
+	/**
32
+	 *
33
+	 */
34
+	public function testCanView()
35
+	{
36
+		$object = $this->objFromFixture(LocationCategory::class, 'service');
37
+		$this->assertTrue($object->canView());
38
+	}
39 39
 
40
-    /**
41
-     *
42
-     */
43
-    public function testCanEdit()
44
-    {
45
-        $object = $this->objFromFixture(LocationCategory::class, 'service');
40
+	/**
41
+	 *
42
+	 */
43
+	public function testCanEdit()
44
+	{
45
+		$object = $this->objFromFixture(LocationCategory::class, 'service');
46 46
 
47
-        $admin = $this->objFromFixture(Member::class, 'locationedit');
48
-        $this->assertTrue($object->canEdit($admin));
47
+		$admin = $this->objFromFixture(Member::class, 'locationedit');
48
+		$this->assertTrue($object->canEdit($admin));
49 49
 
50
-        $member = $this->objFromFixture(Member::class, 'default');
51
-        $this->assertFalse($object->canEdit($member));
52
-    }
50
+		$member = $this->objFromFixture(Member::class, 'default');
51
+		$this->assertFalse($object->canEdit($member));
52
+	}
53 53
 
54
-    /**
55
-     *
56
-     */
57
-    public function testCanDelete()
58
-    {
59
-        $object = $this->objFromFixture(LocationCategory::class, 'service');
54
+	/**
55
+	 *
56
+	 */
57
+	public function testCanDelete()
58
+	{
59
+		$object = $this->objFromFixture(LocationCategory::class, 'service');
60 60
 
61
-        $admin = $this->objFromFixture(Member::class, 'locationdelete');
62
-        $this->assertTrue($object->canDelete($admin));
61
+		$admin = $this->objFromFixture(Member::class, 'locationdelete');
62
+		$this->assertTrue($object->canDelete($admin));
63 63
 
64
-        $member = $this->objFromFixture(Member::class, 'default');
65
-        $this->assertFalse($object->canDelete($member));
66
-    }
64
+		$member = $this->objFromFixture(Member::class, 'default');
65
+		$this->assertFalse($object->canDelete($member));
66
+	}
67 67
 
68
-    /**
69
-     *
70
-     */
71
-    public function testCanCreate()
72
-    {
73
-        $object = $this->objFromFixture(LocationCategory::class, 'service');
68
+	/**
69
+	 *
70
+	 */
71
+	public function testCanCreate()
72
+	{
73
+		$object = $this->objFromFixture(LocationCategory::class, 'service');
74 74
 
75
-        $admin = $this->objFromFixture(Member::class, 'locationcreate');
76
-        $this->assertTrue($object->canCreate($admin));
75
+		$admin = $this->objFromFixture(Member::class, 'locationcreate');
76
+		$this->assertTrue($object->canCreate($admin));
77 77
 
78
-        $member = $this->objFromFixture(Member::class, 'default');
79
-        $this->assertFalse($object->canCreate($member));
80
-    }
78
+		$member = $this->objFromFixture(Member::class, 'default');
79
+		$this->assertFalse($object->canCreate($member));
80
+	}
81 81
 }
Please login to merge, or discard this patch.
tests/Model/LocationTest.php 2 patches
Indentation   +202 added lines, -202 removed lines patch added patch discarded remove patch
@@ -16,206 +16,206 @@
 block discarded – undo
16 16
  */
17 17
 class LocationTest extends SapphireTest
18 18
 {
19
-    /**
20
-     * @var string
21
-     */
22
-    protected static $fixture_file = 'locationfixture.yml';
23
-
24
-    /**
25
-     * @var array
26
-     */
27
-    protected static $extra_dataobjects = [
28
-        ExtendedLocation::class,
29
-    ];
30
-
31
-    /**
32
-     * @var array
33
-     */
34
-    protected static $required_extensions = [
35
-        ExtendedLocation::class => [
36
-            LocationExtension::class,
37
-        ],
38
-    ];
39
-
40
-    /**
41
-     *
42
-     */
43
-    public function testGetCoords()
44
-    {
45
-        $location = $this->objFromFixture(Location::class, 'dynamic');
46
-        $coords = ((int)$location->Lat != 0 && (int)$location->Lng != 0) ? 'true' : 'false';
47
-        $this->assertEquals($coords, $location->getCoords());
48
-    }
49
-
50
-    /**
51
-     *
52
-     */
53
-    public function testFieldLabels()
54
-    {
55
-        $this->markTestSkipped();
56
-        // Link and File tracking display as "Tracking" in SS 4.2 & 4.3, "Tracking" in 4.4
57
-        $location = $this->objFromFixture(Location::class, 'dynamic');
58
-        $labels = $location->FieldLabels();
59
-        $expected = [
60
-            'Title' => 'Name',
61
-            'Featured' => 'Featured',
62
-            'Website' => 'Website',
63
-            'Phone' => 'Phone',
64
-            'Email' => 'Email',
65
-            'Fax' => 'Fax',
66
-            'Address' => 'Address',
67
-            'City' => 'City',
68
-            'State' => 'State',
69
-            'PostalCode' => 'Postal Code',
70
-            'Country' => 'Country',
71
-            'Lat' => 'Lat',
72
-            'Lng' => 'Lng',
73
-            'Categories' => 'Categories',
74
-            'Category.Name' => 'Category',
75
-            'Category.ID' => 'Category',
76
-            'Featured.NiceAsBoolean' => 'Featured',
77
-            'Import_ID' => 'Import_ID',
78
-            'Version' => 'Version',
79
-            'Versions' => 'Versions',
80
-            'Address2' => 'Address2',
81
-            'LinkTracking' => 'Link tracking',
82
-            'FileTracking' => 'File tracking',
83
-        ];
84
-        $this->assertEquals($expected, $labels);
85
-    }
86
-
87
-    /**
88
-     *
89
-     */
90
-    public function testGetCMSFields()
91
-    {
92
-        $object = new Location();
93
-        $fieldset = $object->getCMSFields();
94
-        $this->assertinstanceOf(FieldList::class, $fieldset);
95
-    }
96
-
97
-    /**
98
-     *
99
-     */
100
-    public function testCanView()
101
-    {
102
-        $object = $this->objFromFixture(Location::class, 'dynamic');
103
-        $object->write();
104
-
105
-        $this->assertTrue($object->canView());
106
-
107
-        $nullMember = Member::create();
108
-        $nullMember->write();
109
-
110
-        $this->assertTrue($object->canView($nullMember));
111
-
112
-        $nullMember->delete();
113
-    }
114
-
115
-    /**
116
-     *
117
-     */
118
-    public function testCanEdit()
119
-    {
120
-        $object = $this->objFromFixture(Location::class, 'dynamic');
121
-        $object->write();
122
-
123
-        $objectID = $object->ID;
124
-
125
-        //test permissions per permission setting
126
-        $create = $this->objFromFixture(Member::class, 'locationcreate');
127
-        $edit = $this->objFromFixture(Member::class, 'locationedit');
128
-        $delete = $this->objFromFixture(Member::class, 'locationdelete');
129
-
130
-        $originalTitle = $object->Title;
131
-        $this->assertEquals($originalTitle, 'Dynamic, Inc.');
132
-
133
-        $this->assertTrue($object->canEdit($edit));
134
-        $this->assertFalse($object->canEdit($create));
135
-        $this->assertFalse($object->canEdit($delete));
136
-
137
-        $object->Title = 'Changed Title';
138
-        $object->write();
139
-
140
-        $testEdit = Location::get()->byID($objectID);
141
-        $this->assertEquals($testEdit->Title, 'Changed Title');
142
-    }
143
-
144
-    /**
145
-     *
146
-     */
147
-    public function testCanDelete()
148
-    {
149
-        $object = $this->objFromFixture(Location::class, 'dynamic');
150
-        $object->write();
151
-
152
-        //test permissions per permission setting
153
-        $create = $this->objFromFixture(Member::class, 'locationcreate');
154
-        $edit = $this->objFromFixture(Member::class, 'locationedit');
155
-        $delete = $this->objFromFixture(Member::class, 'locationdelete');
156
-
157
-        $this->assertTrue($object->canDelete($delete));
158
-        $this->assertFalse($object->canDelete($create));
159
-        $this->assertFalse($object->canDelete($edit));
160
-
161
-        $checkObject = $object;
162
-        $object->delete();
163
-
164
-        $this->assertEquals($checkObject->ID, 0);
165
-    }
166
-
167
-    /**
168
-     *
169
-     */
170
-    public function testCanCreate()
171
-    {
172
-        $object = singleton(Location::class);
173
-
174
-        //test permissions per permission setting
175
-        $create = $this->objFromFixture(Member::class, 'locationcreate');
176
-        $edit = $this->objFromFixture(Member::class, 'locationedit');
177
-        $delete = $this->objFromFixture(Member::class, 'locationdelete');
178
-
179
-        $this->assertTrue($object->canCreate($create));
180
-        $this->assertFalse($object->canCreate($edit));
181
-        $this->assertFalse($object->canCreate($delete));
182
-
183
-        $nullMember = Member::create();
184
-        $nullMember->write();
185
-        $this->assertFalse($object->canCreate($nullMember));
186
-
187
-        $nullMember->delete();
188
-    }
189
-
190
-    /**
191
-     *
192
-     */
193
-    public function testProvidePermissions()
194
-    {
195
-        $object = Location::create();
196
-        $expected = [
197
-            'Location_EDIT' => 'Edit a Location',
198
-            'Location_DELETE' => 'Delete a Location',
199
-            'Location_CREATE' => 'Create a Location',
200
-        ];
201
-        $this->assertEquals($expected, $object->providePermissions());
202
-    }
203
-
204
-    /**
205
-     *
206
-     */
207
-    public function testUpdateWebsiteURL()
208
-    {
209
-        $location = $this->objFromFixture(Location::class, 'dynamic');
210
-
211
-        // Create unsaved raw duplicate
212
-        $map = $location->toMap();
213
-        unset($map['Created']);
214
-        /** @var static $clone */
215
-        $clone = Injector::inst()->create(ExtendedLocation::class, $map);
216
-        $clone->ID = 0;
217
-
218
-        $this->assertEquals('http://www.dynamicagency.com', $location->getWebsiteURL());
219
-        $this->assertEquals('foo', $clone->getWebsiteURL());
220
-    }
19
+	/**
20
+	 * @var string
21
+	 */
22
+	protected static $fixture_file = 'locationfixture.yml';
23
+
24
+	/**
25
+	 * @var array
26
+	 */
27
+	protected static $extra_dataobjects = [
28
+		ExtendedLocation::class,
29
+	];
30
+
31
+	/**
32
+	 * @var array
33
+	 */
34
+	protected static $required_extensions = [
35
+		ExtendedLocation::class => [
36
+			LocationExtension::class,
37
+		],
38
+	];
39
+
40
+	/**
41
+	 *
42
+	 */
43
+	public function testGetCoords()
44
+	{
45
+		$location = $this->objFromFixture(Location::class, 'dynamic');
46
+		$coords = ((int)$location->Lat != 0 && (int)$location->Lng != 0) ? 'true' : 'false';
47
+		$this->assertEquals($coords, $location->getCoords());
48
+	}
49
+
50
+	/**
51
+	 *
52
+	 */
53
+	public function testFieldLabels()
54
+	{
55
+		$this->markTestSkipped();
56
+		// Link and File tracking display as "Tracking" in SS 4.2 & 4.3, "Tracking" in 4.4
57
+		$location = $this->objFromFixture(Location::class, 'dynamic');
58
+		$labels = $location->FieldLabels();
59
+		$expected = [
60
+			'Title' => 'Name',
61
+			'Featured' => 'Featured',
62
+			'Website' => 'Website',
63
+			'Phone' => 'Phone',
64
+			'Email' => 'Email',
65
+			'Fax' => 'Fax',
66
+			'Address' => 'Address',
67
+			'City' => 'City',
68
+			'State' => 'State',
69
+			'PostalCode' => 'Postal Code',
70
+			'Country' => 'Country',
71
+			'Lat' => 'Lat',
72
+			'Lng' => 'Lng',
73
+			'Categories' => 'Categories',
74
+			'Category.Name' => 'Category',
75
+			'Category.ID' => 'Category',
76
+			'Featured.NiceAsBoolean' => 'Featured',
77
+			'Import_ID' => 'Import_ID',
78
+			'Version' => 'Version',
79
+			'Versions' => 'Versions',
80
+			'Address2' => 'Address2',
81
+			'LinkTracking' => 'Link tracking',
82
+			'FileTracking' => 'File tracking',
83
+		];
84
+		$this->assertEquals($expected, $labels);
85
+	}
86
+
87
+	/**
88
+	 *
89
+	 */
90
+	public function testGetCMSFields()
91
+	{
92
+		$object = new Location();
93
+		$fieldset = $object->getCMSFields();
94
+		$this->assertinstanceOf(FieldList::class, $fieldset);
95
+	}
96
+
97
+	/**
98
+	 *
99
+	 */
100
+	public function testCanView()
101
+	{
102
+		$object = $this->objFromFixture(Location::class, 'dynamic');
103
+		$object->write();
104
+
105
+		$this->assertTrue($object->canView());
106
+
107
+		$nullMember = Member::create();
108
+		$nullMember->write();
109
+
110
+		$this->assertTrue($object->canView($nullMember));
111
+
112
+		$nullMember->delete();
113
+	}
114
+
115
+	/**
116
+	 *
117
+	 */
118
+	public function testCanEdit()
119
+	{
120
+		$object = $this->objFromFixture(Location::class, 'dynamic');
121
+		$object->write();
122
+
123
+		$objectID = $object->ID;
124
+
125
+		//test permissions per permission setting
126
+		$create = $this->objFromFixture(Member::class, 'locationcreate');
127
+		$edit = $this->objFromFixture(Member::class, 'locationedit');
128
+		$delete = $this->objFromFixture(Member::class, 'locationdelete');
129
+
130
+		$originalTitle = $object->Title;
131
+		$this->assertEquals($originalTitle, 'Dynamic, Inc.');
132
+
133
+		$this->assertTrue($object->canEdit($edit));
134
+		$this->assertFalse($object->canEdit($create));
135
+		$this->assertFalse($object->canEdit($delete));
136
+
137
+		$object->Title = 'Changed Title';
138
+		$object->write();
139
+
140
+		$testEdit = Location::get()->byID($objectID);
141
+		$this->assertEquals($testEdit->Title, 'Changed Title');
142
+	}
143
+
144
+	/**
145
+	 *
146
+	 */
147
+	public function testCanDelete()
148
+	{
149
+		$object = $this->objFromFixture(Location::class, 'dynamic');
150
+		$object->write();
151
+
152
+		//test permissions per permission setting
153
+		$create = $this->objFromFixture(Member::class, 'locationcreate');
154
+		$edit = $this->objFromFixture(Member::class, 'locationedit');
155
+		$delete = $this->objFromFixture(Member::class, 'locationdelete');
156
+
157
+		$this->assertTrue($object->canDelete($delete));
158
+		$this->assertFalse($object->canDelete($create));
159
+		$this->assertFalse($object->canDelete($edit));
160
+
161
+		$checkObject = $object;
162
+		$object->delete();
163
+
164
+		$this->assertEquals($checkObject->ID, 0);
165
+	}
166
+
167
+	/**
168
+	 *
169
+	 */
170
+	public function testCanCreate()
171
+	{
172
+		$object = singleton(Location::class);
173
+
174
+		//test permissions per permission setting
175
+		$create = $this->objFromFixture(Member::class, 'locationcreate');
176
+		$edit = $this->objFromFixture(Member::class, 'locationedit');
177
+		$delete = $this->objFromFixture(Member::class, 'locationdelete');
178
+
179
+		$this->assertTrue($object->canCreate($create));
180
+		$this->assertFalse($object->canCreate($edit));
181
+		$this->assertFalse($object->canCreate($delete));
182
+
183
+		$nullMember = Member::create();
184
+		$nullMember->write();
185
+		$this->assertFalse($object->canCreate($nullMember));
186
+
187
+		$nullMember->delete();
188
+	}
189
+
190
+	/**
191
+	 *
192
+	 */
193
+	public function testProvidePermissions()
194
+	{
195
+		$object = Location::create();
196
+		$expected = [
197
+			'Location_EDIT' => 'Edit a Location',
198
+			'Location_DELETE' => 'Delete a Location',
199
+			'Location_CREATE' => 'Create a Location',
200
+		];
201
+		$this->assertEquals($expected, $object->providePermissions());
202
+	}
203
+
204
+	/**
205
+	 *
206
+	 */
207
+	public function testUpdateWebsiteURL()
208
+	{
209
+		$location = $this->objFromFixture(Location::class, 'dynamic');
210
+
211
+		// Create unsaved raw duplicate
212
+		$map = $location->toMap();
213
+		unset($map['Created']);
214
+		/** @var static $clone */
215
+		$clone = Injector::inst()->create(ExtendedLocation::class, $map);
216
+		$clone->ID = 0;
217
+
218
+		$this->assertEquals('http://www.dynamicagency.com', $location->getWebsiteURL());
219
+		$this->assertEquals('foo', $clone->getWebsiteURL());
220
+	}
221 221
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@
 block discarded – undo
23 23
     public function testGetCoords()
24 24
     {
25 25
         $location = $this->objFromFixture(Location::class, 'dynamic');
26
-        $coords = ((int)$location->Lat != 0 && (int)$location->Lng != 0) ? 'true' : 'false';
26
+        $coords = ((int) $location->Lat != 0 && (int) $location->Lng != 0) ? 'true' : 'false';
27 27
         $this->assertEquals($coords, $location->getCoords());
28 28
     }
29 29
 
Please login to merge, or discard this patch.
tests/TestOnly/Model/ExtendedLocation.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -12,10 +12,10 @@
 block discarded – undo
12 12
  */
13 13
 class ExtendedLocation extends Location implements TestOnly
14 14
 {
15
-    /**
16
-     * @var array
17
-     */
18
-    private static $extensions = [
19
-        LocationExtension::class,
20
-    ];
15
+	/**
16
+	 * @var array
17
+	 */
18
+	private static $extensions = [
19
+		LocationExtension::class,
20
+	];
21 21
 }
Please login to merge, or discard this patch.
tests/Page/LocatorTest.php 1 patch
Indentation   +164 added lines, -164 removed lines patch added patch discarded remove patch
@@ -17,168 +17,168 @@
 block discarded – undo
17 17
  */
18 18
 class LocatorTest extends FunctionalTest
19 19
 {
20
-    /**
21
-     * @var string
22
-     */
23
-    protected static $fixture_file = 'locatorfixture.yml';
24
-
25
-    /**
26
-     *
27
-     */
28
-    protected function setUp()
29
-    {
30
-        parent::setUp();
31
-
32
-        Config::modify()->set(Locator::class, 'location_class', Location::class);
33
-    }
34
-
35
-    /**
36
-     *
37
-     */
38
-    public function testGetCMSFields()
39
-    {
40
-        /** @var Locator $locator */
41
-        $locator = Injector::inst()->create(Locator::class);
42
-        $this->assertInstanceOf(FieldList::class, $locator->getCMSFields());
43
-    }
44
-
45
-    /**
46
-     *
47
-     */
48
-    public function testLocations()
49
-    {
50
-        $filter = Config::inst()->get(LocatorController::class, 'base_filter');
51
-        $filterAny = Config::inst()->get(LocatorController::class, 'base_filter_any');
52
-        $exclude = Config::inst()->get(LocatorController::class, 'base_exclude');
53
-        $locations = Locator::get_locations($filter, $filterAny, $exclude);
54
-        $locations2 = Location::get()->filter($filter)->filterAny($filterAny)->exclude($exclude);
55
-        $this->assertEquals($locations->count(), $locations2->count());
56
-    }
57
-
58
-    /**
59
-     *
60
-     */
61
-    public function testGetAllCategories()
62
-    {
63
-        $this->assertEquals(Locator::get_all_categories()->count(), 4);
64
-    }
65
-
66
-    /**
67
-     *
68
-     */
69
-    public function testGetPageCategories()
70
-    {
71
-        $locator = $this->objFromFixture(Locator::class, 'locator1');
72
-        $this->assertEquals($locator->getPageCategories()->count(), 1);
73
-    }
74
-
75
-    /**
76
-     *
77
-     */
78
-    public function testLocator_categories_by_locator()
79
-    {
80
-        $categories = Locator::locator_categories_by_locator(0);
81
-        $this->assertFalse($categories);
82
-    }
83
-
84
-    /**
85
-     *
86
-     */
87
-    public function testLocatorCategoriesByLocator()
88
-    {
89
-
90
-        $locator = $this->objFromFixture(Locator::class, 'locator1');
91
-        $this->assertEquals(Locator::locator_categories_by_locator($locator->ID)->count(), 1);
92
-
93
-        $newLocator = Locator::create();
94
-        $newLocator->Title = 'Locator 2';
95
-        $newLocator->write();
96
-
97
-        $this->assertEquals(Locator::locator_categories_by_locator($newLocator->ID)->count(), 0);
98
-    }
99
-
100
-    /**
101
-     *
102
-     */
103
-    public function testGetRadii()
104
-    {
105
-        /** @var Locator $locator */
106
-        $locator = Injector::inst()->create(Locator::class);
107
-        $radii = [
108
-            '0' => '5',
109
-            '1' => '10',
110
-            '2' => '15',
111
-            '3' => '100',
112
-        ];
113
-        Config::modify()->set(Locator::class, 'radii', $radii);
114
-        $this->assertEquals($radii, $locator->getRadii());
115
-    }
116
-
117
-    /**
118
-     *
119
-     */
120
-    public function testGetRadiiArrayList()
121
-    {
122
-        /** @var Locator $locator */
123
-        $locator = Injector::inst()->create(Locator::class);
124
-        $this->assertInstanceOf(ArrayList::class, $locator->getRadiiArrayList());
125
-    }
126
-
127
-    /**
128
-     *
129
-     */
130
-    public function testGetLimit()
131
-    {
132
-        /** @var Locator $locator */
133
-        $locator = Injector::inst()->create(Locator::class);
134
-        $this->assertEquals(50, $locator->getLimit());
135
-    }
136
-
137
-    /**
138
-     *
139
-     */
140
-    public function testGetShowRadius()
141
-    {
142
-        /** @var Locator $locator */
143
-        $locator = Injector::inst()->create(Locator::class);
144
-        $this->assertTrue($locator->getShowRadius());
145
-    }
146
-
147
-    /**
148
-     *
149
-     */
150
-    public function testGetUsedCategories()
151
-    {
152
-        /** @var Locator $locator */
153
-        $locator = $this->objFromFixture(Locator::class, 'locator1');
154
-
155
-        $categories = $locator->getUsedCategories()->toArray();
156
-        $this->assertEquals(1, count($categories));
157
-    }
158
-
159
-    /**
160
-     *
161
-     */
162
-    public function testGetInfoWindowTemplate()
163
-    {
164
-        /** @var Locator $object */
165
-        $object = Injector::inst()->create(Locator::class);
166
-        $template = $object->getInfoWindowTemplate();
167
-        // get rid of cache ending
168
-        $template = preg_replace('/\?.*$/', '', $template);
169
-        $this->assertStringEndsWith('client/infowindow-description.html', $template);
170
-    }
171
-
172
-    /**
173
-     *
174
-     */
175
-    public function testGetListTemplate()
176
-    {
177
-        /** @var Locator $object */
178
-        $object = Injector::inst()->create(Locator::class);
179
-        $template = $object->getListTemplate();
180
-        // get rid of cache ending
181
-        $template = preg_replace('/\?.*$/', '', $template);
182
-        $this->assertStringEndsWith('client/location-list-description.html', $template);
183
-    }
20
+	/**
21
+	 * @var string
22
+	 */
23
+	protected static $fixture_file = 'locatorfixture.yml';
24
+
25
+	/**
26
+	 *
27
+	 */
28
+	protected function setUp()
29
+	{
30
+		parent::setUp();
31
+
32
+		Config::modify()->set(Locator::class, 'location_class', Location::class);
33
+	}
34
+
35
+	/**
36
+	 *
37
+	 */
38
+	public function testGetCMSFields()
39
+	{
40
+		/** @var Locator $locator */
41
+		$locator = Injector::inst()->create(Locator::class);
42
+		$this->assertInstanceOf(FieldList::class, $locator->getCMSFields());
43
+	}
44
+
45
+	/**
46
+	 *
47
+	 */
48
+	public function testLocations()
49
+	{
50
+		$filter = Config::inst()->get(LocatorController::class, 'base_filter');
51
+		$filterAny = Config::inst()->get(LocatorController::class, 'base_filter_any');
52
+		$exclude = Config::inst()->get(LocatorController::class, 'base_exclude');
53
+		$locations = Locator::get_locations($filter, $filterAny, $exclude);
54
+		$locations2 = Location::get()->filter($filter)->filterAny($filterAny)->exclude($exclude);
55
+		$this->assertEquals($locations->count(), $locations2->count());
56
+	}
57
+
58
+	/**
59
+	 *
60
+	 */
61
+	public function testGetAllCategories()
62
+	{
63
+		$this->assertEquals(Locator::get_all_categories()->count(), 4);
64
+	}
65
+
66
+	/**
67
+	 *
68
+	 */
69
+	public function testGetPageCategories()
70
+	{
71
+		$locator = $this->objFromFixture(Locator::class, 'locator1');
72
+		$this->assertEquals($locator->getPageCategories()->count(), 1);
73
+	}
74
+
75
+	/**
76
+	 *
77
+	 */
78
+	public function testLocator_categories_by_locator()
79
+	{
80
+		$categories = Locator::locator_categories_by_locator(0);
81
+		$this->assertFalse($categories);
82
+	}
83
+
84
+	/**
85
+	 *
86
+	 */
87
+	public function testLocatorCategoriesByLocator()
88
+	{
89
+
90
+		$locator = $this->objFromFixture(Locator::class, 'locator1');
91
+		$this->assertEquals(Locator::locator_categories_by_locator($locator->ID)->count(), 1);
92
+
93
+		$newLocator = Locator::create();
94
+		$newLocator->Title = 'Locator 2';
95
+		$newLocator->write();
96
+
97
+		$this->assertEquals(Locator::locator_categories_by_locator($newLocator->ID)->count(), 0);
98
+	}
99
+
100
+	/**
101
+	 *
102
+	 */
103
+	public function testGetRadii()
104
+	{
105
+		/** @var Locator $locator */
106
+		$locator = Injector::inst()->create(Locator::class);
107
+		$radii = [
108
+			'0' => '5',
109
+			'1' => '10',
110
+			'2' => '15',
111
+			'3' => '100',
112
+		];
113
+		Config::modify()->set(Locator::class, 'radii', $radii);
114
+		$this->assertEquals($radii, $locator->getRadii());
115
+	}
116
+
117
+	/**
118
+	 *
119
+	 */
120
+	public function testGetRadiiArrayList()
121
+	{
122
+		/** @var Locator $locator */
123
+		$locator = Injector::inst()->create(Locator::class);
124
+		$this->assertInstanceOf(ArrayList::class, $locator->getRadiiArrayList());
125
+	}
126
+
127
+	/**
128
+	 *
129
+	 */
130
+	public function testGetLimit()
131
+	{
132
+		/** @var Locator $locator */
133
+		$locator = Injector::inst()->create(Locator::class);
134
+		$this->assertEquals(50, $locator->getLimit());
135
+	}
136
+
137
+	/**
138
+	 *
139
+	 */
140
+	public function testGetShowRadius()
141
+	{
142
+		/** @var Locator $locator */
143
+		$locator = Injector::inst()->create(Locator::class);
144
+		$this->assertTrue($locator->getShowRadius());
145
+	}
146
+
147
+	/**
148
+	 *
149
+	 */
150
+	public function testGetUsedCategories()
151
+	{
152
+		/** @var Locator $locator */
153
+		$locator = $this->objFromFixture(Locator::class, 'locator1');
154
+
155
+		$categories = $locator->getUsedCategories()->toArray();
156
+		$this->assertEquals(1, count($categories));
157
+	}
158
+
159
+	/**
160
+	 *
161
+	 */
162
+	public function testGetInfoWindowTemplate()
163
+	{
164
+		/** @var Locator $object */
165
+		$object = Injector::inst()->create(Locator::class);
166
+		$template = $object->getInfoWindowTemplate();
167
+		// get rid of cache ending
168
+		$template = preg_replace('/\?.*$/', '', $template);
169
+		$this->assertStringEndsWith('client/infowindow-description.html', $template);
170
+	}
171
+
172
+	/**
173
+	 *
174
+	 */
175
+	public function testGetListTemplate()
176
+	{
177
+		/** @var Locator $object */
178
+		$object = Injector::inst()->create(Locator::class);
179
+		$template = $object->getListTemplate();
180
+		// get rid of cache ending
181
+		$template = preg_replace('/\?.*$/', '', $template);
182
+		$this->assertStringEndsWith('client/location-list-description.html', $template);
183
+	}
184 184
 }
Please login to merge, or discard this patch.
tests/TestOnly/Extension/LocationExtension.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -11,11 +11,11 @@
 block discarded – undo
11 11
  */
12 12
 class LocationExtension extends DataExtension implements TestOnly
13 13
 {
14
-    /**
15
-     * @param $url
16
-     */
17
-    public function updateWebsiteURL(&$url)
18
-    {
19
-        $url = 'foo';
20
-    }
14
+	/**
15
+	 * @param $url
16
+	 */
17
+	public function updateWebsiteURL(&$url)
18
+	{
19
+		$url = 'foo';
20
+	}
21 21
 }
Please login to merge, or discard this patch.
src/Page/Locator.php 2 patches
Indentation   +248 added lines, -248 removed lines patch added patch discarded remove patch
@@ -27,252 +27,252 @@
 block discarded – undo
27 27
  */
28 28
 class Locator extends \Page
29 29
 {
30
-    /**
31
-     * @var string
32
-     */
33
-    private static $singular_name = 'Locator';
34
-
35
-    /**
36
-     * @var string
37
-     */
38
-    private static $plural_name = 'Locators';
39
-
40
-    /**
41
-     * @var string
42
-     */
43
-    private static $description = 'Display locations on a map';
44
-
45
-    /**
46
-     * @var array
47
-     */
48
-    private static $db = [
49
-        'Unit' => 'Enum("m,km","m")',
50
-    ];
51
-
52
-    /**
53
-     * @var array
54
-     */
55
-    private static $many_many = [
56
-        'Categories' => LocationCategory::class,
57
-    ];
58
-
59
-    /**
60
-     * @var string
61
-     */
62
-    private static $table_name = 'Locator';
63
-
64
-    /**
65
-     * @var string
66
-     */
67
-    private static $location_class = LocationPage::class;
68
-
69
-    /**
70
-     * @return FieldList
71
-     */
72
-    public function getCMSFields()
73
-    {
74
-        $this->beforeUpdateCMSFields(function ($fields) {
75
-            // Settings
76
-            $fields->addFieldsToTab('Root.Settings', [
77
-                HeaderField::create('DisplayOptions', 'Display Options', 3),
78
-                OptionsetField::create('Unit', 'Unit of measure', ['m' => 'Miles', 'km' => 'Kilometers']),
79
-            ]);
80
-
81
-            // Filter categories
82
-            $config = GridFieldConfig_RelationEditor::create();
83
-            $config->removeComponentsByType(GridFieldAddExistingAutocompleter::class);
84
-            $config->addComponent(new GridFieldAddExistingSearchButton());
85
-            $categories = $this->Categories();
86
-            $categoriesField = GridField::create('Categories', 'Categories', $categories, $config)
87
-                ->setDescription('only show locations from the selected category');
88
-
89
-            // Filter
90
-            $fields->addFieldsToTab('Root.Filter', [
91
-                HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3),
92
-                $categoriesField,
93
-            ]);
94
-        });
95
-
96
-        return parent::getCMSFields();
97
-    }
98
-
99
-    /**
100
-     * @param array $filter
101
-     * @param array $filterAny
102
-     * @param array $exclude
103
-     * @param null|callable $callback
104
-     *
105
-     * @return DataList|ArrayList
106
-     */
107
-    public static function get_locations(
108
-        $filter = [],
109
-        $filterAny = [],
110
-        $exclude = [],
111
-        $callback = null
112
-    )
113
-    {
114
-        $locationClass = Config::inst()->get(static::class, 'location_class');
115
-        $locations = $locationClass::get()->filter($filter)->exclude($exclude);
116
-
117
-        if (!empty($filterAny)) {
118
-            $locations = $locations->filterAny($filterAny);
119
-        }
120
-        if (!empty($exclude)) {
121
-            $locations = $locations->exclude($exclude);
122
-        }
123
-
124
-        if ($callback !== null && is_callable($callback)) {
125
-            $locations->filterByCallback($callback);
126
-        }
127
-
128
-        return $locations;
129
-    }
130
-
131
-    /**
132
-     * @return DataList
133
-     */
134
-    public static function get_all_categories()
135
-    {
136
-        return LocationCategory::get();
137
-    }
138
-
139
-    /**
140
-     * @return bool
141
-     */
142
-    public function getPageCategories()
143
-    {
144
-        return self::locator_categories_by_locator($this->ID);
145
-    }
146
-
147
-    /**
148
-     * @param int $id
149
-     *
150
-     * @return bool|
151
-     */
152
-    public static function locator_categories_by_locator($id = 0)
153
-    {
154
-        if ($id == 0) {
155
-            return false;
156
-        }
157
-
158
-        /** @var Locator $locator */
159
-        if ($locator = static::get()->byID($id)) {
160
-            return $locator->getUsedCategories();
161
-        }
162
-
163
-        return false;
164
-    }
165
-
166
-    /**
167
-     * Gets the list of radii
168
-     *
169
-     * @return ArrayList
170
-     */
171
-    public function getRadii()
172
-    {
173
-        $radii = [
174
-            '0' => '25',
175
-            '1' => '50',
176
-            '2' => '75',
177
-            '3' => '100',
178
-        ];
179
-        $config_radii = $this->config()->get('radii');
180
-        if ($config_radii) {
181
-            $radii = $config_radii;
182
-        }
183
-
184
-        return $radii;
185
-    }
186
-
187
-    public function getRadiiArrayList()
188
-    {
189
-        $list = [];
190
-
191
-        foreach ($this->getRadii() as $radius) {
192
-            $list[] = new ArrayData([
193
-                'Radius' => $radius,
194
-            ]);
195
-        }
196
-
197
-        return new ArrayList($list);
198
-    }
199
-
200
-    /**
201
-     * Gets the limit of locations
202
-     * @return mixed
203
-     */
204
-    public function getLimit()
205
-    {
206
-        return $this->config()->get('limit');
207
-    }
208
-
209
-    /**
210
-     * Gets if the radius drop down should be shown
211
-     * @return mixed
212
-     */
213
-    public function getShowRadius()
214
-    {
215
-        return $this->config()->get('show_radius');
216
-    }
217
-
218
-    /**
219
-     * @return mixed
220
-     */
221
-    public function getUsedCategories()
222
-    {
223
-        return $this->Categories()->filter([
224
-            'LocationSet.ID:GreaterThan' => 0,
225
-        ]);
226
-    }
227
-
228
-    /**
229
-     * Gets the path of the info window template
230
-     *
231
-     * @return string
232
-     */
233
-    public function getInfoWindowTemplate()
234
-    {
235
-        return ModuleResourceLoader::singleton()->resolveURL(
236
-            Config::inst()->get(
237
-                static::class,
238
-                'infoWindowTemplate'
239
-            )
240
-        );
241
-    }
242
-
243
-    /**
244
-     * Gets the path of the list template
245
-     *
246
-     * @return string
247
-     */
248
-    public function getListTemplate()
249
-    {
250
-        return ModuleResourceLoader::singleton()->resolveURL(
251
-            Config::inst()->get(
252
-                static::class,
253
-                'listTemplate'
254
-            )
255
-        );
256
-    }
257
-
258
-    /**
259
-     * @return null|string
260
-     */
261
-    public function getMapStyle()
262
-    {
263
-        return AddressDataExtension::getMapStyleJSON();
264
-    }
265
-
266
-    public function getMapStyleJSONPath()
267
-    {
268
-        return AddressDataExtension::getMapStyleJSONPath();
269
-    }
270
-
271
-    /**
272
-     * @return null|string
273
-     */
274
-    public function getMarkerIcon()
275
-    {
276
-        return AddressDataExtension::getIconImage();
277
-    }
30
+	/**
31
+	 * @var string
32
+	 */
33
+	private static $singular_name = 'Locator';
34
+
35
+	/**
36
+	 * @var string
37
+	 */
38
+	private static $plural_name = 'Locators';
39
+
40
+	/**
41
+	 * @var string
42
+	 */
43
+	private static $description = 'Display locations on a map';
44
+
45
+	/**
46
+	 * @var array
47
+	 */
48
+	private static $db = [
49
+		'Unit' => 'Enum("m,km","m")',
50
+	];
51
+
52
+	/**
53
+	 * @var array
54
+	 */
55
+	private static $many_many = [
56
+		'Categories' => LocationCategory::class,
57
+	];
58
+
59
+	/**
60
+	 * @var string
61
+	 */
62
+	private static $table_name = 'Locator';
63
+
64
+	/**
65
+	 * @var string
66
+	 */
67
+	private static $location_class = LocationPage::class;
68
+
69
+	/**
70
+	 * @return FieldList
71
+	 */
72
+	public function getCMSFields()
73
+	{
74
+		$this->beforeUpdateCMSFields(function ($fields) {
75
+			// Settings
76
+			$fields->addFieldsToTab('Root.Settings', [
77
+				HeaderField::create('DisplayOptions', 'Display Options', 3),
78
+				OptionsetField::create('Unit', 'Unit of measure', ['m' => 'Miles', 'km' => 'Kilometers']),
79
+			]);
80
+
81
+			// Filter categories
82
+			$config = GridFieldConfig_RelationEditor::create();
83
+			$config->removeComponentsByType(GridFieldAddExistingAutocompleter::class);
84
+			$config->addComponent(new GridFieldAddExistingSearchButton());
85
+			$categories = $this->Categories();
86
+			$categoriesField = GridField::create('Categories', 'Categories', $categories, $config)
87
+				->setDescription('only show locations from the selected category');
88
+
89
+			// Filter
90
+			$fields->addFieldsToTab('Root.Filter', [
91
+				HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3),
92
+				$categoriesField,
93
+			]);
94
+		});
95
+
96
+		return parent::getCMSFields();
97
+	}
98
+
99
+	/**
100
+	 * @param array $filter
101
+	 * @param array $filterAny
102
+	 * @param array $exclude
103
+	 * @param null|callable $callback
104
+	 *
105
+	 * @return DataList|ArrayList
106
+	 */
107
+	public static function get_locations(
108
+		$filter = [],
109
+		$filterAny = [],
110
+		$exclude = [],
111
+		$callback = null
112
+	)
113
+	{
114
+		$locationClass = Config::inst()->get(static::class, 'location_class');
115
+		$locations = $locationClass::get()->filter($filter)->exclude($exclude);
116
+
117
+		if (!empty($filterAny)) {
118
+			$locations = $locations->filterAny($filterAny);
119
+		}
120
+		if (!empty($exclude)) {
121
+			$locations = $locations->exclude($exclude);
122
+		}
123
+
124
+		if ($callback !== null && is_callable($callback)) {
125
+			$locations->filterByCallback($callback);
126
+		}
127
+
128
+		return $locations;
129
+	}
130
+
131
+	/**
132
+	 * @return DataList
133
+	 */
134
+	public static function get_all_categories()
135
+	{
136
+		return LocationCategory::get();
137
+	}
138
+
139
+	/**
140
+	 * @return bool
141
+	 */
142
+	public function getPageCategories()
143
+	{
144
+		return self::locator_categories_by_locator($this->ID);
145
+	}
146
+
147
+	/**
148
+	 * @param int $id
149
+	 *
150
+	 * @return bool|
151
+	 */
152
+	public static function locator_categories_by_locator($id = 0)
153
+	{
154
+		if ($id == 0) {
155
+			return false;
156
+		}
157
+
158
+		/** @var Locator $locator */
159
+		if ($locator = static::get()->byID($id)) {
160
+			return $locator->getUsedCategories();
161
+		}
162
+
163
+		return false;
164
+	}
165
+
166
+	/**
167
+	 * Gets the list of radii
168
+	 *
169
+	 * @return ArrayList
170
+	 */
171
+	public function getRadii()
172
+	{
173
+		$radii = [
174
+			'0' => '25',
175
+			'1' => '50',
176
+			'2' => '75',
177
+			'3' => '100',
178
+		];
179
+		$config_radii = $this->config()->get('radii');
180
+		if ($config_radii) {
181
+			$radii = $config_radii;
182
+		}
183
+
184
+		return $radii;
185
+	}
186
+
187
+	public function getRadiiArrayList()
188
+	{
189
+		$list = [];
190
+
191
+		foreach ($this->getRadii() as $radius) {
192
+			$list[] = new ArrayData([
193
+				'Radius' => $radius,
194
+			]);
195
+		}
196
+
197
+		return new ArrayList($list);
198
+	}
199
+
200
+	/**
201
+	 * Gets the limit of locations
202
+	 * @return mixed
203
+	 */
204
+	public function getLimit()
205
+	{
206
+		return $this->config()->get('limit');
207
+	}
208
+
209
+	/**
210
+	 * Gets if the radius drop down should be shown
211
+	 * @return mixed
212
+	 */
213
+	public function getShowRadius()
214
+	{
215
+		return $this->config()->get('show_radius');
216
+	}
217
+
218
+	/**
219
+	 * @return mixed
220
+	 */
221
+	public function getUsedCategories()
222
+	{
223
+		return $this->Categories()->filter([
224
+			'LocationSet.ID:GreaterThan' => 0,
225
+		]);
226
+	}
227
+
228
+	/**
229
+	 * Gets the path of the info window template
230
+	 *
231
+	 * @return string
232
+	 */
233
+	public function getInfoWindowTemplate()
234
+	{
235
+		return ModuleResourceLoader::singleton()->resolveURL(
236
+			Config::inst()->get(
237
+				static::class,
238
+				'infoWindowTemplate'
239
+			)
240
+		);
241
+	}
242
+
243
+	/**
244
+	 * Gets the path of the list template
245
+	 *
246
+	 * @return string
247
+	 */
248
+	public function getListTemplate()
249
+	{
250
+		return ModuleResourceLoader::singleton()->resolveURL(
251
+			Config::inst()->get(
252
+				static::class,
253
+				'listTemplate'
254
+			)
255
+		);
256
+	}
257
+
258
+	/**
259
+	 * @return null|string
260
+	 */
261
+	public function getMapStyle()
262
+	{
263
+		return AddressDataExtension::getMapStyleJSON();
264
+	}
265
+
266
+	public function getMapStyleJSONPath()
267
+	{
268
+		return AddressDataExtension::getMapStyleJSONPath();
269
+	}
270
+
271
+	/**
272
+	 * @return null|string
273
+	 */
274
+	public function getMarkerIcon()
275
+	{
276
+		return AddressDataExtension::getIconImage();
277
+	}
278 278
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -71,7 +71,7 @@
 block discarded – undo
71 71
      */
72 72
     public function getCMSFields()
73 73
     {
74
-        $this->beforeUpdateCMSFields(function ($fields) {
74
+        $this->beforeUpdateCMSFields(function($fields) {
75 75
             // Settings
76 76
             $fields->addFieldsToTab('Root.Settings', [
77 77
                 HeaderField::create('DisplayOptions', 'Display Options', 3),
Please login to merge, or discard this patch.
tests/form/LocatorFormTest.php 1 patch
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -17,62 +17,62 @@
 block discarded – undo
17 17
  */
18 18
 class LocatorFormTest extends FunctionalTest
19 19
 {
20
-    protected static $fixture_file = 'locatorformfixture.yml';
20
+	protected static $fixture_file = 'locatorformfixture.yml';
21 21
 
22
-    /**
23
-     *
24
-     */
25
-    protected function setUp()
26
-    {
27
-        parent::setUp();
22
+	/**
23
+	 *
24
+	 */
25
+	protected function setUp()
26
+	{
27
+		parent::setUp();
28 28
 
29
-        Config::modify()->set(Locator::class, 'location_class', Location::class);
30
-    }
29
+		Config::modify()->set(Locator::class, 'location_class', Location::class);
30
+	}
31 31
 
32
-    /**
33
-     *
34
-     */
35
-    public function testLocatorFormBase()
36
-    {
37
-        $locator = $this->objFromFixture(Locator::class, 'locator1');
38
-        $form = LocatorForm::create(LocatorController::create($locator), 'LocatorForm');
32
+	/**
33
+	 *
34
+	 */
35
+	public function testLocatorFormBase()
36
+	{
37
+		$locator = $this->objFromFixture(Locator::class, 'locator1');
38
+		$form = LocatorForm::create(LocatorController::create($locator), 'LocatorForm');
39 39
 
40
-        $this->assertInstanceOf(FieldList::class, $form->Fields());
41
-        $this->assertInstanceOf(RequiredFields::class, $form->getValidator());
42
-    }
40
+		$this->assertInstanceOf(FieldList::class, $form->Fields());
41
+		$this->assertInstanceOf(RequiredFields::class, $form->getValidator());
42
+	}
43 43
 
44
-    /**
45
-     *
46
-     */
47
-    public function testUpdateRequiredFields()
48
-    {
49
-        $locator = $this->objFromFixture(Locator::class, 'locator1');
50
-        $form = LocatorForm::create(LocatorController::create($locator), 'LocatorForm');
51
-        $validator = $form->getValidator();
44
+	/**
45
+	 *
46
+	 */
47
+	public function testUpdateRequiredFields()
48
+	{
49
+		$locator = $this->objFromFixture(Locator::class, 'locator1');
50
+		$form = LocatorForm::create(LocatorController::create($locator), 'LocatorForm');
51
+		$validator = $form->getValidator();
52 52
 
53
-        $validator->removeRequiredField('Address');
54
-        $validator->addRequiredField('Foo');
53
+		$validator->removeRequiredField('Address');
54
+		$validator->addRequiredField('Foo');
55 55
 
56
-        $this->assertEquals(['Foo'], $form->getValidator()->getRequired());
57
-    }
56
+		$this->assertEquals(['Foo'], $form->getValidator()->getRequired());
57
+	}
58 58
 
59
-    /**
60
-     *
61
-     */
62
-    public function testFields()
63
-    {
64
-        $locator = $this->objFromFixture(Locator::class, 'locator1');
65
-        $form = LocatorForm::create(LocatorController::create($locator), 'LocatorForm');
66
-        $this->assertInstanceOf(FieldList::class, $form->Fields());
67
-    }
59
+	/**
60
+	 *
61
+	 */
62
+	public function testFields()
63
+	{
64
+		$locator = $this->objFromFixture(Locator::class, 'locator1');
65
+		$form = LocatorForm::create(LocatorController::create($locator), 'LocatorForm');
66
+		$this->assertInstanceOf(FieldList::class, $form->Fields());
67
+	}
68 68
 
69
-    /**
70
-     *
71
-     */
72
-    public function testActions()
73
-    {
74
-        $locator = $this->objFromFixture(Locator::class, 'locator1');
75
-        $form = LocatorForm::create(LocatorController::create($locator), 'LocatorForm');
76
-        $this->assertInstanceOf(FieldList::class, $form->Actions());
77
-    }
69
+	/**
70
+	 *
71
+	 */
72
+	public function testActions()
73
+	{
74
+		$locator = $this->objFromFixture(Locator::class, 'locator1');
75
+		$form = LocatorForm::create(LocatorController::create($locator), 'LocatorForm');
76
+		$this->assertInstanceOf(FieldList::class, $form->Actions());
77
+	}
78 78
 }
Please login to merge, or discard this patch.