|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Netgen\Bundle\InformationCollectionBundle\Tests\Action; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\DBAL\DBALException; |
|
6
|
|
|
use eZ\Publish\API\Repository\Values\Content\Field; |
|
7
|
|
|
use eZ\Publish\Core\FieldType\TextLine\Value as TextLineValue; |
|
8
|
|
|
use eZ\Publish\Core\Repository\ContentService; |
|
9
|
|
|
use eZ\Publish\Core\Repository\Repository; |
|
10
|
|
|
use eZ\Publish\Core\Repository\Values\Content\Content; |
|
11
|
|
|
use eZ\Publish\Core\Repository\Values\Content\Location; |
|
12
|
|
|
use eZ\Publish\Core\Repository\Values\Content\VersionInfo; |
|
13
|
|
|
use eZ\Publish\Core\Repository\Values\ContentType\ContentType; |
|
14
|
|
|
use eZ\Publish\Core\Repository\Values\ContentType\FieldDefinition; |
|
15
|
|
|
use eZ\Publish\Core\Repository\Values\User\User; |
|
16
|
|
|
use eZ\Publish\SPI\Persistence\Content\ContentInfo; |
|
17
|
|
|
use Netgen\Bundle\EzFormsBundle\Form\DataWrapper; |
|
18
|
|
|
use Netgen\Bundle\EzFormsBundle\Form\Payload\InformationCollectionStruct; |
|
19
|
|
|
use Netgen\Bundle\InformationCollectionBundle\Action\DatabaseAction; |
|
20
|
|
|
use Netgen\Bundle\InformationCollectionBundle\Entity\EzInfoCollection; |
|
21
|
|
|
use Netgen\Bundle\InformationCollectionBundle\Entity\EzInfoCollectionAttribute; |
|
22
|
|
|
use Netgen\Bundle\InformationCollectionBundle\Event\InformationCollected; |
|
23
|
|
|
use Netgen\Bundle\InformationCollectionBundle\Factory\FieldDataFactory; |
|
24
|
|
|
use Netgen\Bundle\InformationCollectionBundle\Repository\RepositoryAggregate; |
|
25
|
|
|
use Netgen\Bundle\InformationCollectionBundle\Value\LegacyData; |
|
26
|
|
|
use PHPUnit\Framework\TestCase; |
|
27
|
|
|
|
|
28
|
|
|
class DatabaseActionTest extends TestCase |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* @var DatabaseAction |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $action; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $factory; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $repository; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $ezRepository; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject |
|
52
|
|
|
*/ |
|
53
|
|
|
protected $contentType; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject |
|
57
|
|
|
*/ |
|
58
|
|
|
protected $contentService; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @var array |
|
62
|
|
|
*/ |
|
63
|
|
|
protected $fields; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @var InformationCollectionStruct |
|
67
|
|
|
*/ |
|
68
|
|
|
protected $struct; |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @var LegacyData |
|
72
|
|
|
*/ |
|
73
|
|
|
protected $legacyData; |
|
74
|
|
|
|
|
75
|
|
|
public function setUp() |
|
76
|
|
|
{ |
|
77
|
|
|
$this->factory = $this->getMockBuilder(FieldDataFactory::class) |
|
78
|
|
|
->disableOriginalConstructor() |
|
79
|
|
|
->setMethods(array('getLegacyValue')) |
|
80
|
|
|
->getMock(); |
|
81
|
|
|
|
|
82
|
|
|
$this->repository = $this->getMockBuilder(RepositoryAggregate::class) |
|
83
|
|
|
->disableOriginalConstructor() |
|
84
|
|
|
->setMethods(array('createChild', 'createMain')) |
|
85
|
|
|
->getMock(); |
|
86
|
|
|
|
|
87
|
|
|
$this->ezRepository = $this->getMockBuilder(Repository::class) |
|
88
|
|
|
->disableOriginalConstructor() |
|
89
|
|
|
->setMethods(array('getContentService', 'getCurrentUser')) |
|
90
|
|
|
->getMock(); |
|
91
|
|
|
|
|
92
|
|
|
$this->contentType = new ContentType(array( |
|
|
|
|
|
|
93
|
|
|
'fieldDefinitions' => array( |
|
94
|
|
|
new FieldDefinition(array( |
|
95
|
|
|
'identifier' => 'some_field', |
|
96
|
|
|
'id' => 321, |
|
97
|
|
|
)), |
|
98
|
|
|
new FieldDefinition(array( |
|
99
|
|
|
'identifier' => 'some_field_1', |
|
100
|
|
|
'id' => 654, |
|
101
|
|
|
)), |
|
102
|
|
|
new FieldDefinition(array( |
|
103
|
|
|
'identifier' => 'some_field_2', |
|
104
|
|
|
'id' => 987, |
|
105
|
|
|
)), |
|
106
|
|
|
), |
|
107
|
|
|
)); |
|
108
|
|
|
|
|
109
|
|
|
$this->contentService = $this->getMockBuilder(ContentService::class) |
|
110
|
|
|
->disableOriginalConstructor() |
|
111
|
|
|
->setMethods(array('loadContent')) |
|
112
|
|
|
->getMock(); |
|
113
|
|
|
|
|
114
|
|
|
$this->fields = array( |
|
115
|
|
|
new Field(array( |
|
116
|
|
|
'id' => 123, |
|
117
|
|
|
'fieldDefIdentifier' => 'some_field', |
|
118
|
|
|
'value' => new TextLineValue('some value'), |
|
119
|
|
|
'languageCode' => 'eng_GB', |
|
120
|
|
|
)), |
|
121
|
|
|
new Field(array( |
|
122
|
|
|
'id' => 456, |
|
123
|
|
|
'fieldDefIdentifier' => 'some_field_1', |
|
124
|
|
|
'value' => new TextLineValue('some value 1'), |
|
125
|
|
|
'languageCode' => 'eng_GB', |
|
126
|
|
|
)), |
|
127
|
|
|
new Field(array( |
|
128
|
|
|
'id' => 789, |
|
129
|
|
|
'fieldDefIdentifier' => 'some_field_2', |
|
130
|
|
|
'value' => new TextLineValue('some value 2'), |
|
131
|
|
|
'languageCode' => 'eng_GB', |
|
132
|
|
|
)), |
|
133
|
|
|
); |
|
134
|
|
|
|
|
135
|
|
|
$this->struct = new InformationCollectionStruct(); |
|
136
|
|
|
foreach ($this->fields as $field) { |
|
137
|
|
|
$this->struct->setCollectedFieldValue($field->fieldDefIdentifier, $field->value); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
$this->legacyData = new LegacyData(123, 0, 0.0, 'some value'); |
|
141
|
|
|
|
|
142
|
|
|
$this->action = new DatabaseAction($this->factory, $this->repository, $this->ezRepository); |
|
143
|
|
|
parent::setUp(); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
View Code Duplication |
public function testAct() |
|
|
|
|
|
|
147
|
|
|
{ |
|
148
|
|
|
$location = new Location(array( |
|
149
|
|
|
'contentInfo' => new ContentInfo(array( |
|
150
|
|
|
'id' => 123, |
|
151
|
|
|
)), |
|
152
|
|
|
)); |
|
153
|
|
|
|
|
154
|
|
|
$content = new Content(array( |
|
155
|
|
|
'internalFields' => $this->fields, |
|
156
|
|
|
'versionInfo' => new VersionInfo(array( |
|
157
|
|
|
'contentInfo' => new ContentInfo(array( |
|
158
|
|
|
'mainLanguageCode' => 'eng_GB', |
|
159
|
|
|
)), |
|
160
|
|
|
)), |
|
161
|
|
|
)); |
|
162
|
|
|
|
|
163
|
|
|
$dataWrapper = new DataWrapper($this->struct, $this->contentType, $location); |
|
164
|
|
|
$event = new InformationCollected($dataWrapper); |
|
165
|
|
|
|
|
166
|
|
|
$user = new User(array( |
|
167
|
|
|
'content' => new Content(array( |
|
168
|
|
|
'versionInfo' => new VersionInfo(array( |
|
169
|
|
|
'contentInfo' => new ContentInfo(array( |
|
170
|
|
|
'id' => 123, |
|
171
|
|
|
)), |
|
172
|
|
|
)), |
|
173
|
|
|
)), |
|
174
|
|
|
'login' => 'login', |
|
175
|
|
|
)); |
|
176
|
|
|
|
|
177
|
|
|
$ezInfoCollection = new EzInfoCollection(); |
|
178
|
|
|
$ezInfoCollectionAttribute = new EzInfoCollectionAttribute(); |
|
179
|
|
|
|
|
180
|
|
|
$this->ezRepository->expects($this->once()) |
|
181
|
|
|
->method('getContentService') |
|
182
|
|
|
->willReturn($this->contentService); |
|
183
|
|
|
|
|
184
|
|
|
$this->contentService->expects($this->once()) |
|
185
|
|
|
->method('loadContent') |
|
186
|
|
|
->with(123) |
|
187
|
|
|
->willReturn($content); |
|
188
|
|
|
|
|
189
|
|
|
$this->ezRepository->expects($this->once()) |
|
190
|
|
|
->method('getCurrentUser') |
|
191
|
|
|
->willReturn($user); |
|
192
|
|
|
|
|
193
|
|
|
$this->repository->expects($this->once()) |
|
194
|
|
|
->method('createMain') |
|
195
|
|
|
->willReturn($ezInfoCollection); |
|
196
|
|
|
|
|
197
|
|
|
$this->factory->expects($this->exactly(3)) |
|
198
|
|
|
->method('getLegacyValue') |
|
199
|
|
|
->withAnyParameters() |
|
200
|
|
|
->willReturn($this->legacyData); |
|
201
|
|
|
|
|
202
|
|
|
$this->repository->expects($this->exactly(3)) |
|
203
|
|
|
->method('createChild') |
|
204
|
|
|
->willReturn($ezInfoCollectionAttribute); |
|
205
|
|
|
|
|
206
|
|
|
$this->action->act($event); |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
/** |
|
210
|
|
|
* @expectedException \Netgen\Bundle\InformationCollectionBundle\Exception\ActionFailedException |
|
211
|
|
|
*/ |
|
212
|
|
|
public function testActWithExceptionOnInformationCollectionRepository() |
|
213
|
|
|
{ |
|
214
|
|
|
$location = new Location(array( |
|
215
|
|
|
'contentInfo' => new ContentInfo(array( |
|
216
|
|
|
'id' => 123, |
|
217
|
|
|
)), |
|
218
|
|
|
)); |
|
219
|
|
|
|
|
220
|
|
|
$content = new Content(array( |
|
221
|
|
|
'internalFields' => $this->fields, |
|
222
|
|
|
'versionInfo' => new VersionInfo(array( |
|
223
|
|
|
'contentInfo' => new ContentInfo(array( |
|
224
|
|
|
'mainLanguageCode' => 'eng_GB', |
|
225
|
|
|
)), |
|
226
|
|
|
)), |
|
227
|
|
|
)); |
|
228
|
|
|
|
|
229
|
|
|
$dataWrapper = new DataWrapper($this->struct, $this->contentType, $location); |
|
230
|
|
|
$event = new InformationCollected($dataWrapper); |
|
231
|
|
|
|
|
232
|
|
|
$user = new User(array( |
|
233
|
|
|
'content' => new Content(array( |
|
234
|
|
|
'versionInfo' => new VersionInfo(array( |
|
235
|
|
|
'contentInfo' => new ContentInfo(array( |
|
236
|
|
|
'id' => 123, |
|
237
|
|
|
)), |
|
238
|
|
|
)), |
|
239
|
|
|
)), |
|
240
|
|
|
'login' => 'login', |
|
241
|
|
|
)); |
|
242
|
|
|
|
|
243
|
|
|
$ezInfoCollection = new EzInfoCollection(); |
|
|
|
|
|
|
244
|
|
|
|
|
245
|
|
|
$this->ezRepository->expects($this->once()) |
|
246
|
|
|
->method('getContentService') |
|
247
|
|
|
->willReturn($this->contentService); |
|
248
|
|
|
|
|
249
|
|
|
$this->contentService->expects($this->once()) |
|
250
|
|
|
->method('loadContent') |
|
251
|
|
|
->with(123) |
|
252
|
|
|
->willReturn($content); |
|
253
|
|
|
|
|
254
|
|
|
$this->ezRepository->expects($this->once()) |
|
255
|
|
|
->method('getCurrentUser') |
|
256
|
|
|
->willReturn($user); |
|
257
|
|
|
|
|
258
|
|
|
$this->repository->expects($this->once()) |
|
259
|
|
|
->method('createMain') |
|
260
|
|
|
->willThrowException(new DBALException()); |
|
261
|
|
|
|
|
262
|
|
|
$this->factory->expects($this->never()) |
|
263
|
|
|
->method('getLegacyValue'); |
|
264
|
|
|
|
|
265
|
|
|
$this->repository->expects($this->never()) |
|
266
|
|
|
->method('createChild'); |
|
267
|
|
|
|
|
268
|
|
|
$this->action->act($event); |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
/** |
|
272
|
|
|
* @expectedException \Netgen\Bundle\InformationCollectionBundle\Exception\ActionFailedException |
|
273
|
|
|
*/ |
|
274
|
|
View Code Duplication |
public function testActWithExceptionOnInformationCollectionAttributeRepository() |
|
|
|
|
|
|
275
|
|
|
{ |
|
276
|
|
|
$location = new Location(array( |
|
277
|
|
|
'contentInfo' => new ContentInfo(array( |
|
278
|
|
|
'id' => 123, |
|
279
|
|
|
)), |
|
280
|
|
|
)); |
|
281
|
|
|
|
|
282
|
|
|
$content = new Content(array( |
|
283
|
|
|
'internalFields' => $this->fields, |
|
284
|
|
|
'versionInfo' => new VersionInfo(array( |
|
285
|
|
|
'contentInfo' => new ContentInfo(array( |
|
286
|
|
|
'mainLanguageCode' => 'eng_GB', |
|
287
|
|
|
)), |
|
288
|
|
|
)), |
|
289
|
|
|
)); |
|
290
|
|
|
|
|
291
|
|
|
$dataWrapper = new DataWrapper($this->struct, $this->contentType, $location); |
|
292
|
|
|
$event = new InformationCollected($dataWrapper); |
|
293
|
|
|
|
|
294
|
|
|
$user = new User(array( |
|
295
|
|
|
'content' => new Content(array( |
|
296
|
|
|
'versionInfo' => new VersionInfo(array( |
|
297
|
|
|
'contentInfo' => new ContentInfo(array( |
|
298
|
|
|
'id' => 123, |
|
299
|
|
|
)), |
|
300
|
|
|
)), |
|
301
|
|
|
)), |
|
302
|
|
|
'login' => 'login', |
|
303
|
|
|
)); |
|
304
|
|
|
|
|
305
|
|
|
$ezInfoCollection = new EzInfoCollection(); |
|
306
|
|
|
$ezInfoCollectionAttribute = new EzInfoCollectionAttribute(); |
|
|
|
|
|
|
307
|
|
|
|
|
308
|
|
|
$this->ezRepository->expects($this->once()) |
|
309
|
|
|
->method('getContentService') |
|
310
|
|
|
->willReturn($this->contentService); |
|
311
|
|
|
|
|
312
|
|
|
$this->contentService->expects($this->once()) |
|
313
|
|
|
->method('loadContent') |
|
314
|
|
|
->with(123) |
|
315
|
|
|
->willReturn($content); |
|
316
|
|
|
|
|
317
|
|
|
$this->ezRepository->expects($this->once()) |
|
318
|
|
|
->method('getCurrentUser') |
|
319
|
|
|
->willReturn($user); |
|
320
|
|
|
|
|
321
|
|
|
$this->repository->expects($this->once()) |
|
322
|
|
|
->method('createMain') |
|
323
|
|
|
->willReturn($ezInfoCollection); |
|
324
|
|
|
|
|
325
|
|
|
$this->factory->expects($this->exactly(1)) |
|
326
|
|
|
->method('getLegacyValue') |
|
327
|
|
|
->withAnyParameters() |
|
328
|
|
|
->willReturn($this->legacyData); |
|
329
|
|
|
|
|
330
|
|
|
$this->repository->expects($this->once()) |
|
331
|
|
|
->method('createChild') |
|
332
|
|
|
->willThrowException(new DBALException()); |
|
333
|
|
|
|
|
334
|
|
|
$this->action->act($event); |
|
335
|
|
|
} |
|
336
|
|
|
} |
|
337
|
|
|
|
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..