1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Evheniy\GtmBundle\Tests\Twig; |
4
|
|
|
|
5
|
|
|
use Evheniy\GtmBundle\Twig\GtmExtension; |
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class GtmExtensionTest |
10
|
|
|
* |
11
|
|
|
* @package Evheniy\GtmBundle\Tests\Twig |
12
|
|
|
*/ |
13
|
|
|
class GtmExtensionTest extends \PHPUnit_Framework_TestCase |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var GtmExtension |
17
|
|
|
*/ |
18
|
|
|
private $extension; |
19
|
|
|
/** |
20
|
|
|
* @var ContainerBuilder |
21
|
|
|
*/ |
22
|
|
|
private $container; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* |
26
|
|
|
*/ |
27
|
|
|
protected function setUp() |
28
|
|
|
{ |
29
|
|
|
$this->container = new ContainerBuilder(); |
30
|
|
|
$this->extension = new GtmExtension($this->container); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Test normal config |
35
|
|
|
*/ |
36
|
|
|
public function testWithId() |
37
|
|
|
{ |
38
|
|
|
$this->container->setParameter('gtm', array('id' => 'test')); |
39
|
|
|
|
40
|
|
|
$this->assertTrue($this->container->hasParameter('gtm')); |
41
|
|
|
$gtm = $this->container->getParameter('gtm'); |
42
|
|
|
$this->assertNotEmpty($gtm['id']); |
43
|
|
|
$this->assertEquals($gtm['id'], 'test'); |
44
|
|
|
$gtm = $this->extension->getGlobals(); |
45
|
|
|
$this->assertNotEmpty($gtm['gtm']); |
46
|
|
|
$this->assertNotEmpty($gtm['gtm']['id']); |
47
|
|
|
$this->assertEquals($gtm['gtm']['id'], 'test'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Test empty config |
52
|
|
|
*/ |
53
|
|
|
public function testWithOutId() |
54
|
|
|
{ |
55
|
|
|
$this->assertFalse($this->container->hasParameter('gtm')); |
56
|
|
|
$this->setExpectedException( |
57
|
|
|
'Exception', |
58
|
|
|
'You have requested a non-existent parameter "gtm".' |
59
|
|
|
); |
60
|
|
|
$this->assertEmpty($this->extension->getGlobals()); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Test getName() |
65
|
|
|
*/ |
66
|
|
|
public function testGetName() |
67
|
|
|
{ |
68
|
|
|
$this->assertEquals($this->extension->getName(), 'gtm'); |
69
|
|
|
} |
70
|
|
|
} |