Completed
Pull Request — master (#122)
by Jason
02:51
created
code/objects/Location.php 1 patch
Indentation   +214 added lines, -214 removed lines patch added patch discarded remove patch
@@ -17,245 +17,245 @@
 block discarded – undo
17 17
 class Location extends DataObject implements PermissionProvider
18 18
 {
19 19
 
20
-    /**
21
-     * @var array
22
-     */
23
-    private static $db = array(
24
-        'Title' => 'Varchar(255)',
25
-        'Featured' => 'Boolean',
26
-        'Website' => 'Varchar(255)',
27
-        'Phone' => 'Varchar(40)',
28
-        'Email' => 'Varchar(255)',
29
-        'EmailAddress' => 'Varchar(255)',
30
-        'ShowInLocator' => 'Boolean',
31
-        'Import_ID' => 'Int',
32
-    );
20
+	/**
21
+	 * @var array
22
+	 */
23
+	private static $db = array(
24
+		'Title' => 'Varchar(255)',
25
+		'Featured' => 'Boolean',
26
+		'Website' => 'Varchar(255)',
27
+		'Phone' => 'Varchar(40)',
28
+		'Email' => 'Varchar(255)',
29
+		'EmailAddress' => 'Varchar(255)',
30
+		'ShowInLocator' => 'Boolean',
31
+		'Import_ID' => 'Int',
32
+	);
33 33
 
34
-    /**
35
-     * @var array
36
-     */
37
-    private static $has_one = array(
38
-        'Category' => 'LocationCategory',
39
-    );
34
+	/**
35
+	 * @var array
36
+	 */
37
+	private static $has_one = array(
38
+		'Category' => 'LocationCategory',
39
+	);
40 40
 
41
-    /**
42
-     * @var array
43
-     */
44
-    private static $casting = array(
45
-        'distance' => 'Int',
46
-    );
41
+	/**
42
+	 * @var array
43
+	 */
44
+	private static $casting = array(
45
+		'distance' => 'Int',
46
+	);
47 47
 
48
-    /**
49
-     * @var string
50
-     */
51
-    private static $default_sort = 'Title';
48
+	/**
49
+	 * @var string
50
+	 */
51
+	private static $default_sort = 'Title';
52 52
 
53
-    /**
54
-     * @var array
55
-     */
56
-    private static $defaults = array(
57
-        'ShowInLocator' => true,
58
-    );
53
+	/**
54
+	 * @var array
55
+	 */
56
+	private static $defaults = array(
57
+		'ShowInLocator' => true,
58
+	);
59 59
 
60
-    /**
61
-     * @var string
62
-     */
63
-    private static $singular_name = 'Location';
64
-    /**
65
-     * @var string
66
-     */
67
-    private static $plural_name = 'Locations';
60
+	/**
61
+	 * @var string
62
+	 */
63
+	private static $singular_name = 'Location';
64
+	/**
65
+	 * @var string
66
+	 */
67
+	private static $plural_name = 'Locations';
68 68
 
69
-    /**
70
-     * api access via Restful Server module
71
-     *
72
-     * @var bool
73
-     */
74
-    private static $api_access = true;
69
+	/**
70
+	 * api access via Restful Server module
71
+	 *
72
+	 * @var bool
73
+	 */
74
+	private static $api_access = true;
75 75
 
76
-    /**
77
-     * search fields for Model Admin
78
-     *
79
-     * @var array
80
-     */
81
-    private static $searchable_fields = array(
82
-        'Title',
83
-        'Address',
84
-        'Suburb',
85
-        'State',
86
-        'Postcode',
87
-        'Country',
88
-        'Website',
89
-        'Phone',
90
-        'Email',
91
-        'Category.ID',
92
-        'ShowInLocator',
93
-        'Featured',
94
-    );
76
+	/**
77
+	 * search fields for Model Admin
78
+	 *
79
+	 * @var array
80
+	 */
81
+	private static $searchable_fields = array(
82
+		'Title',
83
+		'Address',
84
+		'Suburb',
85
+		'State',
86
+		'Postcode',
87
+		'Country',
88
+		'Website',
89
+		'Phone',
90
+		'Email',
91
+		'Category.ID',
92
+		'ShowInLocator',
93
+		'Featured',
94
+	);
95 95
 
96
-    /**
97
-     * columns for grid field
98
-     *
99
-     * @var array
100
-     */
101
-    private static $summary_fields = array(
102
-        'Title',
103
-        'Address',
104
-        'Suburb',
105
-        'State',
106
-        'Postcode',
107
-        'Country',
108
-        'Category.Name',
109
-        'ShowInLocator.NiceAsBoolean',
110
-        'Featured.NiceAsBoolean',
111
-        'Coords',
112
-    );
96
+	/**
97
+	 * columns for grid field
98
+	 *
99
+	 * @var array
100
+	 */
101
+	private static $summary_fields = array(
102
+		'Title',
103
+		'Address',
104
+		'Suburb',
105
+		'State',
106
+		'Postcode',
107
+		'Country',
108
+		'Category.Name',
109
+		'ShowInLocator.NiceAsBoolean',
110
+		'Featured.NiceAsBoolean',
111
+		'Coords',
112
+	);
113 113
 
114
-    /**
115
-     * Coords status for $summary_fields
116
-     *
117
-     * @return string
118
-     */
119
-    public function getCoords()
120
-    {
121
-        return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false';
122
-    }
114
+	/**
115
+	 * Coords status for $summary_fields
116
+	 *
117
+	 * @return string
118
+	 */
119
+	public function getCoords()
120
+	{
121
+		return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false';
122
+	}
123 123
 
124
-    /**
125
-     * custom labels for fields
126
-     *
127
-     * @param bool $includerelations
128
-     * @return array|string
129
-     */
130
-    public function fieldLabels($includerelations = true)
131
-    {
132
-        $labels = parent::fieldLabels($includerelations);
124
+	/**
125
+	 * custom labels for fields
126
+	 *
127
+	 * @param bool $includerelations
128
+	 * @return array|string
129
+	 */
130
+	public function fieldLabels($includerelations = true)
131
+	{
132
+		$labels = parent::fieldLabels($includerelations);
133 133
 
134
-        $labels['Title'] = 'Name';
135
-        $labels['Suburb'] = 'City';
136
-        $labels['Postcode'] = 'Postal Code';
137
-        $labels['ShowInLocator'] = 'Show';
138
-        $labels['ShowInLocator.NiceAsBoolean'] = 'Show';
139
-        $labels['Category.Name'] = 'Category';
140
-        $labels['Category.ID'] = 'Category';
141
-        $labels['Email'] = 'Email';
142
-        $labels['Featured.NiceAsBoolean'] = 'Featured';
143
-        $labels['Coords'] = 'Coords';
134
+		$labels['Title'] = 'Name';
135
+		$labels['Suburb'] = 'City';
136
+		$labels['Postcode'] = 'Postal Code';
137
+		$labels['ShowInLocator'] = 'Show';
138
+		$labels['ShowInLocator.NiceAsBoolean'] = 'Show';
139
+		$labels['Category.Name'] = 'Category';
140
+		$labels['Category.ID'] = 'Category';
141
+		$labels['Email'] = 'Email';
142
+		$labels['Featured.NiceAsBoolean'] = 'Featured';
143
+		$labels['Coords'] = 'Coords';
144 144
 
145
-        return $labels;
146
-    }
145
+		return $labels;
146
+	}
147 147
 
148
-    /**
149
-     * @return FieldList
150
-     */
151
-    public function getCMSFields()
152
-    {
153
-        $fields = FieldList::create(
154
-            new TabSet(
155
-                $name = 'Root',
156
-                new Tab(
157
-                    $title = 'Main',
158
-                    HeaderField::create('ContactHD', 'Contact Information'),
159
-                    TextField::create('Title', 'Name'),
160
-                    TextField::create('Phone'),
161
-                    EmailField::create('Email', 'Email'),
162
-                    TextField::create('Website')
163
-                        ->setAttribute('placeholder', 'http://'),
164
-                    DropdownField::create('CategoryID', 'Category', LocationCategory::get()->map('ID', 'Title'))
165
-                        ->setEmptyString('-- select --'),
166
-                    CheckboxField::create('ShowInLocator', 'Show in results')
167
-                        ->setDescription('Location will be included in results list'),
168
-                    CheckboxField::create('Featured')
169
-                        ->setDescription('Location will show at/near the top of the results list')
170
-                )
171
-            )
172
-        );
148
+	/**
149
+	 * @return FieldList
150
+	 */
151
+	public function getCMSFields()
152
+	{
153
+		$fields = FieldList::create(
154
+			new TabSet(
155
+				$name = 'Root',
156
+				new Tab(
157
+					$title = 'Main',
158
+					HeaderField::create('ContactHD', 'Contact Information'),
159
+					TextField::create('Title', 'Name'),
160
+					TextField::create('Phone'),
161
+					EmailField::create('Email', 'Email'),
162
+					TextField::create('Website')
163
+						->setAttribute('placeholder', 'http://'),
164
+					DropdownField::create('CategoryID', 'Category', LocationCategory::get()->map('ID', 'Title'))
165
+						->setEmptyString('-- select --'),
166
+					CheckboxField::create('ShowInLocator', 'Show in results')
167
+						->setDescription('Location will be included in results list'),
168
+					CheckboxField::create('Featured')
169
+						->setDescription('Location will show at/near the top of the results list')
170
+				)
171
+			)
172
+		);
173 173
 
174
-        // allow to be extended via DataExtension
175
-        $this->extend('updateCMSFields', $fields);
174
+		// allow to be extended via DataExtension
175
+		$this->extend('updateCMSFields', $fields);
176 176
 
177
-        // override Suburb field name
178
-        $fields->dataFieldByName('Suburb')->setTitle('City');
177
+		// override Suburb field name
178
+		$fields->dataFieldByName('Suburb')->setTitle('City');
179 179
 
180
-        $fields->removeByName(array(
181
-            'Import_ID',
182
-        ));
180
+		$fields->removeByName(array(
181
+			'Import_ID',
182
+		));
183 183
 
184
-        return $fields;
185
-    }
184
+		return $fields;
185
+	}
186 186
 
187
-    /**
188
-     * @return ValidationResult
189
-     */
190
-    public function validate()
191
-    {
192
-        $result = parent::validate();
187
+	/**
188
+	 * @return ValidationResult
189
+	 */
190
+	public function validate()
191
+	{
192
+		$result = parent::validate();
193 193
 
194
-        return $result;
195
-    }
194
+		return $result;
195
+	}
196 196
 
197
-    /**
198
-     * @return bool|string
199
-     */
200
-    public function EmailAddress()
201
-    {
202
-        Deprecation::notice('3.0', 'Use "$Email" instead.');
203
-        if ($this->Email) {
204
-            return $this->Email;
205
-        } elseif ($this->EmailAddress) {
206
-            return $this->EmailAddress;
207
-        }
197
+	/**
198
+	 * @return bool|string
199
+	 */
200
+	public function EmailAddress()
201
+	{
202
+		Deprecation::notice('3.0', 'Use "$Email" instead.');
203
+		if ($this->Email) {
204
+			return $this->Email;
205
+		} elseif ($this->EmailAddress) {
206
+			return $this->EmailAddress;
207
+		}
208 208
 
209
-        return false;
210
-    }
209
+		return false;
210
+	}
211 211
 
212
-    /**
213
-     * @param null|Member $member
214
-     *
215
-     * @return bool
216
-     */
217
-    public function canView($member = null)
218
-    {
219
-        return true;
220
-    }
212
+	/**
213
+	 * @param null|Member $member
214
+	 *
215
+	 * @return bool
216
+	 */
217
+	public function canView($member = null)
218
+	{
219
+		return true;
220
+	}
221 221
 
222
-    /**
223
-     * @param null|Member $member
224
-     * @return bool|int
225
-     */
226
-    public function canEdit($member = null)
227
-    {
228
-        return Permission::check('Location_EDIT', 'any', $member);
229
-    }
222
+	/**
223
+	 * @param null|Member $member
224
+	 * @return bool|int
225
+	 */
226
+	public function canEdit($member = null)
227
+	{
228
+		return Permission::check('Location_EDIT', 'any', $member);
229
+	}
230 230
 
231
-    /**
232
-     * @param null|Member $member
233
-     * @return bool|int
234
-     */
235
-    public function canDelete($member = null)
236
-    {
237
-        return Permission::check('Location_DELETE', 'any', $member);
238
-    }
231
+	/**
232
+	 * @param null|Member $member
233
+	 * @return bool|int
234
+	 */
235
+	public function canDelete($member = null)
236
+	{
237
+		return Permission::check('Location_DELETE', 'any', $member);
238
+	}
239 239
 
240
-    /**
241
-     * @param null|Member $member
242
-     * @return bool|int
243
-     */
244
-    public function canCreate($member = null)
245
-    {
246
-        return Permission::check('Location_CREATE', 'any', $member);
247
-    }
240
+	/**
241
+	 * @param null|Member $member
242
+	 * @return bool|int
243
+	 */
244
+	public function canCreate($member = null)
245
+	{
246
+		return Permission::check('Location_CREATE', 'any', $member);
247
+	}
248 248
 
249
-    /**
250
-     * @return array
251
-     */
252
-    public function providePermissions()
253
-    {
254
-        return array(
255
-            'Location_EDIT' => 'Edit a Location',
256
-            'Location_DELETE' => 'Delete a Location',
257
-            'Location_CREATE' => 'Create a Location',
258
-        );
259
-    }
249
+	/**
250
+	 * @return array
251
+	 */
252
+	public function providePermissions()
253
+	{
254
+		return array(
255
+			'Location_EDIT' => 'Edit a Location',
256
+			'Location_DELETE' => 'Delete a Location',
257
+			'Location_CREATE' => 'Create a Location',
258
+		);
259
+	}
260 260
 
261 261
 }
Please login to merge, or discard this patch.
code/bulkloader/LocationCsvBulkLoader.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -6,51 +6,51 @@
 block discarded – undo
6 6
 class LocationCsvBulkLoader extends CsvBulkLoader
7 7
 {
8 8
 
9
-    /**
10
-     * @var array
11
-     */
12
-    public $columnMap = array(
13
-        'Name' => 'Title',
14
-        'City' => 'Suburb',
15
-        'EmailAddress' => 'Email',
16
-        'Category' => 'Category.Name',
17
-        'Import_ID' => 'Import_ID',
18
-    );
9
+	/**
10
+	 * @var array
11
+	 */
12
+	public $columnMap = array(
13
+		'Name' => 'Title',
14
+		'City' => 'Suburb',
15
+		'EmailAddress' => 'Email',
16
+		'Category' => 'Category.Name',
17
+		'Import_ID' => 'Import_ID',
18
+	);
19 19
 
20
-    /**
21
-     * @var array
22
-     */
23
-    public $duplicateChecks = array(
24
-        'Import_ID' => 'Import_ID'
25
-    );
20
+	/**
21
+	 * @var array
22
+	 */
23
+	public $duplicateChecks = array(
24
+		'Import_ID' => 'Import_ID'
25
+	);
26 26
 
27
-    /**
28
-     * @var array
29
-     */
30
-    public $relationCallbacks = array(
31
-       'Category.Name' => array(
32
-           'relationname' => 'Category',
33
-           'callback' => 'getCategoryByName',
34
-        ),
35
-    );
27
+	/**
28
+	 * @var array
29
+	 */
30
+	public $relationCallbacks = array(
31
+	   'Category.Name' => array(
32
+		   'relationname' => 'Category',
33
+		   'callback' => 'getCategoryByName',
34
+		),
35
+	);
36 36
 
37
-    /**
38
-     * @param $obj
39
-     * @param $val
40
-     * @param $record
41
-     * @return DataObject|static
42
-     */
43
-    public static function getCategoryByName(&$obj, $val, $record)
44
-    {
45
-        $val = Convert::raw2sql($val);
46
-        $category = LocationCategory::get()->filter(array('Name' => $val))->First();
47
-        if (!$category) {
48
-            $category = LocationCategory::create();
49
-            $category->Name = $val;
50
-            $category->write();
51
-        }
37
+	/**
38
+	 * @param $obj
39
+	 * @param $val
40
+	 * @param $record
41
+	 * @return DataObject|static
42
+	 */
43
+	public static function getCategoryByName(&$obj, $val, $record)
44
+	{
45
+		$val = Convert::raw2sql($val);
46
+		$category = LocationCategory::get()->filter(array('Name' => $val))->First();
47
+		if (!$category) {
48
+			$category = LocationCategory::create();
49
+			$category->Name = $val;
50
+			$category->write();
51
+		}
52 52
 
53
-        return $category;
54
-    }
53
+		return $category;
54
+	}
55 55
 
56 56
 }
Please login to merge, or discard this patch.
tests/LocationTest.php 1 patch
Indentation   +180 added lines, -180 removed lines patch added patch discarded remove patch
@@ -6,184 +6,184 @@
 block discarded – undo
6 6
 class LocationTest extends SapphireTest
7 7
 {
8 8
 
9
-    /**
10
-     * @var string
11
-     */
12
-    protected static $fixture_file = 'locator/tests/Locator_Test.yml';
13
-
14
-    /**
15
-     *
16
-     */
17
-    public function testGetCoords()
18
-    {
19
-        $location = $this->objFromFixture('Location', 'dynamic');
20
-
21
-        $coords = ((int)$location->Lat != 0 && (int)$location->Lng != 0) ? 'true' : 'false';
22
-
23
-        $this->assertEquals($coords, $location->getCoords());
24
-    }
25
-
26
-    /**
27
-     *
28
-     */
29
-    public function testFieldLabels()
30
-    {
31
-        $location = $this->objFromFixture('Location', 'dynamic');
32
-        $labels = $location->FieldLabels();
33
-        $expected = array(
34
-            'Title' => 'Name',
35
-            'Featured' => 'Featured',
36
-            'Website' => 'Website',
37
-            'Phone' => 'Phone',
38
-            'Email' => 'Email',
39
-            'EmailAddress' => 'Email Address',
40
-            'ShowInLocator' => 'Show',
41
-            'Address' => 'Address',
42
-            'Suburb' => 'City',
43
-            'State' => 'State',
44
-            'Postcode' => 'Postal Code',
45
-            'Country' => 'Country',
46
-            'Lat' => 'Lat',
47
-            'Lng' => 'Lng',
48
-            'Category' => 'Category',
49
-            'ShowInLocator.NiceAsBoolean' => 'Show',
50
-            'Category.Name' => 'Category',
51
-            'Category.ID' => 'Category',
52
-            'Featured.NiceAsBoolean' => 'Featured',
53
-            'Coords' => 'Coords',
54
-            'Import_ID' => 'Import_ID',
55
-        );
56
-        $this->assertEquals($expected, $labels);
57
-    }
58
-
59
-    /**
60
-     *
61
-     */
62
-    public function testGetCMSFields()
63
-    {
64
-        $object = new Location();
65
-        $fieldset = $object->getCMSFields();
66
-        $this->assertTrue(is_a($fieldset, 'FieldList'));
67
-    }
68
-
69
-    /**
70
-     *
71
-     */
72
-    public function testValidate()
73
-    {
74
-    }
75
-
76
-    /**
77
-     *
78
-     */
79
-    public function testEmailAddress()
80
-    {
81
-    }
82
-
83
-    /**
84
-     *
85
-     */
86
-    public function testCanView()
87
-    {
88
-        $object = $this->objFromFixture('Location', 'dynamic');
89
-        $object->write();
90
-
91
-        $this->assertTrue($object->canView());
92
-
93
-        $nullMember = Member::create();
94
-        $nullMember->write();
95
-
96
-        $this->assertTrue($object->canView($nullMember));
97
-
98
-        $nullMember->delete();
99
-    }
100
-
101
-    /**
102
-     *
103
-     */
104
-    public function testCanEdit()
105
-    {
106
-        $object = $this->objFromFixture('Location', 'dynamic');
107
-        $object->write();
108
-
109
-        $objectID = $object->ID;
110
-
111
-        //test permissions per permission setting
112
-        $create = $this->objFromFixture('Member', 'locationcreate');
113
-        $edit = $this->objFromFixture('Member', 'locationedit');
114
-        $delete = $this->objFromFixture('Member', 'locationdelete');
115
-
116
-        $originalTitle = $object->Title;
117
-        $this->assertEquals($originalTitle, 'Dynamic, Inc.');
118
-
119
-        $this->assertTrue($object->canEdit($edit));
120
-        $this->assertFalse($object->canEdit($create));
121
-        $this->assertFalse($object->canEdit($delete));
122
-
123
-        $object->Title = 'Changed Title';
124
-        $object->write();
125
-
126
-        $testEdit = Location::get()->byID($objectID);
127
-        $this->assertEquals($testEdit->Title, 'Changed Title');
128
-    }
129
-
130
-    /**
131
-     *
132
-     */
133
-    public function testCanDelete()
134
-    {
135
-        $object = $this->objFromFixture('Location', 'dynamic');
136
-        $object->write();
137
-
138
-        //test permissions per permission setting
139
-        $create = $this->objFromFixture('Member', 'locationcreate');
140
-        $edit = $this->objFromFixture('Member', 'locationedit');
141
-        $delete = $this->objFromFixture('Member', 'locationdelete');
142
-
143
-        $this->assertTrue($object->canDelete($delete));
144
-        $this->assertFalse($object->canDelete($create));
145
-        $this->assertFalse($object->canDelete($edit));
146
-
147
-        $checkObject = $object;
148
-        $object->delete();
149
-
150
-        $this->assertEquals($checkObject->ID, 0);
151
-    }
152
-
153
-    /**
154
-     *
155
-     */
156
-    public function testCanCreate()
157
-    {
158
-        $object = singleton('Location');
159
-
160
-        //test permissions per permission setting
161
-        $create = $this->objFromFixture('Member', 'locationcreate');
162
-        $edit = $this->objFromFixture('Member', 'locationedit');
163
-        $delete = $this->objFromFixture('Member', 'locationdelete');
164
-
165
-        $this->assertTrue($object->canCreate($create));
166
-        $this->assertFalse($object->canCreate($edit));
167
-        $this->assertFalse($object->canCreate($delete));
168
-
169
-        $nullMember = Member::create();
170
-        $nullMember->write();
171
-        $this->assertFalse($object->canCreate($nullMember));
172
-
173
-        $nullMember->delete();
174
-    }
175
-
176
-    /**
177
-     *
178
-     */
179
-    public function testProvidePermissions()
180
-    {
181
-        $object = Location::create();
182
-        $expected = array(
183
-            'Location_EDIT' => 'Edit a Location',
184
-            'Location_DELETE' => 'Delete a Location',
185
-            'Location_CREATE' => 'Create a Location',
186
-        );
187
-        $this->assertEquals($expected, $object->providePermissions());
188
-    }
9
+	/**
10
+	 * @var string
11
+	 */
12
+	protected static $fixture_file = 'locator/tests/Locator_Test.yml';
13
+
14
+	/**
15
+	 *
16
+	 */
17
+	public function testGetCoords()
18
+	{
19
+		$location = $this->objFromFixture('Location', 'dynamic');
20
+
21
+		$coords = ((int)$location->Lat != 0 && (int)$location->Lng != 0) ? 'true' : 'false';
22
+
23
+		$this->assertEquals($coords, $location->getCoords());
24
+	}
25
+
26
+	/**
27
+	 *
28
+	 */
29
+	public function testFieldLabels()
30
+	{
31
+		$location = $this->objFromFixture('Location', 'dynamic');
32
+		$labels = $location->FieldLabels();
33
+		$expected = array(
34
+			'Title' => 'Name',
35
+			'Featured' => 'Featured',
36
+			'Website' => 'Website',
37
+			'Phone' => 'Phone',
38
+			'Email' => 'Email',
39
+			'EmailAddress' => 'Email Address',
40
+			'ShowInLocator' => 'Show',
41
+			'Address' => 'Address',
42
+			'Suburb' => 'City',
43
+			'State' => 'State',
44
+			'Postcode' => 'Postal Code',
45
+			'Country' => 'Country',
46
+			'Lat' => 'Lat',
47
+			'Lng' => 'Lng',
48
+			'Category' => 'Category',
49
+			'ShowInLocator.NiceAsBoolean' => 'Show',
50
+			'Category.Name' => 'Category',
51
+			'Category.ID' => 'Category',
52
+			'Featured.NiceAsBoolean' => 'Featured',
53
+			'Coords' => 'Coords',
54
+			'Import_ID' => 'Import_ID',
55
+		);
56
+		$this->assertEquals($expected, $labels);
57
+	}
58
+
59
+	/**
60
+	 *
61
+	 */
62
+	public function testGetCMSFields()
63
+	{
64
+		$object = new Location();
65
+		$fieldset = $object->getCMSFields();
66
+		$this->assertTrue(is_a($fieldset, 'FieldList'));
67
+	}
68
+
69
+	/**
70
+	 *
71
+	 */
72
+	public function testValidate()
73
+	{
74
+	}
75
+
76
+	/**
77
+	 *
78
+	 */
79
+	public function testEmailAddress()
80
+	{
81
+	}
82
+
83
+	/**
84
+	 *
85
+	 */
86
+	public function testCanView()
87
+	{
88
+		$object = $this->objFromFixture('Location', 'dynamic');
89
+		$object->write();
90
+
91
+		$this->assertTrue($object->canView());
92
+
93
+		$nullMember = Member::create();
94
+		$nullMember->write();
95
+
96
+		$this->assertTrue($object->canView($nullMember));
97
+
98
+		$nullMember->delete();
99
+	}
100
+
101
+	/**
102
+	 *
103
+	 */
104
+	public function testCanEdit()
105
+	{
106
+		$object = $this->objFromFixture('Location', 'dynamic');
107
+		$object->write();
108
+
109
+		$objectID = $object->ID;
110
+
111
+		//test permissions per permission setting
112
+		$create = $this->objFromFixture('Member', 'locationcreate');
113
+		$edit = $this->objFromFixture('Member', 'locationedit');
114
+		$delete = $this->objFromFixture('Member', 'locationdelete');
115
+
116
+		$originalTitle = $object->Title;
117
+		$this->assertEquals($originalTitle, 'Dynamic, Inc.');
118
+
119
+		$this->assertTrue($object->canEdit($edit));
120
+		$this->assertFalse($object->canEdit($create));
121
+		$this->assertFalse($object->canEdit($delete));
122
+
123
+		$object->Title = 'Changed Title';
124
+		$object->write();
125
+
126
+		$testEdit = Location::get()->byID($objectID);
127
+		$this->assertEquals($testEdit->Title, 'Changed Title');
128
+	}
129
+
130
+	/**
131
+	 *
132
+	 */
133
+	public function testCanDelete()
134
+	{
135
+		$object = $this->objFromFixture('Location', 'dynamic');
136
+		$object->write();
137
+
138
+		//test permissions per permission setting
139
+		$create = $this->objFromFixture('Member', 'locationcreate');
140
+		$edit = $this->objFromFixture('Member', 'locationedit');
141
+		$delete = $this->objFromFixture('Member', 'locationdelete');
142
+
143
+		$this->assertTrue($object->canDelete($delete));
144
+		$this->assertFalse($object->canDelete($create));
145
+		$this->assertFalse($object->canDelete($edit));
146
+
147
+		$checkObject = $object;
148
+		$object->delete();
149
+
150
+		$this->assertEquals($checkObject->ID, 0);
151
+	}
152
+
153
+	/**
154
+	 *
155
+	 */
156
+	public function testCanCreate()
157
+	{
158
+		$object = singleton('Location');
159
+
160
+		//test permissions per permission setting
161
+		$create = $this->objFromFixture('Member', 'locationcreate');
162
+		$edit = $this->objFromFixture('Member', 'locationedit');
163
+		$delete = $this->objFromFixture('Member', 'locationdelete');
164
+
165
+		$this->assertTrue($object->canCreate($create));
166
+		$this->assertFalse($object->canCreate($edit));
167
+		$this->assertFalse($object->canCreate($delete));
168
+
169
+		$nullMember = Member::create();
170
+		$nullMember->write();
171
+		$this->assertFalse($object->canCreate($nullMember));
172
+
173
+		$nullMember->delete();
174
+	}
175
+
176
+	/**
177
+	 *
178
+	 */
179
+	public function testProvidePermissions()
180
+	{
181
+		$object = Location::create();
182
+		$expected = array(
183
+			'Location_EDIT' => 'Edit a Location',
184
+			'Location_DELETE' => 'Delete a Location',
185
+			'Location_CREATE' => 'Create a Location',
186
+		);
187
+		$this->assertEquals($expected, $object->providePermissions());
188
+	}
189 189
 }
Please login to merge, or discard this patch.