This repository was archived by the owner on Nov 21, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +35
-1
lines changed Expand file tree Collapse file tree 4 files changed +35
-1
lines changed Original file line number Diff line number Diff line change 1
1
parameters:
2
2
ignoreErrors:
3
3
- '~^Call to an undefined method FluentDOM\\DOM\\Node\\.+?::getNodePath\(\)\.$~'
4
- - '~^Cannot cast FluentDOM\\DOM\\Node\\.+? to string\.$~'
5
4
- '~^Cannot call method (end|([a-z]+)Node)\(\) on Symfony\\Component\\Config\\Definition\\Builder\\NodeParentInterface\|null\.$~'
6
5
- '~^Service "csa_guzzle\.mock\.storage" is not registered in the container\.$~'
7
6
level: max
Original file line number Diff line number Diff line change 7
7
use FluentDOM ;
8
8
use FluentDOM \DOM \Document ;
9
9
use FluentDOM \DOM \Element ;
10
+ use FluentDOM \DOM \Node \NonDocumentTypeChildNode ;
10
11
11
12
trait XmlTestCase
12
13
{
@@ -23,4 +24,9 @@ final protected function loadElement(string $xml) : Element
23
24
{
24
25
return $ this ->loadDocument ($ xml )->documentElement ;
25
26
}
27
+
28
+ final protected function loadNode (string $ xml ) : NonDocumentTypeChildNode
29
+ {
30
+ return $ this ->loadElement ("<root> $ xml</root> " )[0 ];
31
+ }
26
32
}
Original file line number Diff line number Diff line change 4
4
5
5
namespace Libero \ViewsBundle \Views ;
6
6
7
+ use FluentDOM \DOM \CdataSection ;
7
8
use FluentDOM \DOM \Element ;
8
9
use FluentDOM \DOM \Node \NonDocumentTypeChildNode ;
10
+ use FluentDOM \DOM \Text ;
9
11
use Libero \ViewsBundle \Event \BuildViewEvent ;
10
12
use LogicException ;
11
13
use Symfony \Component \EventDispatcher \EventDispatcherInterface ;
@@ -29,6 +31,10 @@ public function convert(NonDocumentTypeChildNode $node, ?string $template = null
29
31
);
30
32
}
31
33
34
+ if (!$ node instanceof Text && !$ node instanceof CdataSection) {
35
+ return new View ('@LiberoPatterns/text.html.twig ' , ['nodes ' => '' ], $ context );
36
+ }
37
+
32
38
return new View ('@LiberoPatterns/text.html.twig ' , ['nodes ' => (string ) $ node ], $ context );
33
39
}
34
40
Original file line number Diff line number Diff line change @@ -46,6 +46,29 @@ public function it_returns_text_by_default() : void
46
46
$ this ->assertEquals ($ expected , $ handler ->convert ($ node ));
47
47
}
48
48
49
+ /**
50
+ * @test
51
+ * @dataProvider nonElementProvider
52
+ */
53
+ public function it_handles_non_elements (string $ node , $ expected = '' ) : void
54
+ {
55
+ $ handler = new EventDispatchingViewConverter (new EventDispatcher ());
56
+
57
+ $ node = $ this ->loadNode ($ node );
58
+
59
+ $ expected = new View ('@LiberoPatterns/text.html.twig ' , ['nodes ' => $ expected ]);
60
+
61
+ $ this ->assertEquals ($ expected , $ handler ->convert ($ node ));
62
+ }
63
+
64
+ public function nonElementProvider () : iterable
65
+ {
66
+ yield 'cdata ' => ['<![CDATA[<cdata>]]> ' , '<cdata> ' ];
67
+ yield 'comment ' => ['<!--comment--> ' ];
68
+ yield 'processing instruction ' => ['<?processing instruction?> ' ];
69
+ yield 'text ' => ['text ' , 'text ' ];
70
+ }
71
+
49
72
/**
50
73
* @test
51
74
*/
You can’t perform that action at this time.
0 commit comments