Issues (62)

Tests/Twig/RoutingExtensionTest.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\Twig;
12
13
use PHPUnit\Framework\TestCase;
14
use Twig\TwigFunction;
15
use Yarhon\RouteGuardBundle\Twig\Node\RouteNode;
16
use Yarhon\RouteGuardBundle\Twig\TokenParser\RouteTokenParser;
17
use Yarhon\RouteGuardBundle\Twig\NodeVisitor\DiscoverRoutingFunctionNodeVisitor;
18
use Yarhon\RouteGuardBundle\Twig\RoutingRuntime;
19
use Yarhon\RouteGuardBundle\Twig\Extension\RoutingExtension;
20
21
class RoutingExtensionTest extends TestCase
22
{
23
    public function testGetFunctions()
24
    {
25
        $extension = new RoutingExtension();
26
27
        $functions = [
28
            new TwigFunction('route_guard_route', [RoutingRuntime::class, 'route']),
29
            new TwigFunction('route_guard_path', [RoutingRuntime::class, 'path']),
30
            new TwigFunction('route_guard_url', [RoutingRuntime::class, 'url']),
31
        ];
32
33
        $this->assertEquals($functions, $extension->getFunctions());
34
    }
35
36
    public function testGetTokenParsersDefaultOptions()
37
    {
38
        $defaults = [
39
            'tag_name' => 'route',
40
            'tag_variable_name' => '_route',
41
            'discover_routing_functions' => false,
42
        ];
43
44
        $extension = new RoutingExtension();
45
46
        $tokenParsers = [
47
            new RouteTokenParser($defaults['tag_name'], $defaults['discover_routing_functions']),
48
        ];
49
50
        $this->assertEquals($tokenParsers, $extension->getTokenParsers());
51
    }
52
53
    public function testGetTokenParsersCustomOptions()
54
    {
55
        $options = [
56
            'tag_name' => 'foo',
57
            'tag_variable_name' => 'bar',
58
            'discover_routing_functions' => true,
59
        ];
60
61
        $extension = new RoutingExtension($options);
62
63
        $tokenParsers = [
64
            new RouteTokenParser($options['tag_name'], $options['discover_routing_functions']),
65
        ];
66
67
        $this->assertEquals($tokenParsers, $extension->getTokenParsers());
68
    }
69
70
    public function testDiscoverNodeVisitorEmpty()
71
    {
72
        $extension = new RoutingExtension();
73
        $nodeVisitors = [];
74
75
        $this->assertEquals($nodeVisitors, $extension->getNodeVisitors());
76
    }
77
78
    public function testDiscoverNodeVisitor()
79
    {
80
        $options = [
81
            'tag_name' => 'foo',
82
            'tag_variable_name' => 'bar',
83
            'discover_routing_functions' => true,
84
        ];
85
86
        $extension = new RoutingExtension($options);
87
        $nodeVisitors = [
88
            new DiscoverRoutingFunctionNodeVisitor($options['tag_name'], $options['tag_variable_name']),
89
        ];
90
91
        $this->assertEquals($nodeVisitors, $extension->getNodeVisitors());
92
    }
93
94
    public function testRouteNode()
95
    {
96
        $defaults = [
97
            'tag_variable_name' => '_route',
98
        ];
99
100
        $extension = new RoutingExtension();
0 ignored issues
show
The assignment to $extension is dead and can be removed.
Loading history...
101
102
        $this->assertAttributeEquals($defaults['tag_variable_name'], 'variableName', RouteNode::class);
103
104
        $options = [
105
            'tag_variable_name' => 'bar',
106
        ];
107
108
        $extension = new RoutingExtension($options);
109
110
        $this->assertAttributeEquals($options['tag_variable_name'], 'variableName', RouteNode::class);
111
    }
112
}
113