Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / symfony / css-selector / Tests / CssSelectorConverterTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\CssSelector\Tests;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\CssSelector\CssSelectorConverter;
16
17 class CssSelectorConverterTest extends TestCase
18 {
19     public function testCssToXPath()
20     {
21         $converter = new CssSelectorConverter();
22
23         $this->assertEquals('descendant-or-self::*', $converter->toXPath(''));
24         $this->assertEquals('descendant-or-self::h1', $converter->toXPath('h1'));
25         $this->assertEquals("descendant-or-self::h1[@id = 'foo']", $converter->toXPath('h1#foo'));
26         $this->assertEquals("descendant-or-self::h1[@class and contains(concat(' ', normalize-space(@class), ' '), ' foo ')]", $converter->toXPath('h1.foo'));
27         $this->assertEquals('descendant-or-self::foo:h1', $converter->toXPath('foo|h1'));
28         $this->assertEquals('descendant-or-self::h1', $converter->toXPath('H1'));
29     }
30
31     public function testCssToXPathXml()
32     {
33         $converter = new CssSelectorConverter(false);
34
35         $this->assertEquals('descendant-or-self::H1', $converter->toXPath('H1'));
36     }
37
38     /**
39      * @expectedException \Symfony\Component\CssSelector\Exception\ParseException
40      * @expectedExceptionMessage Expected identifier, but <eof at 3> found.
41      */
42     public function testParseExceptions()
43     {
44         $converter = new CssSelectorConverter();
45         $converter->toXPath('h1:');
46     }
47
48     /** @dataProvider getCssToXPathWithoutPrefixTestData */
49     public function testCssToXPathWithoutPrefix($css, $xpath)
50     {
51         $converter = new CssSelectorConverter();
52
53         $this->assertEquals($xpath, $converter->toXPath($css, ''), '->parse() parses an input string and returns a node');
54     }
55
56     public function getCssToXPathWithoutPrefixTestData()
57     {
58         return array(
59             array('h1', 'h1'),
60             array('foo|h1', 'foo:h1'),
61             array('h1, h2, h3', 'h1 | h2 | h3'),
62             array('h1:nth-child(3n+1)', "*/*[(name() = 'h1') and (position() - 1 >= 0 and (position() - 1) mod 3 = 0)]"),
63             array('h1 > p', 'h1/p'),
64             array('h1#foo', "h1[@id = 'foo']"),
65             array('h1.foo', "h1[@class and contains(concat(' ', normalize-space(@class), ' '), ' foo ')]"),
66             array('h1[class*="foo bar"]', "h1[@class and contains(@class, 'foo bar')]"),
67             array('h1[foo|class*="foo bar"]', "h1[@foo:class and contains(@foo:class, 'foo bar')]"),
68             array('h1[class]', 'h1[@class]'),
69             array('h1 .foo', "h1/descendant-or-self::*/*[@class and contains(concat(' ', normalize-space(@class), ' '), ' foo ')]"),
70             array('h1 #foo', "h1/descendant-or-self::*/*[@id = 'foo']"),
71             array('h1 [class*=foo]', "h1/descendant-or-self::*/*[@class and contains(@class, 'foo')]"),
72             array('div>.foo', "div/*[@class and contains(concat(' ', normalize-space(@class), ' '), ' foo ')]"),
73             array('div > .foo', "div/*[@class and contains(concat(' ', normalize-space(@class), ' '), ' foo ')]"),
74         );
75     }
76 }