JqueryExtensionTest::testWithLocal()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
3
namespace Evheniy\JqueryBundle\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\JqueryBundle\DependencyInjection\JqueryExtension;
9
10
/**
11
 * Class JqueryExtensionTest
12
 *
13
 * @package Evheniy\JqueryBundle\Tests\DependencyInjection
14
 */
15
class JqueryExtensionTest extends \PHPUnit_Framework_TestCase
16
{
17
    /**
18
     * @var JqueryExtension
19
     */
20
    private $extension;
21
    /**
22
     * @var ContainerBuilder
23
     */
24
    private $container;
25
26
    /**
27
     *
28
     */
29
    protected function setUp()
30
    {
31
        $this->extension = new JqueryExtension();
32
33
        $this->container = new ContainerBuilder();
34
        $this->container->registerExtension($this->extension);
35
    }
36
37
    /**
38
     * @param ContainerBuilder $container
39
     * @param string           $resource
40
     */
41
    protected function loadConfiguration(ContainerBuilder $container, $resource)
42
    {
43
        $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/Fixtures/'));
44
        $loader->load($resource . '.yml');
45
    }
46
47
    /**
48
     * Test empty config
49
     */
50
    public function testWithoutConfiguration()
51
    {
52
        $this->container->loadFromExtension($this->extension->getAlias());
53
        $this->container->compile();
54
        $this->assertTrue($this->container->hasParameter('jquery'));
55
        $jquery = $this->container->getParameter('jquery');
56
        $this->assertNotEmpty($jquery['local']);
57
        $this->assertEquals($jquery['local'], '@JqueryBundle/Resources/public/js/jquery-1.11.3.min.js');
58
    }
59
60
    /**
61
     * Test normal config
62
     */
63
    public function testWithLocal()
64
    {
65
        $this->loadConfiguration($this->container, 'withLocal');
66
        $this->container->compile();
67
68
        $this->assertTrue($this->container->hasParameter('jquery'));
69
        $jquery = $this->container->getParameter('jquery');
70
        $this->assertNotEmpty($jquery['local']);
71
        $this->assertEquals($jquery['local'], 'jquery-1.11.3.min.js');
72
        $this->assertTrue($this->container->hasParameter('jquery.local'));
73
        $this->assertEquals($this->container->getParameter('jquery.local'), 'jquery-1.11.3.min.js');
74
    }
75
76
    /**
77
     * Test normal config
78
     */
79
    public function testTest()
80
    {
81
        $this->loadConfiguration($this->container, 'test');
82
        $this->container->compile();
83
84
        $this->assertTrue($this->container->hasParameter('jquery'));
85
        $this->assertTrue($this->container->hasParameter('jquery.local'));
86
        $jquery = $this->container->getParameter('jquery');
87
        $this->assertNotEmpty($jquery['local']);
88
        $this->assertEquals($jquery['local'], 'jquery-1.11.0.min.js');
89
        $this->assertEquals($this->container->getParameter('jquery.local'), 'jquery-1.11.0.min.js');
90
        $this->assertFalse($jquery['html5']);
91
        $this->assertTrue($jquery['async']);
92
        $this->assertNotEmpty($jquery['cdn']);
93
        $this->assertEquals($jquery['cdn'], '//cdn.site.com');
94
    }
95
96
    /**
97
     * Test wrong config
98
     */
99
    public function testWithOutLocal()
100
    {
101
        $this->loadConfiguration($this->container, 'withOutLocal');
102
        $this->container->compile();
103
        $this->assertTrue($this->container->hasParameter('jquery'));
104
        $jquery = $this->container->getParameter('jquery');
105
        $this->assertNotEmpty($jquery['local']);
106
        $this->assertEquals($jquery['local'], '@JqueryBundle/Resources/public/js/jquery-1.11.3.min.js');
107
        $this->assertEmpty($jquery['cdn']);
108
        $this->assertEquals($jquery['cdn'], '');
109
    }
110
}
111