Completed
Push — master ( 0067f1...cd591f )
by Yaroslav
10:43 queued 02:50
created

Tests/Functional/SensioSecurityTest.php (1 issue)

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
use Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle;
15
16
/**
17
 * @author Yaroslav Honcharuk <[email protected]>
18
 */
19
class SensioSecurityTest extends WebTestCase
20
{
21
    protected static $bundles = [
22
        TwigBundle::class,
23
        SensioFrameworkExtraBundle::class,
24
        Bundle\SensioSecurityBundle\SensioSecurityBundle::class,
25
    ];
26
27
    protected static $routeResources = [
28
        ['@SensioSecurityBundle/Controller/', '/', 'annotation'],
29
    ];
30
31
    protected static $users = [
32
        'bob' => ['password' => 'pa$$word', 'roles' => 'ROLE_USER'],
33
    ];
34
35
    /**
36
     * @dataProvider linkDataProvider
37
     */
38
    public function testLink($user, $route, $expected)
39
    {
40
        if ($user) {
41
            $serverOptions = ['PHP_AUTH_USER' => $user, 'PHP_AUTH_PW' => static::$users[$user]['password']];
42
        } else {
43
            $serverOptions = [];
44
        }
45
46
        $client = static::createClient([], $serverOptions);
47
48
        $uri = '/link2/'.$route[0];
49
50
        $query = array_filter([
51
            'parameters' => isset($route[1]) ? $route[1] : null,
52
            'method' => isset($route[2]) ? $route[2] : null,
53
        ]);
54
55
        if ($query) {
56
            $uri .= '?'.http_build_query($query);
57
        }
58
59
        $crawler = $client->request('GET', $uri);
60
61
        var_dump($crawler->html());
0 ignored issues
show
Security Debugging Code introduced by
var_dump($crawler->html()) looks like debug code. Are you sure you do not want to remove it?
Loading history...
62
63
        $link = $crawler->filterXPath('//*[@id="link"]');
64
        $this->assertEquals($expected, $link->html());
65
    }
66
67
    public function linkDataProvider()
68
    {
69
        return [
70
            [null, ['public_action'], 'http://example.com/public_action'],
71
            /*
72
            [null, ['user_action'], 'No access'],
73
            [null, ['admin_action'], 'No access'],
74
75
            ['bob', ['public_action'], 'http://example.com/public_action'],
76
            ['bob', ['user_action'], 'http://example.com/user_action'],
77
            ['bob', ['admin_action'], 'No access'],
78
            */
79
        ];
80
    }
81
}
82