1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class LocationTest extends Locator_Test |
4
|
|
|
{ |
5
|
|
|
public function testGetCoords() |
6
|
|
|
{ |
7
|
|
|
$location = $this->objFromFixture('Location', 'dynamic'); |
8
|
|
|
|
9
|
|
|
$coords = ((int)$location->Lat != 0 && (int)$location->Lng != 0) ? 'true' : 'false'; |
10
|
|
|
|
11
|
|
|
$this->assertEquals($coords, $location->getCoords()); |
|
|
|
|
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
public function testFieldLabels() |
15
|
|
|
{ |
16
|
|
|
$location = $this->objFromFixture('Location', 'dynamic'); |
17
|
|
|
$labels = $location->FieldLabels(); |
18
|
|
|
$expected = array( |
19
|
|
|
'Title' => 'Name', |
20
|
|
|
'Featured' => 'Featured', |
21
|
|
|
'Website' => 'Website', |
22
|
|
|
'Phone' => 'Phone', |
23
|
|
|
'Email' => 'Email', |
24
|
|
|
'EmailAddress' => 'Email Address', |
25
|
|
|
'ShowInLocator' => 'Show', |
26
|
|
|
'Address' => 'Address', |
27
|
|
|
'Suburb' => 'City', |
28
|
|
|
'State' => 'State', |
29
|
|
|
'Postcode' => 'Postal Code', |
30
|
|
|
'Country' => 'Country', |
31
|
|
|
'Lat' => 'Lat', |
32
|
|
|
'Lng' => 'Lng', |
33
|
|
|
'Category' => 'Category', |
34
|
|
|
'ShowInLocator.NiceAsBoolean' => 'Show', |
35
|
|
|
'Category.Name' => 'Category', |
36
|
|
|
'Category.ID' => 'Category', |
37
|
|
|
'Featured.NiceAsBoolean' => 'Featured', |
38
|
|
|
'Coords' => 'Coords', |
39
|
|
|
); |
40
|
|
|
$this->assertEquals($expected, $labels); |
|
|
|
|
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testGetCMSFields() |
44
|
|
|
{ |
45
|
|
|
$object = new Location(); |
46
|
|
|
$fieldset = $object->getCMSFields(); |
47
|
|
|
$this->assertTrue(is_a($fieldset, 'FieldList')); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testValidate() |
51
|
|
|
{ |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testEmailAddress() |
55
|
|
|
{ |
56
|
|
|
} |
57
|
|
|
|
58
|
|
View Code Duplication |
public function testCanView() |
|
|
|
|
59
|
|
|
{ |
60
|
|
|
$object = $this->objFromFixture('Location', 'dynamic'); |
61
|
|
|
$object->write(); |
62
|
|
|
$this->logInWithPermission('ADMIN'); |
63
|
|
|
$this->assertTrue($object->canView()); |
|
|
|
|
64
|
|
|
$this->logOut(); |
65
|
|
|
$nullMember = Member::create(); |
66
|
|
|
$nullMember->write(); |
67
|
|
|
$this->assertTrue($object->canView($nullMember)); |
|
|
|
|
68
|
|
|
$nullMember->delete(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function testCanEdit() |
72
|
|
|
{ |
73
|
|
|
$object = $this->objFromFixture('Location', 'dynamic'); |
74
|
|
|
$object->write(); |
75
|
|
|
$objectID = $object->ID; |
76
|
|
|
$this->logInWithPermission('Location_EDIT'); |
77
|
|
|
$originalTitle = $object->Title; |
78
|
|
|
$this->assertEquals($originalTitle, 'Dynamic, Inc.'); |
|
|
|
|
79
|
|
|
$this->assertTrue($object->canEdit()); |
|
|
|
|
80
|
|
|
$object->Title = 'Changed Title'; |
81
|
|
|
$object->write(); |
82
|
|
|
$testEdit = Location::get()->byID($objectID); |
83
|
|
|
$this->assertEquals($testEdit->Title, 'Changed Title'); |
|
|
|
|
84
|
|
|
$this->logOut(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function testCanDelete() |
88
|
|
|
{ |
89
|
|
|
$object = $this->objFromFixture('Location', 'dynamic'); |
90
|
|
|
$object->write(); |
91
|
|
|
$this->logInWithPermission('Location_DELETE'); |
92
|
|
|
$this->assertTrue($object->canDelete()); |
|
|
|
|
93
|
|
|
$checkObject = $object; |
94
|
|
|
$object->delete(); |
95
|
|
|
$this->assertEquals($checkObject->ID, 0); |
|
|
|
|
96
|
|
|
} |
97
|
|
|
|
98
|
|
View Code Duplication |
public function testCanCreate() |
|
|
|
|
99
|
|
|
{ |
100
|
|
|
$object = singleton('Location'); |
101
|
|
|
$this->logInWithPermission('Location_CREATE'); |
102
|
|
|
$this->assertTrue($object->canCreate()); |
|
|
|
|
103
|
|
|
$this->logOut(); |
104
|
|
|
$nullMember = Member::create(); |
105
|
|
|
$nullMember->write(); |
106
|
|
|
$this->assertFalse($object->canCreate($nullMember)); |
|
|
|
|
107
|
|
|
$nullMember->delete(); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function testProvidePermissions() |
111
|
|
|
{ |
112
|
|
|
$object = Location::create(); |
113
|
|
|
$expected = array( |
114
|
|
|
'Location_EDIT' => 'Edit a Location', |
115
|
|
|
'Location_DELETE' => 'Delete a Location', |
116
|
|
|
'Location_CREATE' => 'Create a Location', |
117
|
|
|
); |
118
|
|
|
$this->assertEquals($expected, $object->providePermissions()); |
|
|
|
|
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
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.