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 11parameters:
22 ignoreErrors:
33 - '~^Call to an undefined method FluentDOM\\DOM\\Node\\.+?::getNodePath\(\)\.$~'
4- - '~^Cannot cast FluentDOM\\DOM\\Node\\.+? to string\.$~'
54 - '~^Cannot call method (end|([a-z]+)Node)\(\) on Symfony\\Component\\Config\\Definition\\Builder\\NodeParentInterface\|null\.$~'
65 - '~^Service "csa_guzzle\.mock\.storage" is not registered in the container\.$~'
76 level: max
Original file line number Diff line number Diff line change 77use FluentDOM ;
88use FluentDOM \DOM \Document ;
99use FluentDOM \DOM \Element ;
10+ use FluentDOM \DOM \Node \NonDocumentTypeChildNode ;
1011
1112trait XmlTestCase
1213{
@@ -23,4 +24,9 @@ final protected function loadElement(string $xml) : Element
2324 {
2425 return $ this ->loadDocument ($ xml )->documentElement ;
2526 }
27+
28+ final protected function loadNode (string $ xml ) : NonDocumentTypeChildNode
29+ {
30+ return $ this ->loadElement ("<root> $ xml</root> " )[0 ];
31+ }
2632}
Original file line number Diff line number Diff line change 44
55namespace Libero \ViewsBundle \Views ;
66
7+ use FluentDOM \DOM \CdataSection ;
78use FluentDOM \DOM \Element ;
89use FluentDOM \DOM \Node \NonDocumentTypeChildNode ;
10+ use FluentDOM \DOM \Text ;
911use Libero \ViewsBundle \Event \BuildViewEvent ;
1012use LogicException ;
1113use Symfony \Component \EventDispatcher \EventDispatcherInterface ;
@@ -29,6 +31,10 @@ public function convert(NonDocumentTypeChildNode $node, ?string $template = null
2931 );
3032 }
3133
34+ if (!$ node instanceof Text && !$ node instanceof CdataSection) {
35+ return new View ('@LiberoPatterns/text.html.twig ' , ['nodes ' => '' ], $ context );
36+ }
37+
3238 return new View ('@LiberoPatterns/text.html.twig ' , ['nodes ' => (string ) $ node ], $ context );
3339 }
3440
Original file line number Diff line number Diff line change @@ -46,6 +46,29 @@ public function it_returns_text_by_default() : void
4646 $ this ->assertEquals ($ expected , $ handler ->convert ($ node ));
4747 }
4848
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+
4972 /**
5073 * @test
5174 */
You can’t perform that action at this time.
0 commit comments