Completed
Pull Request — dev (#11)
by
unknown
05:12 queued 01:17
created

TestPluginTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 114
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 114
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A synopsis() 0 22 1
B testSupportsControllerAndAction() 0 81 1
1
<?php
2
3
namespace Vectorface\SnappyRouterTests\Plugin;
4
5
use \PHPUnit_Framework_TestCase;
6
use Vectorface\SnappyRouter\Plugin\AbstractPlugin;
7
use Vectorface\SnappyRouter\Plugin\PluginInterface;
8
9
class TestPluginTest extends PHPUnit_Framework_TestCase
10
{
11
    /**
12
     * A demonstrate of a simple test plugin.
13
     * @test
14
     */
15
    public function synopsis()
16
    {
17
        $options = array();
18
        $plugin = new TestPlugin($options);
19
20
        $this->assertEquals(
21
            AbstractPlugin::PRIORITY_DEFAULT,
22
            $plugin->getExecutionOrder()
23
        );
24
25
        $plugin->setWhitelist(
26
            array(
27
                'TestController' => AbstractPlugin::ALL_ACTIONS
28
            )
29
        );
30
        $this->assertTrue(
31
            $plugin->supportsControllerAndAction(
32
                'TestController',
33
                'someAction'
34
            )
35
        );
36
    }
37
38
    /**
39
     * Tests the supportsControllerAndAction methods.
40
     */
41
    public function testSupportsControllerAndAction()
42
    {
43
        $plugin = new TestPlugin(array());
44
45
        // no lists yet, so plugin supports everything
46
        $this->assertTrue(
47
            $plugin->supportsControllerAndAction(
48
                'TestController',
49
                'anyAction'
50
            )
51
        );
52
53
        // set a whitelist
54
        $plugin->setWhitelist(
55
            array(
56
                'TestController' => AbstractPlugin::ALL_ACTIONS,
57
                'AnotherController' => array(
58
                    'specificAction'
59
                )
60
            )
61
        );
62
        // all actions enabled for this controller
63
        $this->assertTrue(
64
            $plugin->supportsControllerAndAction(
65
                'TestController',
66
                'anyAction'
67
            )
68
        );
69
        // specific action enabled
70
        $this->assertTrue(
71
            $plugin->supportsControllerAndAction(
72
                'AnotherController',
73
                'specificAction'
74
            )
75
        );
76
        // controller is missing from whitelist
77
        $this->assertFalse(
78
            $plugin->supportsControllerAndAction(
79
                'MissingController',
80
                'anyAction'
81
            )
82
        );
83
        // action is missing from whitelist
84
        $this->assertFalse(
85
            $plugin->supportsControllerAndAction(
86
                'AnotherController',
87
                'differentAction'
88
            )
89
        );
90
91
        // now the reverse logic for the blacklist
92
        $plugin->setBlacklist(
93
            array(
94
                'TestController' => array(
95
                    'bannedAction'
96
                ),
97
                'BannedController' => AbstractPlugin::ALL_ACTIONS
98
            )
99
        );
100
        // controller is missing from blacklist
101
        $this->assertTrue(
102
            $plugin->supportsControllerAndAction(
103
                'MissingController',
104
                'anyAction'
105
            )
106
        );
107
        // action is blacklisted specifically
108
        $this->assertFalse(
109
            $plugin->supportsControllerAndAction(
110
                'TestController',
111
                'bannedAction'
112
            )
113
        );
114
        // all actions for the controller are banned
115
        $this->assertFalse(
116
            $plugin->supportsControllerAndAction(
117
                'BannedController',
118
                'anyAction'
119
            )
120
        );
121
    }
122
}
123