Completed
Pull Request — master (#88)
by Nic
04:59
created

LocationTest::testProvidePermissions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
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());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<LocationTest>.

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.

Loading history...
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);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<LocationTest>.

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.

Loading history...
41
    }
42
43
    public function testGetCMSFields()
44
    {
45
        $object = new Location();
46
        $fieldset = $object->getCMSFields();
47
        $this->assertTrue(is_a($fieldset, 'FieldList'));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<LocationTest>.

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.

Loading history...
48
    }
49
50
    public function testValidate()
51
    {
52
    }
53
54
    public function testEmailAddress()
55
    {
56
    }
57
58 View Code Duplication
    public function testCanView()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
59
    {
60
        $object = $this->objFromFixture('Location', 'dynamic');
61
        $object->write();
62
        $this->logInWithPermission('ADMIN');
63
        $this->assertTrue($object->canView());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<LocationTest>.

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.

Loading history...
64
        $this->logOut();
65
        $nullMember = Member::create();
66
        $nullMember->write();
67
        $this->assertTrue($object->canView($nullMember));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<LocationTest>.

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.

Loading history...
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.');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<LocationTest>.

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.

Loading history...
79
        $this->assertTrue($object->canEdit());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<LocationTest>.

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.

Loading history...
80
        $object->Title = 'Changed Title';
81
        $object->write();
82
        $testEdit = Location::get()->byID($objectID);
83
        $this->assertEquals($testEdit->Title, 'Changed Title');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<LocationTest>.

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.

Loading history...
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());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<LocationTest>.

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.

Loading history...
93
        $checkObject = $object;
94
        $object->delete();
95
        $this->assertEquals($checkObject->ID, 0);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<LocationTest>.

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.

Loading history...
96
    }
97
98 View Code Duplication
    public function testCanCreate()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
99
    {
100
        $object = singleton('Location');
101
        $this->logInWithPermission('Location_CREATE');
102
        $this->assertTrue($object->canCreate());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<LocationTest>.

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.

Loading history...
103
        $this->logOut();
104
        $nullMember = Member::create();
105
        $nullMember->write();
106
        $this->assertFalse($object->canCreate($nullMember));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<LocationTest>.

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.

Loading history...
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());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<LocationTest>.

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.

Loading history...
119
    }
120
}
121