Completed
Push — master ( 882345...5b1789 )
by Nic
14s queued 10s
created
src/objects/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.
tests/Extension/LocationExtension.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -11,12 +11,12 @@
 block discarded – undo
11 11
  */
12 12
 class LocationExtension extends DataExtension implements TestOnly
13 13
 {
14
-    /**
15
-     * @param $url
16
-     * @return string
17
-     */
18
-    public function updateWebsiteURL(&$url)
19
-    {
20
-        $url = 'foo';
21
-    }
14
+	/**
15
+	 * @param $url
16
+	 * @return string
17
+	 */
18
+	public function updateWebsiteURL(&$url)
19
+	{
20
+		$url = 'foo';
21
+	}
22 22
 }
Please login to merge, or discard this patch.
tests/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/objects/LocationTest.php 1 patch
Indentation   +202 added lines, -202 removed lines patch added patch discarded remove patch
@@ -18,206 +18,206 @@
 block discarded – undo
18 18
  */
19 19
 class LocationTest extends SapphireTest
20 20
 {
21
-    /**
22
-     * @var string
23
-     */
24
-    protected static $fixture_file = '../fixtures.yml';
25
-
26
-    /**
27
-     * @var array
28
-     */
29
-    protected static $extra_dataobjects = [
30
-        ExtendedLocation::class,
31
-    ];
32
-
33
-    /**
34
-     * @var array
35
-     */
36
-    protected static $required_extensions = [
37
-        ExtendedLocation::class => [
38
-            LocationExtension::class,
39
-        ],
40
-    ];
41
-
42
-    /**
43
-     *
44
-     */
45
-    public function testGetCoords()
46
-    {
47
-        $location = $this->objFromFixture(Location::class, 'dynamic');
48
-        $coords = ((int)$location->Lat != 0 && (int)$location->Lng != 0) ? 'true' : 'false';
49
-        $this->assertEquals($coords, $location->getCoords());
50
-    }
51
-
52
-    /**
53
-     *
54
-     */
55
-    public function testFieldLabels()
56
-    {
57
-        $this->markTestSkipped();
58
-        // Link and File tracking display as "Tracking" in SS 4.2 & 4.3, "Tracking" in 4.4
59
-        $location = $this->objFromFixture(Location::class, 'dynamic');
60
-        $labels = $location->FieldLabels();
61
-        $expected = [
62
-            'Title' => 'Name',
63
-            'Featured' => 'Featured',
64
-            'Website' => 'Website',
65
-            'Phone' => 'Phone',
66
-            'Email' => 'Email',
67
-            'Fax' => 'Fax',
68
-            'Address' => 'Address',
69
-            'City' => 'City',
70
-            'State' => 'State',
71
-            'PostalCode' => 'Postal Code',
72
-            'Country' => 'Country',
73
-            'Lat' => 'Lat',
74
-            'Lng' => 'Lng',
75
-            'Categories' => 'Categories',
76
-            'Category.Name' => 'Category',
77
-            'Category.ID' => 'Category',
78
-            'Featured.NiceAsBoolean' => 'Featured',
79
-            'Import_ID' => 'Import_ID',
80
-            'Version' => 'Version',
81
-            'Versions' => 'Versions',
82
-            'Address2' => 'Address2',
83
-            'LinkTracking' => 'Link tracking',
84
-            'FileTracking' => 'File tracking',
85
-        ];
86
-        $this->assertEquals($expected, $labels);
87
-    }
88
-
89
-    /**
90
-     *
91
-     */
92
-    public function testGetCMSFields()
93
-    {
94
-        $object = new Location();
95
-        $fieldset = $object->getCMSFields();
96
-        $this->assertinstanceOf(FieldList::class, $fieldset);
97
-    }
98
-
99
-    /**
100
-     *
101
-     */
102
-    public function testCanView()
103
-    {
104
-        $object = $this->objFromFixture(Location::class, 'dynamic');
105
-        $object->write();
106
-
107
-        $this->assertTrue($object->canView());
108
-
109
-        $nullMember = Member::create();
110
-        $nullMember->write();
111
-
112
-        $this->assertTrue($object->canView($nullMember));
113
-
114
-        $nullMember->delete();
115
-    }
116
-
117
-    /**
118
-     *
119
-     */
120
-    public function testCanEdit()
121
-    {
122
-        $object = $this->objFromFixture(Location::class, 'dynamic');
123
-        $object->write();
124
-
125
-        $objectID = $object->ID;
126
-
127
-        //test permissions per permission setting
128
-        $create = $this->objFromFixture(Member::class, 'locationcreate');
129
-        $edit = $this->objFromFixture(Member::class, 'locationedit');
130
-        $delete = $this->objFromFixture(Member::class, 'locationdelete');
131
-
132
-        $originalTitle = $object->Title;
133
-        $this->assertEquals($originalTitle, 'Dynamic, Inc.');
134
-
135
-        $this->assertTrue($object->canEdit($edit));
136
-        $this->assertFalse($object->canEdit($create));
137
-        $this->assertFalse($object->canEdit($delete));
138
-
139
-        $object->Title = 'Changed Title';
140
-        $object->write();
141
-
142
-        $testEdit = Location::get()->byID($objectID);
143
-        $this->assertEquals($testEdit->Title, 'Changed Title');
144
-    }
145
-
146
-    /**
147
-     *
148
-     */
149
-    public function testCanDelete()
150
-    {
151
-        $object = $this->objFromFixture(Location::class, 'dynamic');
152
-        $object->write();
153
-
154
-        //test permissions per permission setting
155
-        $create = $this->objFromFixture(Member::class, 'locationcreate');
156
-        $edit = $this->objFromFixture(Member::class, 'locationedit');
157
-        $delete = $this->objFromFixture(Member::class, 'locationdelete');
158
-
159
-        $this->assertTrue($object->canDelete($delete));
160
-        $this->assertFalse($object->canDelete($create));
161
-        $this->assertFalse($object->canDelete($edit));
162
-
163
-        $checkObject = $object;
164
-        $object->delete();
165
-
166
-        $this->assertEquals($checkObject->ID, 0);
167
-    }
168
-
169
-    /**
170
-     *
171
-     */
172
-    public function testCanCreate()
173
-    {
174
-        $object = singleton(Location::class);
175
-
176
-        //test permissions per permission setting
177
-        $create = $this->objFromFixture(Member::class, 'locationcreate');
178
-        $edit = $this->objFromFixture(Member::class, 'locationedit');
179
-        $delete = $this->objFromFixture(Member::class, 'locationdelete');
180
-
181
-        $this->assertTrue($object->canCreate($create));
182
-        $this->assertFalse($object->canCreate($edit));
183
-        $this->assertFalse($object->canCreate($delete));
184
-
185
-        $nullMember = Member::create();
186
-        $nullMember->write();
187
-        $this->assertFalse($object->canCreate($nullMember));
188
-
189
-        $nullMember->delete();
190
-    }
191
-
192
-    /**
193
-     *
194
-     */
195
-    public function testProvidePermissions()
196
-    {
197
-        $object = Location::create();
198
-        $expected = [
199
-            'Location_EDIT' => 'Edit a Location',
200
-            'Location_DELETE' => 'Delete a Location',
201
-            'Location_CREATE' => 'Create a Location',
202
-        ];
203
-        $this->assertEquals($expected, $object->providePermissions());
204
-    }
205
-
206
-    /**
207
-     *
208
-     */
209
-    public function testUpdateWebsiteURL()
210
-    {
211
-        $location = $this->objFromFixture(Location::class, 'dynamic');
212
-
213
-        // Create unsaved raw duplicate
214
-        $map = $location->toMap();
215
-        unset($map['Created']);
216
-        /** @var static $clone */
217
-        $clone = Injector::inst()->create(ExtendedLocation::class, $map);
218
-        $clone->ID = 0;
219
-
220
-        $this->assertEquals('http://www.dynamicagency.com', $location->getWebsiteURL());
221
-        $this->assertEquals('foo', $clone->getWebsiteURL());
222
-    }
21
+	/**
22
+	 * @var string
23
+	 */
24
+	protected static $fixture_file = '../fixtures.yml';
25
+
26
+	/**
27
+	 * @var array
28
+	 */
29
+	protected static $extra_dataobjects = [
30
+		ExtendedLocation::class,
31
+	];
32
+
33
+	/**
34
+	 * @var array
35
+	 */
36
+	protected static $required_extensions = [
37
+		ExtendedLocation::class => [
38
+			LocationExtension::class,
39
+		],
40
+	];
41
+
42
+	/**
43
+	 *
44
+	 */
45
+	public function testGetCoords()
46
+	{
47
+		$location = $this->objFromFixture(Location::class, 'dynamic');
48
+		$coords = ((int)$location->Lat != 0 && (int)$location->Lng != 0) ? 'true' : 'false';
49
+		$this->assertEquals($coords, $location->getCoords());
50
+	}
51
+
52
+	/**
53
+	 *
54
+	 */
55
+	public function testFieldLabels()
56
+	{
57
+		$this->markTestSkipped();
58
+		// Link and File tracking display as "Tracking" in SS 4.2 & 4.3, "Tracking" in 4.4
59
+		$location = $this->objFromFixture(Location::class, 'dynamic');
60
+		$labels = $location->FieldLabels();
61
+		$expected = [
62
+			'Title' => 'Name',
63
+			'Featured' => 'Featured',
64
+			'Website' => 'Website',
65
+			'Phone' => 'Phone',
66
+			'Email' => 'Email',
67
+			'Fax' => 'Fax',
68
+			'Address' => 'Address',
69
+			'City' => 'City',
70
+			'State' => 'State',
71
+			'PostalCode' => 'Postal Code',
72
+			'Country' => 'Country',
73
+			'Lat' => 'Lat',
74
+			'Lng' => 'Lng',
75
+			'Categories' => 'Categories',
76
+			'Category.Name' => 'Category',
77
+			'Category.ID' => 'Category',
78
+			'Featured.NiceAsBoolean' => 'Featured',
79
+			'Import_ID' => 'Import_ID',
80
+			'Version' => 'Version',
81
+			'Versions' => 'Versions',
82
+			'Address2' => 'Address2',
83
+			'LinkTracking' => 'Link tracking',
84
+			'FileTracking' => 'File tracking',
85
+		];
86
+		$this->assertEquals($expected, $labels);
87
+	}
88
+
89
+	/**
90
+	 *
91
+	 */
92
+	public function testGetCMSFields()
93
+	{
94
+		$object = new Location();
95
+		$fieldset = $object->getCMSFields();
96
+		$this->assertinstanceOf(FieldList::class, $fieldset);
97
+	}
98
+
99
+	/**
100
+	 *
101
+	 */
102
+	public function testCanView()
103
+	{
104
+		$object = $this->objFromFixture(Location::class, 'dynamic');
105
+		$object->write();
106
+
107
+		$this->assertTrue($object->canView());
108
+
109
+		$nullMember = Member::create();
110
+		$nullMember->write();
111
+
112
+		$this->assertTrue($object->canView($nullMember));
113
+
114
+		$nullMember->delete();
115
+	}
116
+
117
+	/**
118
+	 *
119
+	 */
120
+	public function testCanEdit()
121
+	{
122
+		$object = $this->objFromFixture(Location::class, 'dynamic');
123
+		$object->write();
124
+
125
+		$objectID = $object->ID;
126
+
127
+		//test permissions per permission setting
128
+		$create = $this->objFromFixture(Member::class, 'locationcreate');
129
+		$edit = $this->objFromFixture(Member::class, 'locationedit');
130
+		$delete = $this->objFromFixture(Member::class, 'locationdelete');
131
+
132
+		$originalTitle = $object->Title;
133
+		$this->assertEquals($originalTitle, 'Dynamic, Inc.');
134
+
135
+		$this->assertTrue($object->canEdit($edit));
136
+		$this->assertFalse($object->canEdit($create));
137
+		$this->assertFalse($object->canEdit($delete));
138
+
139
+		$object->Title = 'Changed Title';
140
+		$object->write();
141
+
142
+		$testEdit = Location::get()->byID($objectID);
143
+		$this->assertEquals($testEdit->Title, 'Changed Title');
144
+	}
145
+
146
+	/**
147
+	 *
148
+	 */
149
+	public function testCanDelete()
150
+	{
151
+		$object = $this->objFromFixture(Location::class, 'dynamic');
152
+		$object->write();
153
+
154
+		//test permissions per permission setting
155
+		$create = $this->objFromFixture(Member::class, 'locationcreate');
156
+		$edit = $this->objFromFixture(Member::class, 'locationedit');
157
+		$delete = $this->objFromFixture(Member::class, 'locationdelete');
158
+
159
+		$this->assertTrue($object->canDelete($delete));
160
+		$this->assertFalse($object->canDelete($create));
161
+		$this->assertFalse($object->canDelete($edit));
162
+
163
+		$checkObject = $object;
164
+		$object->delete();
165
+
166
+		$this->assertEquals($checkObject->ID, 0);
167
+	}
168
+
169
+	/**
170
+	 *
171
+	 */
172
+	public function testCanCreate()
173
+	{
174
+		$object = singleton(Location::class);
175
+
176
+		//test permissions per permission setting
177
+		$create = $this->objFromFixture(Member::class, 'locationcreate');
178
+		$edit = $this->objFromFixture(Member::class, 'locationedit');
179
+		$delete = $this->objFromFixture(Member::class, 'locationdelete');
180
+
181
+		$this->assertTrue($object->canCreate($create));
182
+		$this->assertFalse($object->canCreate($edit));
183
+		$this->assertFalse($object->canCreate($delete));
184
+
185
+		$nullMember = Member::create();
186
+		$nullMember->write();
187
+		$this->assertFalse($object->canCreate($nullMember));
188
+
189
+		$nullMember->delete();
190
+	}
191
+
192
+	/**
193
+	 *
194
+	 */
195
+	public function testProvidePermissions()
196
+	{
197
+		$object = Location::create();
198
+		$expected = [
199
+			'Location_EDIT' => 'Edit a Location',
200
+			'Location_DELETE' => 'Delete a Location',
201
+			'Location_CREATE' => 'Create a Location',
202
+		];
203
+		$this->assertEquals($expected, $object->providePermissions());
204
+	}
205
+
206
+	/**
207
+	 *
208
+	 */
209
+	public function testUpdateWebsiteURL()
210
+	{
211
+		$location = $this->objFromFixture(Location::class, 'dynamic');
212
+
213
+		// Create unsaved raw duplicate
214
+		$map = $location->toMap();
215
+		unset($map['Created']);
216
+		/** @var static $clone */
217
+		$clone = Injector::inst()->create(ExtendedLocation::class, $map);
218
+		$clone->ID = 0;
219
+
220
+		$this->assertEquals('http://www.dynamicagency.com', $location->getWebsiteURL());
221
+		$this->assertEquals('foo', $clone->getWebsiteURL());
222
+	}
223 223
 }
Please login to merge, or discard this patch.