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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* Test class for \Magento\Framework\Image\Adapter\AbstractAdapter.
*/
namespace Magento\Framework\Image\Test\Unit\Adapter;
class AbstractTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Framework\Image\Adapter\AbstractAdapter
*/
protected $_model;
/**
* @var \PHPUnit_Framework_MockObject_MockObject |\Magento\Framework\Filesystem\Directory\Write
*/
protected $directoryWriteMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject |\Magento\Framework\Filesystem
*/
protected $filesystemMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject |\Psr\Log\LoggerInterface
*/
protected $loggerMock;
protected function setUp()
{
$this->directoryWriteMock = $this->createMock(\Magento\Framework\Filesystem\Directory\Write::class);
$this->filesystemMock =
$this->createPartialMock(\Magento\Framework\Filesystem::class, ['getDirectoryWrite', 'createDirectory']);
$this->filesystemMock->expects(
$this->once()
)->method(
'getDirectoryWrite'
)->will(
$this->returnValue($this->directoryWriteMock)
);
$this->loggerMock = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
$this->_model = $this->getMockForAbstractClass(
\Magento\Framework\Image\Adapter\AbstractAdapter::class,
[$this->filesystemMock, $this->loggerMock]
);
}
protected function tearDown()
{
$this->directoryWriteMock = null;
$this->_model = null;
$this->filesystemMock = null;
$this->loggerMock = null;
}
/**
* Test adaptResizeValues with null as a value one of parameters
*
* @dataProvider adaptResizeValuesDataProvider
*/
public function testAdaptResizeValues($width, $height, $expectedResult)
{
$method = new \ReflectionMethod($this->_model, '_adaptResizeValues');
$method->setAccessible(true);
$result = $method->invoke($this->_model, $width, $height);
$this->assertEquals($expectedResult, $result);
}
/**
* @return array
*/
public function adaptResizeValuesDataProvider()
{
$expected = [
'src' => ['x' => 0, 'y' => 0],
'dst' => ['x' => 0, 'y' => 0, 'width' => 135, 'height' => 135],
'frame' => ['width' => 135, 'height' => 135],
];
return [[135, null, $expected], [null, 135, $expected]];
}
/**
* @dataProvider prepareDestinationDataProvider
*/
public function testPrepareDestination($destination, $newName, $expectedResult)
{
$property = new \ReflectionProperty(get_class($this->_model), '_fileSrcPath');
$property->setAccessible(true);
$property->setValue($this->_model, '_fileSrcPath');
$property = new \ReflectionProperty(get_class($this->_model), '_fileSrcName');
$property->setAccessible(true);
$property->setValue($this->_model, '_fileSrcName');
$method = new \ReflectionMethod($this->_model, '_prepareDestination');
$method->setAccessible(true);
$result = $method->invoke($this->_model, $destination, $newName);
$this->assertEquals($expectedResult, $result);
}
/**
* @return array
*/
public function prepareDestinationDataProvider()
{
return [
[__DIR__, 'name.txt', __DIR__ . '/name.txt'],
[__DIR__ . '/name.txt', null, __DIR__ . '/name.txt'],
[null, 'name.txt', '_fileSrcPath' . '/name.txt'],
[null, null, '_fileSrcPath' . '/_fileSrcName']
];
}
}