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
|
|
|
|