1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NerdsAndCompany\Schematic\Converters\Models; |
4
|
|
|
|
5
|
|
|
use Craft; |
6
|
|
|
use craft\models\AssetTransform as AssetTransformModel; |
7
|
|
|
use Codeception\Test\Unit; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class AssetTransformTest. |
11
|
|
|
* |
12
|
|
|
* @author Nerds & Company |
13
|
|
|
* @copyright Copyright (c) 2015-2017, Nerds & Company |
14
|
|
|
* @license MIT |
15
|
|
|
* |
16
|
|
|
* @see http://www.nerds.company |
17
|
|
|
*/ |
18
|
|
|
class AssetTransformTest extends Unit |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var AssetTransforms |
22
|
|
|
*/ |
23
|
|
|
private $converter; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Set the converter. |
27
|
|
|
* |
28
|
|
|
* @SuppressWarnings(PHPMD.CamelCaseMethodName) |
29
|
|
|
*/ |
30
|
|
|
protected function _before() |
31
|
|
|
{ |
32
|
|
|
$this->converter = new AssetTransform(); |
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
//============================================================================================================== |
36
|
|
|
//================================================= TESTS ==================================================== |
37
|
|
|
//============================================================================================================== |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @dataProvider provideAssetTransforms |
41
|
|
|
* |
42
|
|
|
* @param AssetTransformModel $transform |
43
|
|
|
* @param array $definition |
44
|
|
|
*/ |
45
|
|
|
public function testGetRecordDefinition(AssetTransformModel $transform, array $definition) |
46
|
|
|
{ |
47
|
|
|
$result = $this->converter->getRecordDefinition($transform); |
48
|
|
|
|
49
|
|
|
$this->assertSame($definition, $result); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @dataProvider provideAssetTransforms |
54
|
|
|
* |
55
|
|
|
* @param AssetTransformModel $transform |
56
|
|
|
* @param array $definition |
57
|
|
|
*/ |
58
|
|
|
public function testSaveRecord(AssetTransformModel $transform, array $definition) |
59
|
|
|
{ |
60
|
|
|
Craft::$app->assetTransforms->expects($this->exactly(1)) |
61
|
|
|
->method('saveTransform') |
62
|
|
|
->with($transform) |
63
|
|
|
->willReturn(true); |
64
|
|
|
|
65
|
|
|
$result = $this->converter->saveRecord($transform, $definition); |
66
|
|
|
|
67
|
|
|
$this->assertTrue($result); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @dataProvider provideAssetTransforms |
72
|
|
|
* |
73
|
|
|
* @param AssetTransformModel $transform |
74
|
|
|
*/ |
75
|
|
|
public function testDeleteRecord(AssetTransformModel $transform) |
76
|
|
|
{ |
77
|
|
|
Craft::$app->assetTransforms->expects($this->exactly(1)) |
78
|
|
|
->method('deleteTransform') |
79
|
|
|
->with($transform->id); |
80
|
|
|
|
81
|
|
|
$this->converter->deleteRecord($transform); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
//============================================================================================================== |
85
|
|
|
//============================================== PROVIDERS =================================================== |
86
|
|
|
//============================================================================================================== |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return array |
90
|
|
|
*/ |
91
|
|
|
public function provideAssetTransforms() |
92
|
|
|
{ |
93
|
|
|
$mockAssetTransform = $this->getMockAssetTransform(1); |
94
|
|
|
|
95
|
|
|
return [ |
96
|
|
|
'valid transform existing group' => [ |
97
|
|
|
'transform' => $mockAssetTransform, |
98
|
|
|
'definition' => $this->getMockAssetTransformDefinition($mockAssetTransform), |
99
|
|
|
], |
100
|
|
|
]; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
//============================================================================================================== |
104
|
|
|
//================================================ HELPERS =================================================== |
105
|
|
|
//============================================================================================================== |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @param int $assetTransformId |
109
|
|
|
* |
110
|
|
|
* @return AssetTransformModel |
111
|
|
|
*/ |
112
|
|
|
private function getMockAssetTransform(int $assetTransformId) |
113
|
|
|
{ |
114
|
|
|
return new AssetTransformModel([ |
115
|
|
|
'id' => $assetTransformId, |
116
|
|
|
'handle' => 'assetTransformHandle'.$assetTransformId, |
117
|
|
|
'name' => 'assetTransformName'.$assetTransformId, |
118
|
|
|
]); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @param AssetTransformModel $assetTransform |
123
|
|
|
* |
124
|
|
|
* @return array |
125
|
|
|
*/ |
126
|
|
|
private function getMockAssetTransformDefinition(AssetTransformModel $assetTransform) |
127
|
|
|
{ |
128
|
|
|
return [ |
129
|
|
|
'class' => get_class($assetTransform), |
130
|
|
|
'attributes' => [ |
131
|
|
|
'name' => 'assetTransformName'.$assetTransform->id, |
132
|
|
|
'handle' => 'assetTransformHandle'.$assetTransform->id, |
133
|
|
|
'width' => null, |
134
|
|
|
'height' => null, |
135
|
|
|
'format' => null, |
136
|
|
|
'mode' => 'crop', |
137
|
|
|
'position' => 'center-center', |
138
|
|
|
'interlace' => 'none', |
139
|
|
|
'quality' => null, |
140
|
|
|
], |
141
|
|
|
]; |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..