SettingsTest::testCanEdit()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 14
rs 10
1
<?php
2
3
namespace Dynamic\Foxy\Test\Model;
4
5
use Dynamic\Foxy\Model\Setting;
6
use SilverStripe\Dev\SapphireTest;
7
use SilverStripe\Forms\FieldList;
8
use SilverStripe\Security\Member;
9
10
/**
11
 * Class SettingsTest
12
 * @package Dynamic\Foxy\Test\Model
13
 */
14
class SettingsTest extends SapphireTest
15
{
16
17
    /**
18
     * @var string
19
     */
20
    protected static $fixture_file = '../fixtures.yml';
21
22
    /**
23
     *
24
     */
25
    public function testGetCMSFields()
26
    {
27
        /** @var Setting $object */
28
        $object = singleton(Setting::class);
29
        $fields = $object->getCMSFields();
30
        $this->assertInstanceOf(FieldList::class, $fields);
31
    }
32
33
    /**
34
     *
35
     */
36
    public function testGetCMSActions()
37
    {
38
        /** @var Setting $object */
39
        $object = singleton(Setting::class);
40
        $fields = $object->getCMSActions();
41
        $this->assertInstanceOf(FieldList::class, $fields);
42
    }
43
44
    /**
45
     *
46
     */
47
    public function testOnBeforeWrite()
48
    {
49
        /** @var Setting $object */
50
        $object = Setting::create();
51
        $this->assertNull($object->StoreKey);
52
53
        $object->write();
54
        $this->assertInternalType('string', $object->StoreKey);
55
    }
56
57
    /**
58
     *
59
     */
60
    public function testGenerateStoreKey()
61
    {
62
        /** @var Setting $object */
63
        $object = singleton(Setting::class);
64
        $key = $object->generateStoreKey();
65
        $this->assertEquals(60, strlen($key));
66
        $this->assertEquals('dYnm1c', substr($key, 0, 6));
67
    }
68
69
    /**
70
     *
71
     */
72
    public function testCanEdit()
73
    {
74
        /** @var Setting $object */
75
        $object = singleton(Setting::class);
76
        /** @var \SilverStripe\Security\Member $admin */
77
        $admin = $this->objFromFixture(Member::class, 'admin');
78
        /** @var \SilverStripe\Security\Member $siteOwner */
79
        $siteOwner = $this->objFromFixture(Member::class, 'site-owner');
80
        /** @var \SilverStripe\Security\Member $default */
81
        $default = $this->objFromFixture(Member::class, 'default');
82
83
        $this->assertFalse($object->canEdit($default));
84
        $this->assertTrue($object->canEdit($admin));
85
        $this->assertTrue($object->canEdit($siteOwner));
86
    }
87
88
    /**
89
     *
90
     */
91
    public function testProvidePermissions()
92
    {
93
        /** @var Setting $object */
94
        $object = singleton(Setting::class);
95
        $this->assertInternalType('array', $object->providePermissions());
96
        $this->assertArrayHasKey('EDIT_FOXY_SETTING', $object->providePermissions());
97
    }
98
99
    /**
100
     *
101
     */
102
    public function testCurrentFoxySetting()
103
    {
104
        $this->assertInstanceOf(Setting::class, Setting::current_foxy_setting());
105
    }
106
107
    /**
108
     *
109
     */
110
    public function testMakeFoxySetting()
111
    {
112
        $this->assertInstanceOf(Setting::class, Setting::make_foxy_setting());
113
    }
114
115
    /**
116
     *
117
     */
118
    public function testGetTemplateGlobalVariables()
119
    {
120
        $this->assertInternalType('array', Setting::get_template_global_variables());
121
        $this->assertArrayHasKey('FoxyStripe', Setting::get_template_global_variables());
122
    }
123
}
124