1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Evheniy\HTML5CacheBundle\Tests\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
6
|
|
|
use Symfony\Component\Config\FileLocator; |
7
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
8
|
|
|
use Evheniy\HTML5CacheBundle\DependencyInjection\HTML5CacheExtension; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class HTML5CacheExtensionTest |
13
|
|
|
* |
14
|
|
|
* @package Evheniy\HTML5CacheBundle\Tests\DependencyInjection |
15
|
|
|
*/ |
16
|
|
|
class HTML5CacheExtensionTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var HTML5CacheExtension |
20
|
|
|
*/ |
21
|
|
|
private $extension; |
22
|
|
|
/** |
23
|
|
|
* @var ContainerBuilder |
24
|
|
|
*/ |
25
|
|
|
private $container; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* |
29
|
|
|
*/ |
30
|
|
|
protected function setUp() |
31
|
|
|
{ |
32
|
|
|
$this->extension = new HTML5CacheExtension(); |
33
|
|
|
|
34
|
|
|
$this->container = new ContainerBuilder(); |
35
|
|
|
$this->container->registerExtension($this->extension); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param ContainerBuilder $container |
40
|
|
|
* @param string $resource |
41
|
|
|
*/ |
42
|
|
|
protected function loadConfiguration(ContainerBuilder $container, $resource) |
43
|
|
|
{ |
44
|
|
|
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/Fixtures/')); |
45
|
|
|
$loader->load($resource . '.yml'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Test empty config |
50
|
|
|
*/ |
51
|
|
|
public function testWithoutConfiguration() |
52
|
|
|
{ |
53
|
|
|
$this->container->loadFromExtension($this->extension->getAlias()); |
54
|
|
|
$this->container->compile(); |
55
|
|
|
$this->assertTrue($this->container->hasParameter('html5_cache')); |
56
|
|
|
$html5Cache = $this->container->getParameter('html5_cache'); |
57
|
|
|
$this->assertEmpty($html5Cache['cdn']); |
58
|
|
|
$this->assertTrue($html5Cache['http']); |
59
|
|
|
$this->assertTrue($html5Cache['https']); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Test normal config |
64
|
|
|
*/ |
65
|
|
|
public function testTest() |
66
|
|
|
{ |
67
|
|
|
$this->loadConfiguration($this->container, 'test'); |
68
|
|
|
$this->container->compile(); |
69
|
|
|
$this->assertTrue($this->container->hasParameter('html5_cache')); |
70
|
|
|
$html5Cache = $this->container->getParameter('html5_cache'); |
71
|
|
|
$this->assertNotEmpty($html5Cache['cdn']); |
72
|
|
|
$this->assertEquals($html5Cache['cdn'], '//cdn.site.com'); |
73
|
|
|
$this->assertEmpty($html5Cache['https']); |
74
|
|
|
$this->assertFalse($html5Cache['https']); |
75
|
|
|
$this->assertEmpty($html5Cache['http']); |
76
|
|
|
$this->assertFalse($html5Cache['http']); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* |
81
|
|
|
*/ |
82
|
|
|
public function testGetAlias() |
83
|
|
|
{ |
84
|
|
|
$this->assertEquals($this->extension->getAlias(), 'html5_cache'); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|