1212namespace Symfony \Component \CssSelector \Tests \XPath ;
1313
1414use PHPUnit \Framework \TestCase ;
15+ use Symfony \Component \CssSelector \Node \ElementNode ;
16+ use Symfony \Component \CssSelector \Node \FunctionNode ;
17+ use Symfony \Component \CssSelector \Parser \Parser ;
1518use Symfony \Component \CssSelector \XPath \Extension \HtmlExtension ;
1619use Symfony \Component \CssSelector \XPath \Translator ;
20+ use Symfony \Component \CssSelector \XPath \XPathExpr ;
1721
1822class TranslatorTest extends TestCase
1923{
@@ -31,6 +35,73 @@ public function testCssToXPath($css, $xpath)
3135 $ this ->assertEquals ($ xpath , $ translator ->cssToXPath ($ css , '' ));
3236 }
3337
38+ /**
39+ * @expectedException \Symfony\Component\CssSelector\Exception\ExpressionErrorException
40+ */
41+ public function testCssToXPathPseudoElement ()
42+ {
43+ $ translator = new Translator ();
44+ $ translator ->registerExtension (new HtmlExtension ($ translator ));
45+ $ translator ->cssToXPath ('e::first-line ' );
46+ }
47+
48+ /**
49+ * @expectedException \Symfony\Component\CssSelector\Exception\ExpressionErrorException
50+ */
51+ public function testGetExtensionNotExistsExtension ()
52+ {
53+ $ translator = new Translator ();
54+ $ translator ->registerExtension (new HtmlExtension ($ translator ));
55+ $ translator ->getExtension ('fake ' );
56+ }
57+
58+ /**
59+ * @expectedException \Symfony\Component\CssSelector\Exception\ExpressionErrorException
60+ */
61+ public function testAddCombinationNotExistsExtension ()
62+ {
63+ $ translator = new Translator ();
64+ $ translator ->registerExtension (new HtmlExtension ($ translator ));
65+ $ parser = new Parser ();
66+ $ xpath = $ parser ->parse ('* ' )[0 ];
67+ $ combinedXpath = $ parser ->parse ('* ' )[0 ];
68+ $ translator ->addCombination ('fake ' , $ xpath , $ combinedXpath );
69+ }
70+
71+ /**
72+ * @expectedException \Symfony\Component\CssSelector\Exception\ExpressionErrorException
73+ */
74+ public function testAddFunctionNotExistsFunction ()
75+ {
76+ $ translator = new Translator ();
77+ $ translator ->registerExtension (new HtmlExtension ($ translator ));
78+ $ xpath = new XPathExpr ();
79+ $ function = new FunctionNode (new ElementNode (), 'fake ' );
80+ $ translator ->addFunction ($ xpath , $ function );
81+ }
82+
83+ /**
84+ * @expectedException \Symfony\Component\CssSelector\Exception\ExpressionErrorException
85+ */
86+ public function testAddPseudoClassNotExistsClass ()
87+ {
88+ $ translator = new Translator ();
89+ $ translator ->registerExtension (new HtmlExtension ($ translator ));
90+ $ xpath = new XPathExpr ();
91+ $ translator ->addPseudoClass ($ xpath , 'fake ' );
92+ }
93+
94+ /**
95+ * @expectedException \Symfony\Component\CssSelector\Exception\ExpressionErrorException
96+ */
97+ public function testAddAttributeMatchingClassNotExistsClass ()
98+ {
99+ $ translator = new Translator ();
100+ $ translator ->registerExtension (new HtmlExtension ($ translator ));
101+ $ xpath = new XPathExpr ();
102+ $ translator ->addAttributeMatching ($ xpath , '' , '' , '' );
103+ }
104+
34105 /** @dataProvider getXmlLangTestData */
35106 public function testXmlLang ($ css , array $ elementsId )
36107 {
0 commit comments