1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* (c) Christian Gripp <[email protected]> |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Core23\MatomoBundle\Tests\Twig\Extension; |
11
|
|
|
|
12
|
|
|
use Core23\MatomoBundle\Twig\Extension\MatomoTwigExtension; |
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
use Prophecy\Argument; |
15
|
|
|
use Twig\Environment; |
16
|
|
|
use Twig\TwigFunction; |
17
|
|
|
|
18
|
|
|
class MatomoTwigExtensionTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
private $environment; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* {@inheritdoc} |
24
|
|
|
*/ |
25
|
|
|
protected function setUp(): void |
26
|
|
|
{ |
27
|
|
|
$this->environment = $this->prophesize(Environment::class); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testGetFunctions(): void |
31
|
|
|
{ |
32
|
|
|
$extension = new MatomoTwigExtension($this->environment->reveal()); |
33
|
|
|
|
34
|
|
|
$functions = $extension->getFunctions(); |
35
|
|
|
|
36
|
|
|
$this->assertCount(1, $functions); |
37
|
|
|
|
38
|
|
|
foreach ($functions as $function) { |
39
|
|
|
$this->assertInstanceOf(TwigFunction::class, $function); |
40
|
|
|
$this->assertIsCallable($function->getCallable()); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testRenderTracker(): void |
45
|
|
|
{ |
46
|
|
|
$this->environment->render('@Core23Matomo/tracker_code.html.twig', [ |
47
|
|
|
'site_id' => 13, |
48
|
|
|
'matomo_host' => 'localhost', |
49
|
|
|
'cookie_domain' => null, |
50
|
|
|
]) |
51
|
|
|
->willReturn('HTML CONTENT') |
52
|
|
|
; |
53
|
|
|
|
54
|
|
|
$extension = new MatomoTwigExtension($this->environment->reveal()); |
55
|
|
|
|
56
|
|
|
$this->assertSame('HTML CONTENT', $extension->renderTracker([ |
57
|
|
|
'site_id' => 13, |
58
|
|
|
])); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function testRenderTrackerWithoutSiteId(): void |
62
|
|
|
{ |
63
|
|
|
$extension = new MatomoTwigExtension($this->environment->reveal()); |
64
|
|
|
|
65
|
|
|
$this->environment->render(Argument::any()) |
66
|
|
|
->shouldNotBeCalled() |
67
|
|
|
; |
68
|
|
|
|
69
|
|
|
$this->assertSame('', $extension->renderTracker()); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|