Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2559ba7

Browse filesBrowse files
committed
synchronize tests for static and non-static API
Synchronizing the classes ensures that no tests are lost when the legacy API is removed in symfony#16020 for Symfony 3.0, thus mitigating the risk of future regressions.
1 parent 1309cfb commit 2559ba7
Copy full SHA for 2559ba7

File tree

Expand file treeCollapse file tree

1 file changed

+42
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+42
-0
lines changed

‎src/Symfony/Component/CssSelector/Tests/CssSelectorConverterTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/CssSelector/Tests/CssSelectorConverterTest.php
+42Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,46 @@ public function testCssToXPathXml()
3333

3434
$this->assertEquals('descendant-or-self::H1', $converter->toXPath('H1'));
3535
}
36+
37+
public function testParseExceptions()
38+
{
39+
$converter = new CssSelectorConverter();
40+
41+
try {
42+
$converter->toXPath('h1:');
43+
$this->fail('->parse() throws an Exception if the css selector is not valid');
44+
} catch (\Exception $e) {
45+
$this->assertInstanceOf('\Symfony\Component\CssSelector\Exception\ParseException', $e, '->parse() throws an Exception if the css selector is not valid');
46+
$this->assertEquals('Expected identifier, but <eof at 3> found.', $e->getMessage(), '->parse() throws an Exception if the css selector is not valid');
47+
}
48+
}
49+
50+
/** @dataProvider getCssToXPathWithoutPrefixTestData */
51+
public function testCssToXPathWithoutPrefix($css, $xpath)
52+
{
53+
$converter = new CssSelectorConverter();
54+
55+
$this->assertEquals($xpath, $converter->toXPath($css, ''), '->parse() parses an input string and returns a node');
56+
}
57+
58+
public function getCssToXPathWithoutPrefixTestData()
59+
{
60+
return array(
61+
array('h1', 'h1'),
62+
array('foo|h1', 'foo:h1'),
63+
array('h1, h2, h3', 'h1 | h2 | h3'),
64+
array('h1:nth-child(3n+1)', "*/*[name() = 'h1' and (position() - 1 >= 0 and (position() - 1) mod 3 = 0)]"),
65+
array('h1 > p', 'h1/p'),
66+
array('h1#foo', "h1[@id = 'foo']"),
67+
array('h1.foo', "h1[@class and contains(concat(' ', normalize-space(@class), ' '), ' foo ')]"),
68+
array('h1[class*="foo bar"]', "h1[@class and contains(@class, 'foo bar')]"),
69+
array('h1[foo|class*="foo bar"]', "h1[@foo:class and contains(@foo:class, 'foo bar')]"),
70+
array('h1[class]', 'h1[@class]'),
71+
array('h1 .foo', "h1/descendant-or-self::*/*[@class and contains(concat(' ', normalize-space(@class), ' '), ' foo ')]"),
72+
array('h1 #foo', "h1/descendant-or-self::*/*[@id = 'foo']"),
73+
array('h1 [class*=foo]', "h1/descendant-or-self::*/*[@class and contains(@class, 'foo')]"),
74+
array('div>.foo', "div/*[@class and contains(concat(' ', normalize-space(@class), ' '), ' foo ')]"),
75+
array('div > .foo', "div/*[@class and contains(concat(' ', normalize-space(@class), ' '), ' foo ')]"),
76+
);
77+
}
3678
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.