Completed
Push — master ( 3c4b6a...d139bf )
by Sam
02:03
created

SiteConfigTest::setUpAfterClass()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
use SilverStripe\SiteConfig\SiteConfig;
4
use SilverStripe\Dev\SapphireTest;
5
6
/**
7
 * @package siteconfig
8
 * @subpackage tests
9
 */
10
class SiteConfigTest extends SapphireTest
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
11
{
12
    protected static $fixture_file = 'SiteConfigTest.yml';
13
14
    protected static $illegal_extensions = array(
15
        'SilverStripe\\CMS\\Model\\SiteTree' => array('SiteTreeSubsites'),
16
    );
17
18
    public static function setUpAfterClass()
19
    {
20
        // Fix issue with tests failing without CMS module
21
        if (!class_exists('SilverStripe\\CMS\\Model\\SiteTree')) {
22
            unset(static::$illegal_extensions['SilverStripe\\CMS\\Model\\SiteTree']);
23
        }
24
25
        static::setUpAfterClass(); // TODO: Change the autogenerated stub
26
    }
27
28 View Code Duplication
    public function testCanCreateRootPages()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
    {
30
        $config = $this->objFromFixture('SilverStripe\\SiteConfig\\SiteConfig', 'default');
31
32
        // Log in without pages admin access
33
        $this->logInWithPermission('CMS_ACCESS_AssetAdmin');
34
        $this->assertFalse($config->canCreateTopLevel());
35
36
        // Login with necessary edit permission
37
        $perms = SiteConfig::config()->required_permission;
38
        $this->logInWithPermission(reset($perms));
39
        $this->assertTrue($config->canCreateTopLevel());
40
    }
41
42
    public function testCanViewPages()
43
    {
44
        $config = $this->objFromFixture('SilverStripe\\SiteConfig\\SiteConfig', 'default');
45
        $this->assertTrue($config->canViewPages());
46
    }
47
48
    public function testCanEdit()
49
    {
50
        $config = $this->objFromFixture('SilverStripe\\SiteConfig\\SiteConfig', 'default');
51
52
        // Unrelated permissions don't allow siteconfig
53
        $this->logInWithPermission('CMS_ACCESS_AssetAdmin');
54
        $this->assertFalse($config->canEdit());
55
56
        // Only those with edit permission can do this
57
        $this->logInWithPermission('EDIT_SITECONFIG');
58
        $this->assertTrue($config->canEdit());
59
    }
60
61 View Code Duplication
    public function testCanEditPages()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
62
    {
63
        $config = $this->objFromFixture('SilverStripe\\SiteConfig\\SiteConfig', 'default');
64
65
        // Log in without pages admin access
66
        $this->logInWithPermission('CMS_ACCESS_AssetAdmin');
67
        $this->assertFalse($config->canEditPages());
68
69
        // Login with necessary edit permission
70
        $perms = SiteConfig::config()->required_permission;
71
        $this->logInWithPermission(reset($perms));
72
        $this->assertTrue($config->canEditPages());
73
    }
74
}
75