Code Duplication    Length = 32-32 lines in 2 locations

tests/php/SiteConfigTest.php 2 locations

@@ 22-53 (lines=32) @@
19
        SiteTree::class => ['SiteTreeSubsites'],
20
    );
21
22
    public function testCanCreateRootPages()
23
    {
24
        /** @var SiteConfig $config */
25
        $config = $this->objFromFixture(SiteConfig::class, 'default');
26
27
        // Admin trumps all
28
        $this->actWithPermission('ADMIN', function () use ($config) {
29
            $this->assertTrue($config->canCreateTopLevel());
30
        });
31
32
        // Log in without pages admin access
33
        $this->actWithPermission('CMS_ACCESS_AssetAdmin', function () use ($config) {
34
            $this->assertFalse($config->canCreateTopLevel());
35
        });
36
37
        // Login with necessary edit permission
38
        $perms = SiteConfig::config()->get('required_permission');
39
        $this->actWithPermission(reset($perms), function () use ($config) {
40
            $this->assertTrue($config->canCreateTopLevel());
41
        });
42
43
        // "OnlyTheseUsers" restricts to the correct groups
44
        $config->CanCreateTopLevelType = 'OnlyTheseUsers';
45
        $this->actWithPermission('ADMIN', function () use ($config) {
46
            $this->assertTrue($config->canCreateTopLevel());
47
        });
48
        $this->actWithPermission('CMS_ACCESS_AssetAdmin', function () use ($config) {
49
            $this->assertFalse($config->canCreateTopLevel());
50
            $config->CreateTopLevelGroups()->add(Security::getCurrentUser()->Groups()->First());
51
            $this->assertTrue($config->canCreateTopLevel());
52
        });
53
    }
54
55
    public function testCanViewPages()
56
    {
@@ 100-131 (lines=32) @@
97
        });
98
    }
99
100
    public function testCanEditPages()
101
    {
102
        /** @var SiteConfig $config */
103
        $config = $this->objFromFixture(SiteConfig::class, 'default');
104
105
        // Admin can always edit
106
        $this->actWithPermission('ADMIN', function () use ($config) {
107
            $this->assertTrue($config->canEditPages());
108
        });
109
110
        // Log in without pages admin access
111
        $this->actWithPermission('CMS_ACCESS_AssetAdmin', function () use ($config) {
112
            $this->assertFalse($config->canEditPages());
113
        });
114
115
        // Login with necessary edit permission
116
        $perms = SiteConfig::config()->get('required_permission');
117
        $this->actWithPermission(reset($perms), function () use ($config) {
118
            $this->assertTrue($config->canEditPages());
119
        });
120
121
        // "OnlyTheseUsers" restricts to the correct groups
122
        $config->CanEditType = 'OnlyTheseUsers';
123
        $this->actWithPermission('ADMIN', function () use ($config) {
124
            $this->assertTrue($config->canEditPages());
125
        });
126
        $this->actWithPermission('CMS_ACCESS_AssetAdmin', function () use ($config) {
127
            $this->assertFalse($config->canEditPages());
128
            $config->EditorGroups()->add(Security::getCurrentUser()->Groups()->First());
129
            $this->assertTrue($config->canEditPages());
130
        });
131
    }
132
}
133