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\PseudoNode ;
use Symfony\Component\CssSelector\Node\ElementNode ;
2010-03-31 07:42:18 +01:00
class PseudoNodeTest extends \PHPUnit_Framework_TestCase
{
2010-05-06 12:25:53 +01:00
public function testToXpath ()
{
$element = new ElementNode ( '*' , 'h1' );
// h1:checked
$pseudo = new PseudoNode ( $element , ':' , 'checked' );
$this -> assertEquals ( " h1[(@selected or @checked) and (name(.) = 'input' or name(.) = 'option')] " , ( string ) $pseudo -> toXpath (), '->toXpath() returns the xpath representation of the node' );
// h1:first-child
$pseudo = new PseudoNode ( $element , ':' , 'first-child' );
$this -> assertEquals ( " */*[name() = 'h1' and (position() = 1)] " , ( string ) $pseudo -> toXpath (), '->toXpath() returns the xpath representation of the node' );
// h1:last-child
$pseudo = new PseudoNode ( $element , ':' , 'last-child' );
$this -> assertEquals ( " */*[name() = 'h1' and (position() = last())] " , ( string ) $pseudo -> toXpath (), '->toXpath() returns the xpath representation of the node' );
// h1:first-of-type
$pseudo = new PseudoNode ( $element , ':' , 'first-of-type' );
$this -> assertEquals ( " */h1[position() = 1] " , ( string ) $pseudo -> toXpath (), '->toXpath() returns the xpath representation of the node' );
// h1:last-of-type
$pseudo = new PseudoNode ( $element , ':' , 'last-of-type' );
$this -> assertEquals ( " */h1[position() = last()] " , ( string ) $pseudo -> toXpath (), '->toXpath() returns the xpath representation of the node' );
// h1:only-child
$pseudo = new PseudoNode ( $element , ':' , 'only-child' );
$this -> assertEquals ( " */*[name() = 'h1' and (last() = 1)] " , ( string ) $pseudo -> toXpath (), '->toXpath() returns the xpath representation of the node' );
// h1:only-of-type
$pseudo = new PseudoNode ( $element , ':' , 'only-of-type' );
$this -> assertEquals ( " h1[last() = 1] " , ( string ) $pseudo -> toXpath (), '->toXpath() returns the xpath representation of the node' );
// h1:empty
$pseudo = new PseudoNode ( $element , ':' , 'empty' );
$this -> assertEquals ( " h1[not(*) and not(normalize-space())] " , ( string ) $pseudo -> toXpath (), '->toXpath() returns the xpath representation of the node' );
}
2010-03-31 07:42:18 +01:00
}