DefaultControllerTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 8
dl 0
loc 41
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getTwig() 0 15 1
A testWithCdn() 0 6 1
A testWithOutCdn() 0 6 1
1
<?php
2
namespace Evheniy\TwitterBootstrapBundle\Tests\Controller;
3
4
use Assetic\Extension\Twig\AsseticExtension;
5
use Assetic\Factory\AssetFactory;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Evheniy\TwitterBootstrapBundle\Twig\TwitterBootstrapExtension;
8
use Evheniy\TwitterBootstrapBundle\DependencyInjection\TwitterBootstrapExtension as TwitterBootstrapExtensionDI;
9
10
/**
11
 * Class DefaultControllerTest
12
 *
13
 * @package Evheniy\TwitterBootstrapBundle\Tests\Controller
14
 */
15
class DefaultControllerTest extends \PHPUnit_Framework_TestCase
16
{
17
    /**
18
     *
19
     */
20
    protected function getTwig(array $data)
21
    {
22
        $twig = new \Twig_Environment(
23
            new \Twig_Loader_Array(
24
                array('TwitterBootstrapBundle:TwitterBootstrap:js.html.twig' => file_get_contents(dirname(__FILE__) . '/../../Resources/views/TwitterBootstrap/js.html.twig'))
25
            )
26
        );
27
        $container = new ContainerBuilder();
28
        $extension = new TwitterBootstrapExtensionDI();
29
        $extension->load($data, $container);
30
        $twig ->addExtension(new AsseticExtension(new AssetFactory(dirname(__FILE__) . '/')));
31
        $twig ->addExtension(new TwitterBootstrapExtension($container));
32
33
        return $twig;
34
    }
35
36
    /**
37
     *
38
     */
39
    public function testWithCdn()
40
    {
41
        $html = $this->getTwig(array(array('local_cdn' => 'cdn.site.com')))->render('TwitterBootstrapBundle:TwitterBootstrap:js.html.twig');
42
        $this->assertRegExp('/href\=\"\/\/cdn\.site\.comcss\/bootstrap\.css\"/', $html);
43
        $this->assertRegExp('/src\=\"\/\/cdn\.site\.comjs\/bootstrap.js\"/', $html);
44
    }
45
46
    /**
47
     *
48
     */
49
    public function testWithOutCdn()
50
    {
51
        $html = $this->getTwig(array(array()))->render('TwitterBootstrapBundle:TwitterBootstrap:js.html.twig');
52
        $this->assertRegExp('/href\=\"css\/bootstrap\.css\"/', $html);
53
        $this->assertRegExp('/src\=\"js\/bootstrap.js\"/', $html);
54
    }
55
}