Completed
Push — master ( f7b33a...213343 )
by Andy
03:36
created

testGenerateUrlMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
namespace Palmtree\CanonicalUrlBundle\Tests\Twig\Extension;
4
5
use Palmtree\CanonicalUrlBundle\Service\CanonicalUrlGenerator;
6
use Palmtree\CanonicalUrlBundle\Tests\AbstractTest;
7
use Palmtree\CanonicalUrlBundle\Twig\Extension\CanonicalLinkExtension;
8
use Symfony\Component\HttpFoundation\RequestStack;
9
10
class CanonicalLinkExtensionTest extends AbstractTest
11
{
12
    /** @dataProvider configProvider */
13
    public function testGenerateUrlMethod(array $config)
14
    {
15
        $extension = $this->getExtension($config);
16
17
        $url = $extension->generateUrl('foo');
18
19
        $this->assertEquals('https://example.org/foo', $url);
20
    }
21
22
    /** @dataProvider configProvider */
23
    public function testRenderLinkTag($config)
24
    {
25
        $extension = $this->getExtension($config);
26
27
        $loader = new \Twig_Loader_Filesystem();
28
        $loader->setPaths(__DIR__ . '/../../../Resources/views', 'PalmtreeCanonicalUrl');
29
30
        $twig = new \Twig_Environment($loader, array(
31
            'debug'      => true,
32
            'cache'      => false,
33
            'autoescape' => 'html',
34
        ));
35
36
        $twig->addExtension($extension);
37
38
        $html = $extension->renderLinkTag($twig, 'https://example.org');
39
        $html = trim($html);
40
41
        $this->assertEquals('<link rel="canonical" href="https://example.org">', $html);
42
    }
43
44
    protected function getExtension($config)
45
    {
46
        $urlGenerator = new CanonicalUrlGenerator($this->getRouter(), $config);
47
        $requestStack = new RequestStack();
48
49
        $requestStack->push($this->getFooRequest());
50
51
        $extension = new CanonicalLinkExtension($urlGenerator, $requestStack);
52
53
        return $extension;
54
    }
55
}
56