Passed
Branch master (608a5d)
by Simon
01:54
created

AnnotatePermissionCheckerTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 11
rs 9.4285
c 1
b 0
f 0
1
<?php
2
3
namespace SilverLeague\IDEAnnotator\Tests;
4
5
use SilverStripe\Core\Injector\Injector;
6
use SilverStripe\Core\Config\Config;
7
use SilverStripe\Dev\SapphireTest;
8
use SilverLeague\IDEAnnotator\DataObjectAnnotator;
9
use SilverStripe\Assets\File;
10
use SilverStripe\ORM\DataObject;
11
use SilverLeague\IDEAnnotator\AnnotatePermissionChecker;
12
use SilverStripe\Control\Director;
13
14
/**
15
 * Class DataObjectAnnotatorTest
16
 *
17
 * @mixin \PHPUnit_Framework_TestCase
18
 */
19
class AnnotatePermissionCheckerTest extends SapphireTest
20
{
21
22
    /**
23
     * @var \SilverLeague\IDEAnnotator\AnnotatePermissionChecker $permissionChecker
24
     */
25
    private $permissionChecker = null;
26
27
    /**
28
     * @var MockDataObjectAnnotator
1 ignored issue
show
Bug introduced by
The type SilverLeague\IDEAnnotato...MockDataObjectAnnotator was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
29
     */
30
    private $annotator;
31
32
    public function testIsEnabled()
33
    {
34
        $this->assertTrue($this->permissionChecker->isEnabled());
35
36
        Config::inst()->remove(DataObjectAnnotator::class, 'enabled');
0 ignored issues
show
Bug introduced by
The method remove() does not exist on SilverStripe\Config\Coll...nfigCollectionInterface. It seems like you code against a sub-type of SilverStripe\Config\Coll...nfigCollectionInterface such as SilverStripe\Config\Coll...nfigCollectionInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

36
        Config::inst()->/** @scrutinizer ignore-call */ remove(DataObjectAnnotator::class, 'enabled');
Loading history...
37
        Config::modify()->set(DataObjectAnnotator::class, 'enabled', false);
38
        $this->assertFalse($this->permissionChecker->isEnabled());
39
    }
40
41
    /**
42
     * Test is a module name is in the @Config enabled_modules
43
     * and will be seen as allowed or disallowed correctly
44
     */
45
    public function testModuleIsAllowed()
46
    {
47
        $this->assertFalse($this->permissionChecker->moduleIsAllowed('framework'));
48
        $this->assertTrue($this->permissionChecker->moduleIsAllowed('mysite'));
49
        $this->assertTrue($this->permissionChecker->moduleIsAllowed('ideannotator'));
50
    }
51
52
    /**
53
     * Test if a DataObject is in an allowed module name
54
     * and will be seen as allowed or disallowed correctly
55
     */
56
    public function testDataObjectIsAllowed()
57
    {
58
        $this->assertTrue($this->permissionChecker->classNameIsAllowed(Team::class));
1 ignored issue
show
Bug introduced by
The type SilverLeague\IDEAnnotator\Tests\Team was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
59
        $this->assertTrue($this->permissionChecker->classNameIsAllowed(Team_Extension::class));
1 ignored issue
show
Bug introduced by
The type SilverLeague\IDEAnnotator\Tests\Team_Extension was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
60
61
        $this->assertFalse($this->permissionChecker->classNameIsAllowed(DataObject::class));
62
        $this->assertFalse($this->permissionChecker->classNameIsAllowed(File::class));
63
64
        Config::inst()->remove(DataObjectAnnotator::class, 'enabled_modules');
65
        Config::modify()->set(DataObjectAnnotator::class, 'enabled_modules', array('mysite'));
66
67
        $this->assertFalse($this->permissionChecker->classNameIsAllowed(Team::class));
68
    }
69
70
    public function tearDown()
71
    {
72
        parent::tearDown();
73
    }
74
75
    /**
76
     * Setup Defaults
77
     */
78
    protected function setUp()
79
    {
80
        parent::setUp();
81
        Config::modify()->set(Director::class, 'environment_type', 'dev');
82
        Config::modify()->set(DataObjectAnnotator::class, 'enabled', true);
83
        Config::modify()->set(DataObjectAnnotator::class, 'enabled_modules', ['ideannotator', 'mysite']);
84
85
        Config::modify()->merge(Team::class, 'extensions', [Team_Extension::class]);
86
87
        $this->annotator = Injector::inst()->get(MockDataObjectAnnotator::class);
88
        $this->permissionChecker = Injector::inst()->get(AnnotatePermissionChecker::class);
89
    }
90
}
91