Blame view

vendor/fzaninotto/faker/test/Faker/Provider/ImageTest.php 1.84 KB
ad2e91f7   Mihail   move multyparser ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
  <?php
  
  namespace Faker\Test\Provider;
  
  use Faker\Provider\Image;
  
  class ImageTest extends \PHPUnit_Framework_TestCase
  {
      public function testImageUrlUses640x680AsTheDefaultSize()
      {
          $this->assertRegExp('#^http://lorempixel.com/640/480/#', Image::imageUrl());
      }
  
      public function testImageUrlAcceptsCustomWidthAndHeight()
      {
          $this->assertRegExp('#^http://lorempixel.com/800/400/#', Image::imageUrl(800, 400));
      }
  
      public function testImageUrlAcceptsCustomCategory()
      {
          $this->assertRegExp('#^http://lorempixel.com/800/400/nature/#', Image::imageUrl(800, 400, 'nature'));
      }
  
      public function testImageUrlAcceptsCustomText()
      {
          $this->assertRegExp('#^http://lorempixel.com/800/400/nature/Faker#', Image::imageUrl(800, 400, 'nature', false, 'Faker'));
      }
  
      public function testImageUrlAddsARandomGetParameterByDefault()
      {
          $url = Image::imageUrl(800, 400);
          $splitUrl = preg_split('/\?/', $url);
  
          $this->assertEquals(count($splitUrl), 2);
          $this->assertRegexp('#\d{5}#', $splitUrl[1]);
      }
  
      /**
       * @expectedException \InvalidArgumentException
       */
      public function testUrlWithDimensionsAndBadCategory()
      {
          Image::imageUrl(800, 400, 'bullhonky');
      }
  
      public function testDownloadWithDefaults()
      {
          $file = Image::image(sys_get_temp_dir());
          $this->assertFileExists($file);
          if (function_exists('getimagesize')) {
              list($width, $height, $type, $attr) = getimagesize($file);
              $this->assertEquals(640, $width);
              $this->assertEquals(480, $height);
              $this->assertEquals(constant('IMAGETYPE_JPEG'), $type);
          } else {
              $this->assertEquals('jpg', pathinfo($file, PATHINFO_EXTENSION));
          }
          if (file_exists($file)) {
              unlink($file);
          }
      }
  }