12
12
namespace Symfony \Component \CssSelector \Tests \XPath ;
13
13
14
14
use PHPUnit \Framework \TestCase ;
15
+ use Symfony \Component \CssSelector \Exception \ExpressionErrorException ;
16
+ use Symfony \Component \CssSelector \Node \ElementNode ;
17
+ use Symfony \Component \CssSelector \Node \FunctionNode ;
18
+ use Symfony \Component \CssSelector \Parser \Parser ;
15
19
use Symfony \Component \CssSelector \XPath \Extension \HtmlExtension ;
16
20
use Symfony \Component \CssSelector \XPath \Translator ;
21
+ use Symfony \Component \CssSelector \XPath \XPathExpr ;
17
22
18
23
class TranslatorTest extends TestCase
19
24
{
@@ -31,6 +36,61 @@ public function testCssToXPath($css, $xpath)
31
36
$ this ->assertEquals ($ xpath , $ translator ->cssToXPath ($ css , '' ));
32
37
}
33
38
39
+ public function testCssToXPathPseudoElement ()
40
+ {
41
+ $ translator = new Translator ();
42
+ $ translator ->registerExtension (new HtmlExtension ($ translator ));
43
+ $ this ->expectException (ExpressionErrorException::class);
44
+ $ translator ->cssToXPath ('e::first-line ' );
45
+ }
46
+
47
+ public function testGetExtensionNotExistsExtension ()
48
+ {
49
+ $ translator = new Translator ();
50
+ $ translator ->registerExtension (new HtmlExtension ($ translator ));
51
+ $ this ->expectException (ExpressionErrorException::class);
52
+ $ translator ->getExtension ('fake ' );
53
+ }
54
+
55
+ public function testAddCombinationNotExistsExtension ()
56
+ {
57
+ $ translator = new Translator ();
58
+ $ translator ->registerExtension (new HtmlExtension ($ translator ));
59
+ $ this ->expectException (ExpressionErrorException::class);
60
+ $ parser = new Parser ();
61
+ $ xpath = $ parser ->parse ('* ' )[0 ];
62
+ $ combinedXpath = $ parser ->parse ('* ' )[0 ];
63
+ $ translator ->addCombination ('fake ' , $ xpath , $ combinedXpath );
64
+ }
65
+
66
+ public function testAddFunctionNotExistsFunction ()
67
+ {
68
+ $ translator = new Translator ();
69
+ $ translator ->registerExtension (new HtmlExtension ($ translator ));
70
+ $ xpath = new XPathExpr ();
71
+ $ function = new FunctionNode (new ElementNode (), 'fake ' );
72
+ $ this ->expectException (ExpressionErrorException::class);
73
+ $ translator ->addFunction ($ xpath , $ function );
74
+ }
75
+
76
+ public function testAddPseudoClassNotExistsClass ()
77
+ {
78
+ $ translator = new Translator ();
79
+ $ translator ->registerExtension (new HtmlExtension ($ translator ));
80
+ $ xpath = new XPathExpr ();
81
+ $ this ->expectException (ExpressionErrorException::class);
82
+ $ translator ->addPseudoClass ($ xpath , 'fake ' );
83
+ }
84
+
85
+ public function testAddAttributeMatchingClassNotExistsClass ()
86
+ {
87
+ $ translator = new Translator ();
88
+ $ translator ->registerExtension (new HtmlExtension ($ translator ));
89
+ $ xpath = new XPathExpr ();
90
+ $ this ->expectException (ExpressionErrorException::class);
91
+ $ translator ->addAttributeMatching ($ xpath , '' , '' , '' );
92
+ }
93
+
34
94
/** @dataProvider getXmlLangTestData */
35
95
public function testXmlLang ($ css , array $ elementsId )
36
96
{
0 commit comments