1212namespace Symfony \Component \CssSelector \Tests \XPath ;
1313
1414use 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 ;
1519use Symfony \Component \CssSelector \XPath \Extension \HtmlExtension ;
1620use Symfony \Component \CssSelector \XPath \Translator ;
21+ use Symfony \Component \CssSelector \XPath \XPathExpr ;
1722
1823class TranslatorTest extends TestCase
1924{
@@ -31,6 +36,61 @@ public function testCssToXPath($css, $xpath)
3136 $ this ->assertEquals ($ xpath , $ translator ->cssToXPath ($ css , '' ));
3237 }
3338
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+
3494 /** @dataProvider getXmlLangTestData */
3595 public function testXmlLang ($ css , array $ elementsId )
3696 {
0 commit comments