Completed
Push — master ( cc20d7...7a07c8 )
by Nic
03:04
created

LocationTest::testCanEdit()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 25
rs 8.8571
cc 1
eloc 16
nc 1
nop 0
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());
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...
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);
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...
44
    }
45
46
    public function testGetCMSFields()
47
    {
48
        $object = new Location();
49
        $fieldset = $object->getCMSFields();
50
        $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...
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());
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...
67
68
        $nullMember = Member::create();
69
        $nullMember->write();
70
71
        $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...
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.');
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...
90
91
        $this->assertTrue($object->canEdit($edit));
0 ignored issues
show
Bug introduced by
It seems like $edit defined by $this->objFromFixture('Member', 'locationedit') on line 85 can also be of type object<DataObject>; however, DataObject::canEdit() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
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...
92
        $this->assertFalse($object->canEdit($create));
0 ignored issues
show
Bug introduced by
It seems like $create defined by $this->objFromFixture('Member', 'locationcreate') on line 84 can also be of type object<DataObject>; however, DataObject::canEdit() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
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...
93
        $this->assertFalse($object->canEdit($delete));
0 ignored issues
show
Bug introduced by
It seems like $delete defined by $this->objFromFixture('Member', 'locationdelete') on line 86 can also be of type object<DataObject>; however, DataObject::canEdit() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
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...
94
95
        $object->Title = 'Changed Title';
96
        $object->write();
97
98
        $testEdit = Location::get()->byID($objectID);
99
        $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...
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));
0 ignored issues
show
Bug introduced by
It seems like $delete defined by $this->objFromFixture('Member', 'locationdelete') on line 110 can also be of type object<DataObject>; however, DataObject::canDelete() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
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...
113
        $this->assertFalse($object->canDelete($create));
0 ignored issues
show
Bug introduced by
It seems like $create defined by $this->objFromFixture('Member', 'locationcreate') on line 108 can also be of type object<DataObject>; however, DataObject::canDelete() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
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...
114
        $this->assertFalse($object->canDelete($edit));
0 ignored issues
show
Bug introduced by
It seems like $edit defined by $this->objFromFixture('Member', 'locationedit') on line 109 can also be of type object<DataObject>; however, DataObject::canDelete() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
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...
115
116
        $checkObject = $object;
117
        $object->delete();
118
119
        $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...
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));
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...
132
        $this->assertFalse($object->canCreate($edit));
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...
133
        $this->assertFalse($object->canCreate($delete));
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...
134
135
        $nullMember = Member::create();
136
        $nullMember->write();
137
        $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...
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());
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...
151
    }
152
}
153