ImageTest.php 1.3 KB

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