1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class LocationTest extends SapphireTest |
4
|
|
|
{ |
5
|
|
|
|
6
|
|
|
protected static $fixture_file = 'locator/tests/Locator_Test.yml'; |
7
|
|
|
|
8
|
|
|
public function testGetCoords() |
9
|
|
|
{ |
10
|
|
|
$location = $this->objFromFixture('Location', 'dynamic'); |
11
|
|
|
|
12
|
|
|
$coords = ((int)$location->Lat != 0 && (int)$location->Lng != 0) ? 'true' : 'false'; |
13
|
|
|
|
14
|
|
|
$this->assertEquals($coords, $location->getCoords()); |
|
|
|
|
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public function testFieldLabels() |
18
|
|
|
{ |
19
|
|
|
$location = $this->objFromFixture('Location', 'dynamic'); |
20
|
|
|
$labels = $location->FieldLabels(); |
21
|
|
|
$expected = array( |
22
|
|
|
'Title' => 'Name', |
23
|
|
|
'Featured' => 'Featured', |
24
|
|
|
'Website' => 'Website', |
25
|
|
|
'Phone' => 'Phone', |
26
|
|
|
'Email' => 'Email', |
27
|
|
|
'EmailAddress' => 'Email Address', |
28
|
|
|
'ShowInLocator' => 'Show', |
29
|
|
|
'Address' => 'Address', |
30
|
|
|
'Suburb' => 'City', |
31
|
|
|
'State' => 'State', |
32
|
|
|
'Postcode' => 'Postal Code', |
33
|
|
|
'Country' => 'Country', |
34
|
|
|
'Lat' => 'Lat', |
35
|
|
|
'Lng' => 'Lng', |
36
|
|
|
'Category' => 'Category', |
37
|
|
|
'ShowInLocator.NiceAsBoolean' => 'Show', |
38
|
|
|
'Category.Name' => 'Category', |
39
|
|
|
'Category.ID' => 'Category', |
40
|
|
|
'Featured.NiceAsBoolean' => 'Featured', |
41
|
|
|
'Coords' => 'Coords', |
42
|
|
|
); |
43
|
|
|
$this->assertEquals($expected, $labels); |
|
|
|
|
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testGetCMSFields() |
47
|
|
|
{ |
48
|
|
|
$object = new Location(); |
49
|
|
|
$fieldset = $object->getCMSFields(); |
50
|
|
|
$this->assertTrue(is_a($fieldset, 'FieldList')); |
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testValidate() |
54
|
|
|
{ |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testEmailAddress() |
58
|
|
|
{ |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function testCanView() |
62
|
|
|
{ |
63
|
|
|
$object = $this->objFromFixture('Location', 'dynamic'); |
64
|
|
|
$object->write(); |
65
|
|
|
|
66
|
|
|
$this->assertTrue($object->canView()); |
|
|
|
|
67
|
|
|
|
68
|
|
|
$nullMember = Member::create(); |
69
|
|
|
$nullMember->write(); |
70
|
|
|
|
71
|
|
|
$this->assertTrue($object->canView($nullMember)); |
|
|
|
|
72
|
|
|
|
73
|
|
|
$nullMember->delete(); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function testCanEdit() |
77
|
|
|
{ |
78
|
|
|
$object = $this->objFromFixture('Location', 'dynamic'); |
79
|
|
|
$object->write(); |
80
|
|
|
|
81
|
|
|
$objectID = $object->ID; |
82
|
|
|
|
83
|
|
|
//test permissions per permission setting |
84
|
|
|
$create = $this->objFromFixture('Member', 'locationcreate'); |
85
|
|
|
$edit = $this->objFromFixture('Member', 'locationedit'); |
86
|
|
|
$delete = $this->objFromFixture('Member', 'locationdelete'); |
87
|
|
|
|
88
|
|
|
$originalTitle = $object->Title; |
89
|
|
|
$this->assertEquals($originalTitle, 'Dynamic, Inc.'); |
|
|
|
|
90
|
|
|
|
91
|
|
|
$this->assertTrue($object->canEdit($edit)); |
|
|
|
|
92
|
|
|
$this->assertFalse($object->canEdit($create)); |
|
|
|
|
93
|
|
|
$this->assertFalse($object->canEdit($delete)); |
|
|
|
|
94
|
|
|
|
95
|
|
|
$object->Title = 'Changed Title'; |
96
|
|
|
$object->write(); |
97
|
|
|
|
98
|
|
|
$testEdit = Location::get()->byID($objectID); |
99
|
|
|
$this->assertEquals($testEdit->Title, 'Changed Title'); |
|
|
|
|
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function testCanDelete() |
103
|
|
|
{ |
104
|
|
|
$object = $this->objFromFixture('Location', 'dynamic'); |
105
|
|
|
$object->write(); |
106
|
|
|
|
107
|
|
|
//test permissions per permission setting |
108
|
|
|
$create = $this->objFromFixture('Member', 'locationcreate'); |
109
|
|
|
$edit = $this->objFromFixture('Member', 'locationedit'); |
110
|
|
|
$delete = $this->objFromFixture('Member', 'locationdelete'); |
111
|
|
|
|
112
|
|
|
$this->assertTrue($object->canDelete($delete)); |
|
|
|
|
113
|
|
|
$this->assertFalse($object->canDelete($create)); |
|
|
|
|
114
|
|
|
$this->assertFalse($object->canDelete($edit)); |
|
|
|
|
115
|
|
|
|
116
|
|
|
$checkObject = $object; |
117
|
|
|
$object->delete(); |
118
|
|
|
|
119
|
|
|
$this->assertEquals($checkObject->ID, 0); |
|
|
|
|
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function testCanCreate() |
123
|
|
|
{ |
124
|
|
|
$object = singleton('Location'); |
125
|
|
|
|
126
|
|
|
//test permissions per permission setting |
127
|
|
|
$create = $this->objFromFixture('Member', 'locationcreate'); |
128
|
|
|
$edit = $this->objFromFixture('Member', 'locationedit'); |
129
|
|
|
$delete = $this->objFromFixture('Member', 'locationdelete'); |
130
|
|
|
|
131
|
|
|
$this->assertTrue($object->canCreate($create)); |
|
|
|
|
132
|
|
|
$this->assertFalse($object->canCreate($edit)); |
|
|
|
|
133
|
|
|
$this->assertFalse($object->canCreate($delete)); |
|
|
|
|
134
|
|
|
|
135
|
|
|
$nullMember = Member::create(); |
136
|
|
|
$nullMember->write(); |
137
|
|
|
$this->assertFalse($object->canCreate($nullMember)); |
|
|
|
|
138
|
|
|
|
139
|
|
|
$nullMember->delete(); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function testProvidePermissions() |
143
|
|
|
{ |
144
|
|
|
$object = Location::create(); |
145
|
|
|
$expected = array( |
146
|
|
|
'Location_EDIT' => 'Edit a Location', |
147
|
|
|
'Location_DELETE' => 'Delete a Location', |
148
|
|
|
'Location_CREATE' => 'Create a Location', |
149
|
|
|
); |
150
|
|
|
$this->assertEquals($expected, $object->providePermissions()); |
|
|
|
|
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.