ImageTest.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\DomCrawler\Image;
  13. class ImageTest extends TestCase
  14. {
  15. /**
  16. * @expectedException \LogicException
  17. */
  18. public function testConstructorWithANonImgTag()
  19. {
  20. $dom = new \DOMDocument();
  21. $dom->loadHTML('<html><div><div></html>');
  22. new Image($dom->getElementsByTagName('div')->item(0), 'http://www.example.com/');
  23. }
  24. /**
  25. * @dataProvider getGetUriTests
  26. */
  27. public function testGetUri($url, $currentUri, $expected)
  28. {
  29. $dom = new \DOMDocument();
  30. $dom->loadHTML(sprintf('<html><img alt="foo" src="%s" /></html>', $url));
  31. $image = new Image($dom->getElementsByTagName('img')->item(0), $currentUri);
  32. $this->assertEquals($expected, $image->getUri());
  33. }
  34. public function getGetUriTests()
  35. {
  36. return [
  37. ['/foo.png', 'http://localhost/bar/foo/', 'http://localhost/foo.png'],
  38. ['foo.png', 'http://localhost/bar/foo/', 'http://localhost/bar/foo/foo.png'],
  39. ];
  40. }
  41. }