Completed
Push — master ( 18bc97...e7bdcd )
by Yaroslav
09:10
created

SymfonyAccessControlTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 27
dl 0
loc 49
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testLink() 0 4 1
A linkDataProvider() 0 13 1
1
<?php
2
3
/*
4
 *
5
 * (c) Yaroslav Honcharuk <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Yarhon\RouteGuardBundle\Tests\Functional;
12
13
use Symfony\Bundle\TwigBundle\TwigBundle;
14
15
/**
16
 * @runTestsInSeparateProcesses
17
 *
18
 * @author Yaroslav Honcharuk <[email protected]>
19
 */
20
class SymfonyAccessControlTest extends WebTestCase
21
{
22
    protected static $bundles = [
23
        TwigBundle::class,
24
        Bundle\SymfonyAccessControlBundle\SymfonyAccessControlBundle::class,
25
    ];
26
27
    protected static $configs = [
28
        'framework' => [
29
            'router' => [
30
                'resource' => '@SymfonyAccessControlBundle/routes.yaml',
31
            ],
32
        ],
33
        'security' => [
34
            'access_control' => [
35
                ['path' => 'foo', 'roles' => 'ROLE_DUMMY'],
36
                ['path' => '^/static_path', 'roles' => 'ROLE_USER'],
37
                ['path' => '^/dynamic_path/user', 'roles' => 'ROLE_USER'],
38
                ['path' => '^/dynamic_path/admin', 'roles' => 'ROLE_ADMIN'],
39
            ],
40
        ],
41
    ];
42
43
    protected static $users = [
44
        'bob' => ['password' => 'pa$$word', 'roles' => 'ROLE_USER'],
45
    ];
46
47
    /**
48
     * @dataProvider linkDataProvider
49
     */
50
    public function testLink($user, $route, $expected)
51
    {
52
        $link = $this->requestLink($user, $route);
53
        $this->assertEquals($expected, $link->html());
54
    }
55
56
    public function linkDataProvider()
57
    {
58
        return [
59
            [null, ['public'], 'http://example.com/public'],
60
            ['bob', ['public'], 'http://example.com/public'],
61
62
            [null, ['static_path'], 'No access'],
63
            ['bob', ['static_path'], 'http://example.com/static_path'],
64
65
            [null, ['dynamic_path', ['page' => 'test']], 'http://example.com/dynamic_path/test'],
66
            [null, ['dynamic_path', ['page' => 'user']], 'No access'],
67
            ['bob', ['dynamic_path', ['page' => 'user']], 'http://example.com/dynamic_path/user'],
68
            ['bob', ['dynamic_path', ['page' => 'admin']], 'No access'],
69
        ];
70
    }
71
}
72