2010-03-31 07:42:18 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2010-04-25 16:06:54 +01:00
|
|
|
* This file is part of the Symfony package.
|
2010-03-31 07:42:18 +01:00
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2010-03-31 07:42:18 +01:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2010-08-20 22:09:55 +01:00
|
|
|
namespace Symfony\Tests\Component\CssSelector\Node;
|
2010-03-31 07:42:18 +01:00
|
|
|
|
2010-08-20 22:09:55 +01:00
|
|
|
use Symfony\Component\CssSelector\Node\AttribNode;
|
|
|
|
use Symfony\Component\CssSelector\Node\ElementNode;
|
2010-03-31 07:42:18 +01:00
|
|
|
|
|
|
|
class AttribNodeTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
2010-05-06 12:25:53 +01:00
|
|
|
public function testToXpath()
|
|
|
|
{
|
|
|
|
$element = new ElementNode('*', 'h1');
|
2010-03-31 07:42:18 +01:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
$operators = array(
|
|
|
|
'^=' => "h1[starts-with(@class, 'foo')]",
|
|
|
|
'$=' => "h1[substring(@class, string-length(@class)-2) = 'foo']",
|
|
|
|
'*=' => "h1[contains(@class, 'foo')]",
|
|
|
|
'=' => "h1[@class = 'foo']",
|
|
|
|
'~=' => "h1[contains(concat(' ', normalize-space(@class), ' '), ' foo ')]",
|
|
|
|
'|=' => "h1[@class = 'foo' or starts-with(@class, 'foo-')]",
|
|
|
|
'!=' => "h1[not(@class) or @class != 'foo']",
|
|
|
|
);
|
2010-03-31 07:42:18 +01:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
// h1[class??foo]
|
2010-05-07 15:09:11 +01:00
|
|
|
foreach ($operators as $op => $xpath) {
|
2010-05-06 12:25:53 +01:00
|
|
|
$attrib = new AttribNode($element, '*', 'class', $op, 'foo');
|
|
|
|
$this->assertEquals($xpath, (string) $attrib->toXpath(), '->toXpath() returns the xpath representation of the node');
|
|
|
|
}
|
2010-03-31 07:42:18 +01:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
// h1[class]
|
|
|
|
$attrib = new AttribNode($element, '*', 'class', 'exists', 'foo');
|
|
|
|
$this->assertEquals('h1[@class]', (string) $attrib->toXpath(), '->toXpath() returns the xpath representation of the node');
|
|
|
|
}
|
2010-03-31 07:42:18 +01:00
|
|
|
}
|