|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
5
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
6
|
|
|
*/ |
|
7
|
|
|
declare(strict_types=1); |
|
8
|
|
|
|
|
9
|
|
|
namespace eZ\Bundle\EzPublishCoreBundle\Tests\Imagine\ImageAsset; |
|
10
|
|
|
|
|
11
|
|
|
use eZ\Bundle\EzPublishCoreBundle\Imagine\ImageAsset\AliasGenerator; |
|
12
|
|
|
use eZ\Publish\API\Repository\ContentService; |
|
13
|
|
|
use eZ\Publish\API\Repository\Values\Content\Field; |
|
14
|
|
|
use eZ\Publish\Core\FieldType\ImageAsset; |
|
15
|
|
|
use eZ\Publish\Core\FieldType\Image; |
|
16
|
|
|
use eZ\Publish\Core\Repository\Values\Content\Content; |
|
17
|
|
|
use eZ\Publish\Core\Repository\Values\Content\VersionInfo; |
|
18
|
|
|
use eZ\Publish\SPI\Variation\Values\Variation; |
|
19
|
|
|
use eZ\Publish\SPI\Variation\VariationHandler; |
|
20
|
|
|
use PHPUnit\Framework\TestCase; |
|
21
|
|
|
|
|
22
|
|
|
class AliasGeneratorTest extends TestCase |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var \eZ\Bundle\EzPublishCoreBundle\Imagine\ImageAsset\AliasGenerator |
|
26
|
|
|
*/ |
|
27
|
|
|
private $aliasGenerator; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var \eZ\Publish\SPI\Variation\VariationHandler|\PHPUnit_Framework_MockObject_MockObject |
|
31
|
|
|
*/ |
|
32
|
|
|
private $innerAliasGenerator; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var \eZ\Publish\API\Repository\ContentService|\PHPUnit_Framework_MockObject_MockObject |
|
36
|
|
|
*/ |
|
37
|
|
|
private $contentService; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var \eZ\Publish\Core\FieldType\ImageAsset\AssetMapper|\PHPUnit_Framework_MockObject_MockObject |
|
41
|
|
|
*/ |
|
42
|
|
|
private $assetMapper; |
|
43
|
|
|
|
|
44
|
|
|
protected function setUp() |
|
45
|
|
|
{ |
|
46
|
|
|
$this->innerAliasGenerator = $this->createMock(VariationHandler::class); |
|
47
|
|
|
$this->contentService = $this->createMock(ContentService::class); |
|
48
|
|
|
$this->assetMapper = $this->createMock(ImageAsset\AssetMapper::class); |
|
49
|
|
|
|
|
50
|
|
|
$this->aliasGenerator = new AliasGenerator( |
|
51
|
|
|
$this->innerAliasGenerator, |
|
52
|
|
|
$this->contentService, |
|
53
|
|
|
$this->assetMapper |
|
54
|
|
|
); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function testGetVariationOfImageAsset() |
|
58
|
|
|
{ |
|
59
|
|
|
$assetField = new Field([ |
|
60
|
|
|
'value' => new ImageAsset\Value([ |
|
61
|
|
|
'destinationContentId' => 486, |
|
62
|
|
|
]), |
|
63
|
|
|
]); |
|
64
|
|
|
$imageField = new Field([ |
|
65
|
|
|
'value' => new Image\Value([ |
|
66
|
|
|
'id' => 'images/6/8/4/0/486-10-eng-GB/photo.jpg', |
|
67
|
|
|
]), |
|
68
|
|
|
]); |
|
69
|
|
|
|
|
70
|
|
|
$assetVersionInfo = new VersionInfo(); |
|
71
|
|
|
$imageVersionInfo = new VersionInfo(); |
|
72
|
|
|
$imageContent = new Content([ |
|
73
|
|
|
'versionInfo' => $imageVersionInfo, |
|
74
|
|
|
]); |
|
75
|
|
|
|
|
76
|
|
|
$variationName = 'thumbnail'; |
|
77
|
|
|
$parameters = []; |
|
78
|
|
|
|
|
79
|
|
|
$expectedVariation = new Variation(); |
|
80
|
|
|
|
|
81
|
|
|
$this->contentService |
|
82
|
|
|
->expects($this->once()) |
|
83
|
|
|
->method('loadContent') |
|
84
|
|
|
->with($assetField->value->destinationContentId) |
|
85
|
|
|
->willReturn($imageContent); |
|
86
|
|
|
|
|
87
|
|
|
$this->assetMapper |
|
88
|
|
|
->expects($this->once()) |
|
89
|
|
|
->method('getAssetField') |
|
90
|
|
|
->with($imageContent) |
|
91
|
|
|
->willReturn($imageField); |
|
92
|
|
|
|
|
93
|
|
|
$this->innerAliasGenerator |
|
94
|
|
|
->expects($this->once()) |
|
95
|
|
|
->method('getVariation') |
|
96
|
|
|
->with($imageField, $imageVersionInfo, $variationName, $parameters) |
|
97
|
|
|
->willReturn($expectedVariation); |
|
98
|
|
|
|
|
99
|
|
|
$actualVariation = $this->aliasGenerator->getVariation( |
|
100
|
|
|
$assetField, |
|
101
|
|
|
$assetVersionInfo, |
|
102
|
|
|
$variationName, |
|
103
|
|
|
$parameters |
|
104
|
|
|
); |
|
105
|
|
|
|
|
106
|
|
|
$this->assertEquals($expectedVariation, $actualVariation); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function testGetVariationOfNonImageAsset() |
|
110
|
|
|
{ |
|
111
|
|
|
$imageField = new Field([ |
|
112
|
|
|
'value' => new Image\Value([ |
|
113
|
|
|
'id' => 'images/6/8/4/0/486-10-eng-GB/photo.jpg', |
|
114
|
|
|
]), |
|
115
|
|
|
]); |
|
116
|
|
|
|
|
117
|
|
|
$imageVersionInfo = new VersionInfo(); |
|
118
|
|
|
$variationName = 'thumbnail'; |
|
119
|
|
|
$parameters = []; |
|
120
|
|
|
|
|
121
|
|
|
$expectedVariation = new Variation(); |
|
122
|
|
|
|
|
123
|
|
|
$this->contentService |
|
124
|
|
|
->expects($this->never()) |
|
125
|
|
|
->method('loadContent'); |
|
126
|
|
|
|
|
127
|
|
|
$this->assetMapper |
|
128
|
|
|
->expects($this->never()) |
|
129
|
|
|
->method('getAssetField'); |
|
130
|
|
|
|
|
131
|
|
|
$this->innerAliasGenerator |
|
132
|
|
|
->expects($this->once()) |
|
133
|
|
|
->method('getVariation') |
|
134
|
|
|
->with($imageField, $imageVersionInfo, $variationName, $parameters) |
|
135
|
|
|
->willReturn($expectedVariation); |
|
136
|
|
|
|
|
137
|
|
|
$actualVariation = $this->aliasGenerator->getVariation( |
|
138
|
|
|
$imageField, |
|
139
|
|
|
$imageVersionInfo, |
|
140
|
|
|
$variationName, |
|
141
|
|
|
$parameters |
|
142
|
|
|
); |
|
143
|
|
|
|
|
144
|
|
|
$this->assertEquals($expectedVariation, $actualVariation); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
public function testSupport() |
|
148
|
|
|
{ |
|
149
|
|
|
$this->assertTrue($this->aliasGenerator->supportsValue(new ImageAsset\Value())); |
|
150
|
|
|
$this->assertFalse($this->aliasGenerator->supportsValue(new Image\Value())); |
|
151
|
|
|
} |
|
152
|
|
|
} |
|
153
|
|
|
|