Completed
Push — master ( dd845a...c89ab0 )
by Jason
12s
created

tests/LocationTest.php (19 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Dynamic\Locator\Tests;
4
5
use Dynamic\SilverStripeGeocoder\GoogleGeocoder;
6
use SilverStripe\Core\Config\Config;
7
use SilverStripe\Dev\SapphireTest;
8
use Dynamic\Locator\Location;
9
use SilverStripe\Security\Member;
10
11
/**
12
 * Class LocationTest
13
 */
14
class LocationTest extends SapphireTest
15
{
16
    /**
17
     * @var string
18
     */
19
    protected static $fixture_file = 'locator/tests/fixtures.yml';
20
21
    /**
22
     *
23
     */
24
    public function testGetCoords()
25
    {
26
        $location = $this->objFromFixture('Dynamic\\Locator\\Location', 'dynamic');
27
        $coords = ((int)$location->Lat != 0 && (int)$location->Lng != 0) ? 'true' : 'false';
28
        $this->assertEquals($coords, $location->getCoords());
0 ignored issues
show
The method assertEquals() does not seem to exist on object<Dynamic\Locator\Tests\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...
29
    }
30
31
    /**
32
     *
33
     */
34
    public function testFieldLabels()
35
    {
36
        $location = $this->objFromFixture(Location::class, 'dynamic');
37
        $labels = $location->FieldLabels();
38
        $expected = array(
39
            'Title' => 'Name',
40
            'Featured' => 'Featured',
41
            'Website' => 'Website',
42
            'Phone' => 'Phone',
43
            'Email' => 'Email',
44
            'Address' => 'Address',
45
            'City' => 'City',
46
            'State' => 'State',
47
            'PostalCode' => 'Postal Code',
48
            'Country' => 'Country',
49
            'Lat' => 'Lat',
50
            'Lng' => 'Lng',
51
            'Category' => 'Category',
52
            'Category.Name' => 'Category',
53
            'Category.ID' => 'Category',
54
            'Featured.NiceAsBoolean' => 'Featured',
55
            'Import_ID' => 'Import_ID',
56
            'Version' => 'Version',
57
            'Versions' => 'Versions',
58
            'Address2' => 'Address2'
59
        );
60
        $this->assertEquals($expected, $labels);
0 ignored issues
show
The method assertEquals() does not seem to exist on object<Dynamic\Locator\Tests\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...
61
    }
62
63
    /**
64
     *
65
     */
66
    public function testGetCMSFields()
67
    {
68
        $object = new Location();
69
        $fieldset = $object->getCMSFields();
70
        $this->assertTrue(is_a($fieldset, 'SilverStripe\\Forms\\FieldList'));
0 ignored issues
show
The method assertTrue() does not seem to exist on object<Dynamic\Locator\Tests\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...
71
    }
72
73
    /**
74
     *
75
     */
76
    public function testCanView()
77
    {
78
        $object = $this->objFromFixture(Location::class, 'dynamic');
79
        $object->write();
80
81
        $this->assertTrue($object->canView());
0 ignored issues
show
The method assertTrue() does not seem to exist on object<Dynamic\Locator\Tests\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...
82
83
        $nullMember = Member::create();
84
        $nullMember->write();
85
86
        $this->assertTrue($object->canView($nullMember));
0 ignored issues
show
The method assertTrue() does not seem to exist on object<Dynamic\Locator\Tests\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...
87
88
        $nullMember->delete();
89
    }
90
91
    /**
92
     *
93
     */
94
    public function testCanEdit()
95
    {
96
        $object = $this->objFromFixture(Location::class, 'dynamic');
97
        $object->write();
98
99
        $objectID = $object->ID;
100
101
        //test permissions per permission setting
102
        $create = $this->objFromFixture(Member::class, 'locationcreate');
103
        $edit = $this->objFromFixture(Member::class, 'locationedit');
104
        $delete = $this->objFromFixture(Member::class, 'locationdelete');
105
106
        $originalTitle = $object->Title;
107
        $this->assertEquals($originalTitle, 'Dynamic, Inc.');
0 ignored issues
show
The method assertEquals() does not seem to exist on object<Dynamic\Locator\Tests\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...
108
109
        $this->assertTrue($object->canEdit($edit));
0 ignored issues
show
The method assertTrue() does not seem to exist on object<Dynamic\Locator\Tests\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...
110
        $this->assertFalse($object->canEdit($create));
0 ignored issues
show
The method assertFalse() does not seem to exist on object<Dynamic\Locator\Tests\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...
111
        $this->assertFalse($object->canEdit($delete));
0 ignored issues
show
The method assertFalse() does not seem to exist on object<Dynamic\Locator\Tests\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...
112
113
        $object->Title = 'Changed Title';
114
        $object->write();
115
116
        $testEdit = Location::get()->byID($objectID);
117
        $this->assertEquals($testEdit->Title, 'Changed Title');
0 ignored issues
show
The method assertEquals() does not seem to exist on object<Dynamic\Locator\Tests\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...
118
    }
119
120
    /**
121
     *
122
     */
123
    public function testCanDelete()
124
    {
125
        $object = $this->objFromFixture(Location::class, 'dynamic');
126
        $object->write();
127
128
        //test permissions per permission setting
129
        $create = $this->objFromFixture(Member::class, 'locationcreate');
130
        $edit = $this->objFromFixture(Member::class, 'locationedit');
131
        $delete = $this->objFromFixture(Member::class, 'locationdelete');
132
133
        $this->assertTrue($object->canDelete($delete));
0 ignored issues
show
The method assertTrue() does not seem to exist on object<Dynamic\Locator\Tests\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
        $this->assertFalse($object->canDelete($create));
0 ignored issues
show
The method assertFalse() does not seem to exist on object<Dynamic\Locator\Tests\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...
135
        $this->assertFalse($object->canDelete($edit));
0 ignored issues
show
The method assertFalse() does not seem to exist on object<Dynamic\Locator\Tests\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...
136
137
        $checkObject = $object;
138
        $object->delete();
139
140
        $this->assertEquals($checkObject->ID, 0);
0 ignored issues
show
The method assertEquals() does not seem to exist on object<Dynamic\Locator\Tests\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...
141
    }
142
143
    /**
144
     *
145
     */
146
    public function testCanCreate()
147
    {
148
        $object = singleton(Location::class);
149
150
        //test permissions per permission setting
151
        $create = $this->objFromFixture(Member::class, 'locationcreate');
152
        $edit = $this->objFromFixture(Member::class, 'locationedit');
153
        $delete = $this->objFromFixture(Member::class, 'locationdelete');
154
155
        $this->assertTrue($object->canCreate($create));
0 ignored issues
show
The method assertTrue() does not seem to exist on object<Dynamic\Locator\Tests\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...
156
        $this->assertFalse($object->canCreate($edit));
0 ignored issues
show
The method assertFalse() does not seem to exist on object<Dynamic\Locator\Tests\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...
157
        $this->assertFalse($object->canCreate($delete));
0 ignored issues
show
The method assertFalse() does not seem to exist on object<Dynamic\Locator\Tests\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...
158
159
        $nullMember = Member::create();
160
        $nullMember->write();
161
        $this->assertFalse($object->canCreate($nullMember));
0 ignored issues
show
The method assertFalse() does not seem to exist on object<Dynamic\Locator\Tests\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...
162
163
        $nullMember->delete();
164
    }
165
166
    /**
167
     *
168
     */
169
    public function testProvidePermissions()
170
    {
171
        $object = Location::create();
172
        $expected = array(
173
            'Location_EDIT' => 'Edit a Location',
174
            'Location_DELETE' => 'Delete a Location',
175
            'Location_CREATE' => 'Create a Location',
176
        );
177
        $this->assertEquals($expected, $object->providePermissions());
0 ignored issues
show
The method assertEquals() does not seem to exist on object<Dynamic\Locator\Tests\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...
178
    }
179
}
180