CrawlerSelectorTextSameTest.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\DomCrawler\Tests\Test\Constraint;
  11. use PHPUnit\Framework\ExpectationFailedException;
  12. use PHPUnit\Framework\TestCase;
  13. use PHPUnit\Framework\TestFailure;
  14. use Symfony\Component\DomCrawler\Crawler;
  15. use Symfony\Component\DomCrawler\Test\Constraint\CrawlerSelectorTextSame;
  16. class CrawlerSelectorTextSameTest extends TestCase
  17. {
  18. public function testConstraint(): void
  19. {
  20. $constraint = new CrawlerSelectorTextSame('title', 'Foo');
  21. $this->assertTrue($constraint->evaluate(new Crawler('<html><head><title>Foo'), '', true));
  22. $this->assertFalse($constraint->evaluate(new Crawler('<html><head><title>Bar'), '', true));
  23. try {
  24. $constraint->evaluate(new Crawler('<html><head><title>Bar'));
  25. } catch (ExpectationFailedException $e) {
  26. $this->assertEquals("Failed asserting that the Crawler has a node matching selector \"title\" with content \"Foo\".\n", TestFailure::exceptionToString($e));
  27. return;
  28. }
  29. $this->fail();
  30. }
  31. }