Passed
Pull Request — master (#173)
by Matthew
13:34
created

LocationTest::testCanEdit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 9
rs 9.6666
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\Forms\FieldList;
10
use SilverStripe\Security\Member;
11
12
/**
13
 * Class LocationTest
14
 */
15
class LocationTest extends SapphireTest
16
{
17
18
    protected static $fixture_file = '../fixtures.yml';
19
20
    /**
21
     *
22
     */
23
    public function testGetCoords()
24
    {
25
        $location = $this->objFromFixture(Location::class, 'dynamic');
26
        $coords = ((int)$location->Lat != 0 && (int)$location->Lng != 0) ? 'true' : 'false';
27
        $this->assertEquals($coords, $location->getCoords());
28
    }
29
30
    /**
31
     *
32
     */
33
    public function testFieldLabels()
34
    {
35
        $location = $this->objFromFixture(Location::class, 'dynamic');
36
        $labels = $location->FieldLabels();
37
        $expected = array(
38
            'Title' => 'Name',
39
            'Featured' => 'Featured',
40
            'Website' => 'Website',
41
            'Phone' => 'Phone',
42
            'Email' => 'Email',
43
            'Address' => 'Address',
44
            'City' => 'City',
45
            'State' => 'State',
46
            'PostalCode' => 'Postal Code',
47
            'Country' => 'Country',
48
            'Lat' => 'Lat',
49
            'Lng' => 'Lng',
50
            'Category' => 'Category',
51
            'Category.Name' => 'Category',
52
            'Category.ID' => 'Category',
53
            'Featured.NiceAsBoolean' => 'Featured',
54
            'Import_ID' => 'Import_ID',
55
            'Version' => 'Version',
56
            'Versions' => 'Versions',
57
            'Address2' => 'Address2'
58
        );
59
        $this->assertEquals($expected, $labels);
60
    }
61
62
    /**
63
     *
64
     */
65
    public function testGetCMSFields()
66
    {
67
        $object = new Location();
68
        $fields = $object->getCMSFields();
69
        $this->assertInstanceOf(FieldList::class, $fields);
70
    }
71
72
    /**
73
     *
74
     */
75
    public function testCanView()
76
    {
77
        $object = $this->objFromFixture(Location::class, 'dynamic');
78
79
        $admin = $this->objFromFixture(Member::class, 'admin');
80
        $this->assertTrue($object->canView($admin));
81
82
        $member = $this->objFromFixture(Member::class, 'default');
83
        $this->assertTrue($object->canView($member));
84
    }
85
86
    /**
87
     *
88
     */
89
    public function testCanEdit()
90
    {
91
        $object = $this->objFromFixture(Location::class, 'dynamic');
92
93
        $admin = $this->objFromFixture(Member::class, 'admin');
94
        $this->assertTrue($object->canEdit($admin));
95
96
        $member = $this->objFromFixture(Member::class, 'default');
97
        $this->assertFalse($object->canEdit($member));
98
    }
99
100
    /**
101
     *
102
     */
103
    public function testCanDelete()
104
    {
105
        $object = $this->objFromFixture(Location::class, 'dynamic');
106
107
        $admin = $this->objFromFixture(Member::class, 'admin');
108
        $this->assertTrue($object->canDelete($admin));
109
110
        $member = $this->objFromFixture(Member::class, 'default');
111
        $this->assertFalse($object->canDelete($member));
112
    }
113
114
    /**
115
     *
116
     */
117
    public function testCanCreate()
118
    {
119
        $object = $this->objFromFixture(Location::class, 'dynamic');
120
121
        $admin = $this->objFromFixture(Member::class, 'admin');
122
        $this->assertTrue($object->canCreate($admin));
123
124
        $member = $this->objFromFixture(Member::class, 'default');
125
        $this->assertFalse($object->canCreate($member));
126
    }
127
128
    /**
129
     *
130
     */
131
    public function testProvidePermissions()
132
    {
133
        $object = Location::create();
134
        $expected = array(
135
            'Location_EDIT' => 'Edit a Location',
136
            'Location_DELETE' => 'Delete a Location',
137
            'Location_CREATE' => 'Create a Location',
138
        );
139
        $this->assertEquals($expected, $object->providePermissions());
140
    }
141
}
142