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
|
|
|
use Ivoaz\Bundle\ContentEditableBundle\Twig\ContentEditableTokenParser; |
16
|
|
|
|
17
|
|
|
class ContentEditableTokenParserTest extends \PHPUnit_Framework_TestCase |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @dataProvider getCompileTestData |
21
|
|
|
* |
22
|
|
|
* @param ContentEditableNode $expectedNode |
23
|
|
|
* @param string $source |
24
|
|
|
* @param string $message |
25
|
|
|
*/ |
26
|
|
|
public function testCompile(ContentEditableNode $expectedNode, $source, $message = '') |
27
|
|
|
{ |
28
|
|
|
$env = new \Twig_Environment( |
29
|
|
|
$this->getMock('Twig_LoaderInterface'), |
|
|
|
|
30
|
|
|
['cache' => false, 'autoescape' => false, 'optimizations' => 0] |
31
|
|
|
); |
32
|
|
|
$env->addTokenParser(new ContentEditableTokenParser()); |
33
|
|
|
$parser = new \Twig_Parser($env); |
34
|
|
|
|
35
|
|
|
$stream = $env->tokenize($source); |
36
|
|
|
$node = $parser->parse($stream) |
37
|
|
|
->getNode('body') |
38
|
|
|
->getNode(0); |
39
|
|
|
|
40
|
|
|
$this->assertEquals($expectedNode, $node, $message); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return array |
45
|
|
|
*/ |
46
|
|
|
public function getCompileTestData() |
47
|
|
|
{ |
48
|
|
|
return [ |
49
|
|
|
[ |
50
|
|
|
new ContentEditableNode( |
51
|
|
|
['body' => new \Twig_Node_Text('Text', 1)], |
52
|
|
|
['name' => 'name', 'options' => []], |
53
|
|
|
1, |
54
|
|
|
'contenteditable' |
55
|
|
|
), |
56
|
|
|
'{% contenteditable "name" %}Text{% endcontenteditable %}', |
57
|
|
|
], |
58
|
|
|
[ |
59
|
|
|
new ContentEditableNode( |
60
|
|
|
['body' => new \Twig_Node_Text('Text', 1)], |
61
|
|
|
[ |
62
|
|
|
'name' => 'name', |
63
|
|
|
'options' => [ |
64
|
|
|
'test_string' => 'string', |
65
|
|
|
'test_number' => 0, |
66
|
|
|
'test_true' => true, |
67
|
|
|
'test_false' => false, |
68
|
|
|
'test_enabled' => true, |
69
|
|
|
], |
70
|
|
|
], |
71
|
|
|
1, |
72
|
|
|
'contenteditable' |
73
|
|
|
), |
74
|
|
|
'{% contenteditable "name" test_string="string" test_number=0 test_true=true test_false=false test_enabled %}Text{% endcontenteditable %}', |
75
|
|
|
], |
76
|
|
|
]; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.