ImageTest.php 1.3 KB

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