Skip to content

Commit

Permalink
minor #29798 Component CssSelector tests (vladis84)
Browse files Browse the repository at this point in the history
This PR was submitted for the master branch but it was merged into the 3.4 branch instead (closes #29798).

Discussion
----------

Component CssSelector tests

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no
| Tests pass?   | yes
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

<!--
Write a short README entry for your feature/bugfix here (replace this comment block.)
This will help people understand your PR and can be used as a start of the Doc PR.
Additionally:
 - Bug fixes must be submitted against the lowest branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too).
 - Features and deprecations must be submitted against the master branch.
-->

Commits
-------

c7410be Component CssSelector tests
  • Loading branch information
fabpot committed Jan 13, 2019
2 parents ea68e28 + c7410be commit b06967e
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/Symfony/Component/CssSelector/Tests/XPath/TranslatorTest.php
Expand Up @@ -12,8 +12,13 @@
namespace Symfony\Component\CssSelector\Tests\XPath;

use PHPUnit\Framework\TestCase;
use Symfony\Component\CssSelector\Exception\ExpressionErrorException;
use Symfony\Component\CssSelector\Node\ElementNode;
use Symfony\Component\CssSelector\Node\FunctionNode;
use Symfony\Component\CssSelector\Parser\Parser;
use Symfony\Component\CssSelector\XPath\Extension\HtmlExtension;
use Symfony\Component\CssSelector\XPath\Translator;
use Symfony\Component\CssSelector\XPath\XPathExpr;

class TranslatorTest extends TestCase
{
Expand All @@ -31,6 +36,61 @@ public function testCssToXPath($css, $xpath)
$this->assertEquals($xpath, $translator->cssToXPath($css, ''));
}

public function testCssToXPathPseudoElement()
{
$translator = new Translator();
$translator->registerExtension(new HtmlExtension($translator));
$this->expectException(ExpressionErrorException::class);
$translator->cssToXPath('e::first-line');
}

public function testGetExtensionNotExistsExtension()
{
$translator = new Translator();
$translator->registerExtension(new HtmlExtension($translator));
$this->expectException(ExpressionErrorException::class);
$translator->getExtension('fake');
}

public function testAddCombinationNotExistsExtension()
{
$translator = new Translator();
$translator->registerExtension(new HtmlExtension($translator));
$this->expectException(ExpressionErrorException::class);
$parser = new Parser();
$xpath = $parser->parse('*')[0];
$combinedXpath = $parser->parse('*')[0];
$translator->addCombination('fake', $xpath, $combinedXpath);
}

public function testAddFunctionNotExistsFunction()
{
$translator = new Translator();
$translator->registerExtension(new HtmlExtension($translator));
$xpath = new XPathExpr();
$function = new FunctionNode(new ElementNode(), 'fake');
$this->expectException(ExpressionErrorException::class);
$translator->addFunction($xpath, $function);
}

public function testAddPseudoClassNotExistsClass()
{
$translator = new Translator();
$translator->registerExtension(new HtmlExtension($translator));
$xpath = new XPathExpr();
$this->expectException(ExpressionErrorException::class);
$translator->addPseudoClass($xpath, 'fake');
}

public function testAddAttributeMatchingClassNotExistsClass()
{
$translator = new Translator();
$translator->registerExtension(new HtmlExtension($translator));
$xpath = new XPathExpr();
$this->expectException(ExpressionErrorException::class);
$translator->addAttributeMatching($xpath, '', '', '');
}

/** @dataProvider getXmlLangTestData */
public function testXmlLang($css, array $elementsId)
{
Expand Down

0 comments on commit b06967e

Please sign in to comment.