You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.3KB

  1. <?php
  2. namespace Faker\Test\Provider;
  3. use Faker\Provider\Image;
  4. class ImageTest extends \PHPUnit_Framework_TestCase
  5. {
  6. public function testUrlWithDefaults()
  7. {
  8. $this->assertEquals(Image::imageUrl(), 'http://lorempixel.com/640/480/');
  9. }
  10. public function testUrlWithDimensions()
  11. {
  12. $this->assertEquals(Image::imageUrl(800, 400), 'http://lorempixel.com/800/400/');
  13. }
  14. public function testUrlWithDimensionsAndCategory()
  15. {
  16. $this->assertEquals(Image::imageUrl(800, 400, 'nature'), 'http://lorempixel.com/800/400/nature/');
  17. }
  18. /**
  19. * @expectedException \InvalidArgumentException
  20. */
  21. public function testUrlWithDimensionsAndBadCategory()
  22. {
  23. Image::imageUrl(800, 400, 'bullhonky');
  24. }
  25. public function testDownloadWithDefaults()
  26. {
  27. $file = Image::image(sys_get_temp_dir());
  28. $this->assertFileExists($file);
  29. if (function_exists('getimagesize')) {
  30. list($width, $height, $type, $attr) = getimagesize($file);
  31. $this->assertEquals(640, $width);
  32. $this->assertEquals(480, $height);
  33. $this->assertEquals(constant('IMAGETYPE_JPEG'), $type);
  34. } else {
  35. $this->assertEquals('jpg', pathinfo($file, PATHINFO_EXTENSION));
  36. }
  37. if (file_exists($file)) {
  38. unlink($file);
  39. }
  40. }
  41. }