ContentEditableNodeTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 6
dl 0
loc 50
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testCompile() 0 8 1
A getCompileTestData() 0 17 1
1
<?php
2
3
/*
4
 * This file is part of the Ivoaz ContentEditable bundle.
5
 *
6
 * (c) Ivo Azirjans <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Ivoaz\Bundle\ContentEditableBundle\Tests\Twig;
13
14
use Ivoaz\Bundle\ContentEditableBundle\Twig\ContentEditableNode;
15
16
class ContentEditableNodeTest extends \PHPUnit_Framework_TestCase
17
{
18
    /**
19
     * @var \Twig_Compiler
20
     */
21
    private $compiler;
22
23
    public function setUp()
24
    {
25
        $this->compiler = new \Twig_Compiler(new \Twig_Environment(new \Twig_Loader_Array([])));
26
    }
27
28
    /**
29
     * @dataProvider getCompileTestData
30
     *
31
     * @param string $expectedSource
32
     * @param array  $nodes
33
     * @param array  $attributes
34
     * @param string $message
35
     */
36
    public function testCompile($expectedSource, $nodes, $attributes, $message = '')
37
    {
38
        $node = new ContentEditableNode($nodes, $attributes);
39
40
        $node->compile($this->compiler);
41
42
        $this->assertSame($expectedSource, $this->compiler->getSource(), $message);
43
    }
44
45
    /**
46
     * @return array
47
     */
48
    public function getCompileTestData()
49
    {
50
        return [
51
            [
52
                'echo $this->env->getExtension(\'ivoaz_content_editable\')->render("","name",array());',
53
                ['body' => new \Twig_Node_Text('', 0)],
54
                ['name' => 'name', 'options' => []],
55
                'The text and options should be compiled empty.'
56
            ],
57
            [
58
                'echo $this->env->getExtension(\'ivoaz_content_editable\')->render("text","name",array("locale" => "en", "test_option" => "test"));',
59
                ['body' => new \Twig_Node_Text('text', 0)],
60
                ['name' => 'name', 'options' => ['locale' => 'en', 'test_option' => 'test']],
61
                'The text and options should be compiled.'
62
            ],
63
        ];
64
    }
65
}
66