Completed
Push — master ( db942d...dc6dc4 )
by Daniel
13:09
created

tests/php/SiteConfigTest.php (2 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 SilverStripe\SiteConfig\Tests;
4
5
use SilverStripe\CMS\Model\SiteTree;
6
use SilverStripe\SiteConfig\SiteConfig;
7
use SilverStripe\Dev\SapphireTest;
8
9
/**
10
 * @package siteconfig
11
 * @subpackage tests
12
 */
13
class SiteConfigTest extends SapphireTest
14
{
15
    protected static $fixture_file = 'SiteConfigTest.yml';
16
17
    protected static $illegal_extensions = array(
18
        SiteTree::class => array('SiteTreeSubsites'),
19
    );
20
21 View Code Duplication
    public function testCanCreateRootPages()
0 ignored issues
show
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...
22
    {
23
        /** @var SiteConfig $config */
24
        $config = $this->objFromFixture(SiteConfig::class, 'default');
25
26
        // Log in without pages admin access
27
        $this->logInWithPermission('CMS_ACCESS_AssetAdmin');
28
        $this->assertFalse($config->canCreateTopLevel());
29
30
        // Login with necessary edit permission
31
        $perms = SiteConfig::config()->get('required_permission');
32
        $this->logInWithPermission(reset($perms));
33
        $this->assertTrue($config->canCreateTopLevel());
34
    }
35
36
    public function testCanViewPages()
37
    {
38
        /** @var SiteConfig $config */
39
        $config = $this->objFromFixture(SiteConfig::class, 'default');
40
        $this->assertTrue($config->canViewPages());
41
    }
42
43
    public function testCanEdit()
44
    {
45
        $config = $this->objFromFixture(SiteConfig::class, 'default');
46
47
        // Unrelated permissions don't allow siteconfig
48
        $this->logInWithPermission('CMS_ACCESS_AssetAdmin');
49
        $this->assertFalse($config->canEdit());
50
51
        // Only those with edit permission can do this
52
        $this->logInWithPermission('EDIT_SITECONFIG');
53
        $this->assertTrue($config->canEdit());
54
    }
55
56 View Code Duplication
    public function testCanEditPages()
0 ignored issues
show
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...
57
    {
58
        /** @var SiteConfig $config */
59
        $config = $this->objFromFixture(SiteConfig::class, 'default');
60
61
        // Log in without pages admin access
62
        $this->logInWithPermission('CMS_ACCESS_AssetAdmin');
63
        $this->assertFalse($config->canEditPages());
64
65
        // Login with necessary edit permission
66
        $perms = SiteConfig::config()->get('required_permission');
67
        $this->logInWithPermission(reset($perms));
68
        $this->assertTrue($config->canEditPages());
69
    }
70
}
71