/vendor/symfony/css-selector/Tests/Parser/Handler/AbstractHandlerTest.php |
@@ -0,0 +1,70 @@ |
<?php |
|
/* |
* This file is part of the Symfony package. |
* |
* (c) Fabien Potencier <fabien@symfony.com> |
* |
* For the full copyright and license information, please view the LICENSE |
* file that was distributed with this source code. |
*/ |
|
namespace Symfony\Component\CssSelector\Tests\Parser\Handler; |
|
use PHPUnit\Framework\TestCase; |
use Symfony\Component\CssSelector\Parser\Reader; |
use Symfony\Component\CssSelector\Parser\Token; |
use Symfony\Component\CssSelector\Parser\TokenStream; |
|
/** |
* @author Jean-François Simon <contact@jfsimon.fr> |
*/ |
abstract class AbstractHandlerTest extends TestCase |
{ |
/** @dataProvider getHandleValueTestData */ |
public function testHandleValue($value, Token $expectedToken, $remainingContent) |
{ |
$reader = new Reader($value); |
$stream = new TokenStream(); |
|
$this->assertTrue($this->generateHandler()->handle($reader, $stream)); |
$this->assertEquals($expectedToken, $stream->getNext()); |
$this->assertRemainingContent($reader, $remainingContent); |
} |
|
/** @dataProvider getDontHandleValueTestData */ |
public function testDontHandleValue($value) |
{ |
$reader = new Reader($value); |
$stream = new TokenStream(); |
|
$this->assertFalse($this->generateHandler()->handle($reader, $stream)); |
$this->assertStreamEmpty($stream); |
$this->assertRemainingContent($reader, $value); |
} |
|
abstract public function getHandleValueTestData(); |
|
abstract public function getDontHandleValueTestData(); |
|
abstract protected function generateHandler(); |
|
protected function assertStreamEmpty(TokenStream $stream) |
{ |
$property = new \ReflectionProperty($stream, 'tokens'); |
$property->setAccessible(true); |
|
$this->assertEquals(array(), $property->getValue($stream)); |
} |
|
protected function assertRemainingContent(Reader $reader, $remainingContent) |
{ |
if ('' === $remainingContent) { |
$this->assertEquals(0, $reader->getRemainingLength()); |
$this->assertTrue($reader->isEOF()); |
} else { |
$this->assertEquals(strlen($remainingContent), $reader->getRemainingLength()); |
$this->assertEquals(0, $reader->getOffset($remainingContent)); |
} |
} |
} |
/vendor/symfony/css-selector/Tests/Parser/Handler/CommentHandlerTest.php |
@@ -0,0 +1,55 @@ |
<?php |
|
/* |
* This file is part of the Symfony package. |
* |
* (c) Fabien Potencier <fabien@symfony.com> |
* |
* For the full copyright and license information, please view the LICENSE |
* file that was distributed with this source code. |
*/ |
|
namespace Symfony\Component\CssSelector\Tests\Parser\Handler; |
|
use Symfony\Component\CssSelector\Parser\Handler\CommentHandler; |
use Symfony\Component\CssSelector\Parser\Reader; |
use Symfony\Component\CssSelector\Parser\Token; |
use Symfony\Component\CssSelector\Parser\TokenStream; |
|
class CommentHandlerTest extends AbstractHandlerTest |
{ |
/** @dataProvider getHandleValueTestData */ |
public function testHandleValue($value, Token $unusedArgument, $remainingContent) |
{ |
$reader = new Reader($value); |
$stream = new TokenStream(); |
|
$this->assertTrue($this->generateHandler()->handle($reader, $stream)); |
// comments are ignored (not pushed as token in stream) |
$this->assertStreamEmpty($stream); |
$this->assertRemainingContent($reader, $remainingContent); |
} |
|
public function getHandleValueTestData() |
{ |
return array( |
// 2nd argument only exists for inherited method compatibility |
array('/* comment */', new Token(null, null, null), ''), |
array('/* comment */foo', new Token(null, null, null), 'foo'), |
); |
} |
|
public function getDontHandleValueTestData() |
{ |
return array( |
array('>'), |
array('+'), |
array(' '), |
); |
} |
|
protected function generateHandler() |
{ |
return new CommentHandler(); |
} |
} |
/vendor/symfony/css-selector/Tests/Parser/Handler/HashHandlerTest.php |
@@ -0,0 +1,49 @@ |
<?php |
|
/* |
* This file is part of the Symfony package. |
* |
* (c) Fabien Potencier <fabien@symfony.com> |
* |
* For the full copyright and license information, please view the LICENSE |
* file that was distributed with this source code. |
*/ |
|
namespace Symfony\Component\CssSelector\Tests\Parser\Handler; |
|
use Symfony\Component\CssSelector\Parser\Handler\HashHandler; |
use Symfony\Component\CssSelector\Parser\Token; |
use Symfony\Component\CssSelector\Parser\Tokenizer\TokenizerPatterns; |
use Symfony\Component\CssSelector\Parser\Tokenizer\TokenizerEscaping; |
|
class HashHandlerTest extends AbstractHandlerTest |
{ |
public function getHandleValueTestData() |
{ |
return array( |
array('#id', new Token(Token::TYPE_HASH, 'id', 0), ''), |
array('#123', new Token(Token::TYPE_HASH, '123', 0), ''), |
|
array('#id.class', new Token(Token::TYPE_HASH, 'id', 0), '.class'), |
array('#id element', new Token(Token::TYPE_HASH, 'id', 0), ' element'), |
); |
} |
|
public function getDontHandleValueTestData() |
{ |
return array( |
array('id'), |
array('123'), |
array('<'), |
array('<'), |
array('#'), |
); |
} |
|
protected function generateHandler() |
{ |
$patterns = new TokenizerPatterns(); |
|
return new HashHandler($patterns, new TokenizerEscaping($patterns)); |
} |
} |
/vendor/symfony/css-selector/Tests/Parser/Handler/IdentifierHandlerTest.php |
@@ -0,0 +1,49 @@ |
<?php |
|
/* |
* This file is part of the Symfony package. |
* |
* (c) Fabien Potencier <fabien@symfony.com> |
* |
* For the full copyright and license information, please view the LICENSE |
* file that was distributed with this source code. |
*/ |
|
namespace Symfony\Component\CssSelector\Tests\Parser\Handler; |
|
use Symfony\Component\CssSelector\Parser\Handler\IdentifierHandler; |
use Symfony\Component\CssSelector\Parser\Token; |
use Symfony\Component\CssSelector\Parser\Tokenizer\TokenizerPatterns; |
use Symfony\Component\CssSelector\Parser\Tokenizer\TokenizerEscaping; |
|
class IdentifierHandlerTest extends AbstractHandlerTest |
{ |
public function getHandleValueTestData() |
{ |
return array( |
array('foo', new Token(Token::TYPE_IDENTIFIER, 'foo', 0), ''), |
array('foo|bar', new Token(Token::TYPE_IDENTIFIER, 'foo', 0), '|bar'), |
array('foo.class', new Token(Token::TYPE_IDENTIFIER, 'foo', 0), '.class'), |
array('foo[attr]', new Token(Token::TYPE_IDENTIFIER, 'foo', 0), '[attr]'), |
array('foo bar', new Token(Token::TYPE_IDENTIFIER, 'foo', 0), ' bar'), |
); |
} |
|
public function getDontHandleValueTestData() |
{ |
return array( |
array('>'), |
array('+'), |
array(' '), |
array('*|foo'), |
array('/* comment */'), |
); |
} |
|
protected function generateHandler() |
{ |
$patterns = new TokenizerPatterns(); |
|
return new IdentifierHandler($patterns, new TokenizerEscaping($patterns)); |
} |
} |
/vendor/symfony/css-selector/Tests/Parser/Handler/NumberHandlerTest.php |
@@ -0,0 +1,50 @@ |
<?php |
|
/* |
* This file is part of the Symfony package. |
* |
* (c) Fabien Potencier <fabien@symfony.com> |
* |
* For the full copyright and license information, please view the LICENSE |
* file that was distributed with this source code. |
*/ |
|
namespace Symfony\Component\CssSelector\Tests\Parser\Handler; |
|
use Symfony\Component\CssSelector\Parser\Handler\NumberHandler; |
use Symfony\Component\CssSelector\Parser\Token; |
use Symfony\Component\CssSelector\Parser\Tokenizer\TokenizerPatterns; |
|
class NumberHandlerTest extends AbstractHandlerTest |
{ |
public function getHandleValueTestData() |
{ |
return array( |
array('12', new Token(Token::TYPE_NUMBER, '12', 0), ''), |
array('12.34', new Token(Token::TYPE_NUMBER, '12.34', 0), ''), |
array('+12.34', new Token(Token::TYPE_NUMBER, '+12.34', 0), ''), |
array('-12.34', new Token(Token::TYPE_NUMBER, '-12.34', 0), ''), |
|
array('12 arg', new Token(Token::TYPE_NUMBER, '12', 0), ' arg'), |
array('12]', new Token(Token::TYPE_NUMBER, '12', 0), ']'), |
); |
} |
|
public function getDontHandleValueTestData() |
{ |
return array( |
array('hello'), |
array('>'), |
array('+'), |
array(' '), |
array('/* comment */'), |
); |
} |
|
protected function generateHandler() |
{ |
$patterns = new TokenizerPatterns(); |
|
return new NumberHandler($patterns); |
} |
} |
/vendor/symfony/css-selector/Tests/Parser/Handler/StringHandlerTest.php |
@@ -0,0 +1,50 @@ |
<?php |
|
/* |
* This file is part of the Symfony package. |
* |
* (c) Fabien Potencier <fabien@symfony.com> |
* |
* For the full copyright and license information, please view the LICENSE |
* file that was distributed with this source code. |
*/ |
|
namespace Symfony\Component\CssSelector\Tests\Parser\Handler; |
|
use Symfony\Component\CssSelector\Parser\Handler\StringHandler; |
use Symfony\Component\CssSelector\Parser\Token; |
use Symfony\Component\CssSelector\Parser\Tokenizer\TokenizerPatterns; |
use Symfony\Component\CssSelector\Parser\Tokenizer\TokenizerEscaping; |
|
class StringHandlerTest extends AbstractHandlerTest |
{ |
public function getHandleValueTestData() |
{ |
return array( |
array('"hello"', new Token(Token::TYPE_STRING, 'hello', 1), ''), |
array('"1"', new Token(Token::TYPE_STRING, '1', 1), ''), |
array('" "', new Token(Token::TYPE_STRING, ' ', 1), ''), |
array('""', new Token(Token::TYPE_STRING, '', 1), ''), |
array("'hello'", new Token(Token::TYPE_STRING, 'hello', 1), ''), |
|
array("'foo'bar", new Token(Token::TYPE_STRING, 'foo', 1), 'bar'), |
); |
} |
|
public function getDontHandleValueTestData() |
{ |
return array( |
array('hello'), |
array('>'), |
array('1'), |
array(' '), |
); |
} |
|
protected function generateHandler() |
{ |
$patterns = new TokenizerPatterns(); |
|
return new StringHandler($patterns, new TokenizerEscaping($patterns)); |
} |
} |
/vendor/symfony/css-selector/Tests/Parser/Handler/WhitespaceHandlerTest.php |
@@ -0,0 +1,44 @@ |
<?php |
|
/* |
* This file is part of the Symfony package. |
* |
* (c) Fabien Potencier <fabien@symfony.com> |
* |
* For the full copyright and license information, please view the LICENSE |
* file that was distributed with this source code. |
*/ |
|
namespace Symfony\Component\CssSelector\Tests\Parser\Handler; |
|
use Symfony\Component\CssSelector\Parser\Handler\WhitespaceHandler; |
use Symfony\Component\CssSelector\Parser\Token; |
|
class WhitespaceHandlerTest extends AbstractHandlerTest |
{ |
public function getHandleValueTestData() |
{ |
return array( |
array(' ', new Token(Token::TYPE_WHITESPACE, ' ', 0), ''), |
array("\n", new Token(Token::TYPE_WHITESPACE, "\n", 0), ''), |
array("\t", new Token(Token::TYPE_WHITESPACE, "\t", 0), ''), |
|
array(' foo', new Token(Token::TYPE_WHITESPACE, ' ', 0), 'foo'), |
array(' .foo', new Token(Token::TYPE_WHITESPACE, ' ', 0), '.foo'), |
); |
} |
|
public function getDontHandleValueTestData() |
{ |
return array( |
array('>'), |
array('1'), |
array('a'), |
); |
} |
|
protected function generateHandler() |
{ |
return new WhitespaceHandler(); |
} |
} |