b374k
m1n1 1.01
Apache/2.4.41 (Ubuntu)
Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64
uid=33(www-data) gid=33(www-data) groups=33(www-data)
server ip : 62.171.164.128 | your ip : 127.0.0.1
safemode OFF
 >  / home / a / home / dev2.destoffenstraat.com / vendor / magento / framework / Image / Test / Unit / Adapter /
Filename/home/a/home/dev2.destoffenstraat.com/vendor/magento/framework/Image/Test/Unit/Adapter/Gd2Test.php
Size3.73 kb
Permissionrw-r--r--
Ownerroot : root
Create time21-Aug-2025 12:26
Last modified07-Jan-2021 21:08
Last accessed23-Aug-2025 11:51
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\Framework\Image\Test\Unit\Adapter;

use Magento\Framework\Image\Adapter\AbstractAdapter;
use Magento\Framework\Image\Adapter\Gd2;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use PHPUnit\Framework\TestCase;

/**
* \Magento\Framework\Image\Adapter\Gd2 class test
*/
class Gd2Test extends TestCase
{
/**
* Value to mock ini_get('memory_limit')
*
* @var string
*/
public static $memoryLimit;

/**
* @var array simulation of getimagesize()
*/
public static $imageData = [];

/**
* Simulation of filesize() function
*
* @var int
*/
public static $imageSize = 1;

/**
* Adapter for testing
* @var Gd2
*/
protected $adapter;

/**
* @var ObjectManager
*/
protected $objectManager;

/**
* Setup testing object
*/
protected function setUp(): void
{
require_once __DIR__ . '/_files/global_php_mock.php';
$this->objectManager = new ObjectManager($this);
$this->adapter = $this->objectManager->getObject(Gd2::class);
}

/**
* Test parent class
*/
public function testParentClass()
{
$this->assertInstanceOf(AbstractAdapter::class, $this->adapter);
}

/**
* Test open() method
*
* @param array $fileData
* @param string|bool|null $exception
* @param string $limit
* @dataProvider filesProvider
*/
public function testOpen($fileData, $exception, $limit)
{
self::$memoryLimit = $limit;
self::$imageData = $fileData;

if (!empty($exception)) {
$this->expectException($exception);
}

$this->adapter->open('file');
}

/**
* @return array
*/
public function filesProvider()
{
$smallFile = [
0 => 480,
1 => 320,
2 => 2,
3 => 'width="480" height="320"',
'bits' => 8,
'channels' => 3,
'mime' => 'image/jpeg',
];

$bigFile = [
0 => 3579,
1 => 2398,
2 => 2,
3 => 'width="3579" height="2398"',
'bits' => 8,
'channels' => 3,
'mime' => 'image/jpeg',
];

return [
'positive_M' => [$smallFile, false, '2M'],
'positive_KB' => [$smallFile, false, '2048K'],
'negative_KB' => [$bigFile, 'OverflowException', '2048K'],
'negative_bytes' => [$bigFile, 'OverflowException', '2048000'],
'no_limit' => [$bigFile, false, '-1'],
];
}

/**
* Test if open() method resets cached fileType
*/
public function testOpenDifferentTypes()
{
self::$imageData = [
0 => 480,
1 => 320,
2 => 2,
3 => 'width="480" height="320"',
'bits' => 8,
'channels' => 3,
'mime' => 'image/jpeg',
];

$this->adapter->open('file');
$type1 = $this->adapter->getImageType();

self::$imageData = [
0 => 480,
1 => 320,
2 => 3,
3 => 'width="480" height="320"',
'bits' => 8,
'channels' => 3,
'mime' => 'image/png',
];

$this->adapter->open('file');
$type2 = $this->adapter->getImageType();

$this->assertNotEquals($type1, $type2);
}

/**
* Test open() with invalid URL.
*/
public function testOpenInvalidURL()
{
$this->expectException(\InvalidArgumentException::class);

$this->adapter->open('bar://foo.bar');
}
}