Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Gd2Test.php
Go to the documentation of this file.
1 <?php
7 
9 
13 class Gd2Test extends \PHPUnit\Framework\TestCase
14 {
20  public static $memoryLimit;
21 
25  public static $imageData = [];
26 
31  protected $adapter;
32 
36  protected $objectManager;
37 
41  protected function setUp()
42  {
43  require_once __DIR__ . '/_files/global_php_mock.php';
44  $this->objectManager = new ObjectManager($this);
45  $this->adapter = $this->objectManager->getObject(\Magento\Framework\Image\Adapter\Gd2::class);
46  }
47 
51  public function testParentClass()
52  {
53  $this->assertInstanceOf(\Magento\Framework\Image\Adapter\AbstractAdapter::class, $this->adapter);
54  }
55 
64  public function testOpen($fileData, $exception, $limit)
65  {
66  self::$memoryLimit = $limit;
67  self::$imageData = $fileData;
68 
69  if (!empty($exception)) {
70  $this->expectException($exception);
71  }
72 
73  $this->adapter->open('file');
74  }
75 
79  public function filesProvider()
80  {
81  $smallFile = [
82  0 => 480,
83  1 => 320,
84  2 => 2,
85  3 => 'width="480" height="320"',
86  'bits' => 8,
87  'channels' => 3,
88  'mime' => 'image/jpeg',
89  ];
90 
91  $bigFile = [
92  0 => 3579,
93  1 => 2398,
94  2 => 2,
95  3 => 'width="3579" height="2398"',
96  'bits' => 8,
97  'channels' => 3,
98  'mime' => 'image/jpeg',
99  ];
100 
101  return [
102  'positive_M' => [$smallFile, false, '2M'],
103  'positive_KB' => [$smallFile, false, '2048K'],
104  'negative_KB' => [$bigFile, 'OverflowException', '2048K'],
105  'negative_bytes' => [$bigFile, 'OverflowException', '2048000'],
106  'no_limit' => [$bigFile, false, '-1'],
107  ];
108  }
109 
114  public function testOpenDifferentTypes()
115  {
116  self::$imageData = [
117  0 => 480,
118  1 => 320,
119  2 => 2,
120  3 => 'width="480" height="320"',
121  'bits' => 8,
122  'channels' => 3,
123  'mime' => 'image/jpeg',
124  ];
125 
126  $this->adapter->open('file');
127  $type1 = $this->adapter->getImageType();
128 
129  self::$imageData = [
130  0 => 480,
131  1 => 320,
132  2 => 3,
133  3 => 'width="480" height="320"',
134  'bits' => 8,
135  'channels' => 3,
136  'mime' => 'image/png',
137  ];
138 
139  $this->adapter->open('file');
140  $type2 = $this->adapter->getImageType();
141 
142  $this->assertNotEquals($type1, $type2);
143  }
144 }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
testOpen($fileData, $exception, $limit)
Definition: Gd2Test.php:64