1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File contains: eZ\Publish\Core\Repository\Tests\Service\Integration\ContentBase class. |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
8
|
|
|
* |
9
|
|
|
* @version //autogentag// |
10
|
|
|
*/ |
11
|
|
|
namespace eZ\Publish\Core\Repository\Tests\Service\Integration; |
12
|
|
|
|
13
|
|
|
use eZ\Publish\Core\Repository\Tests\Service\Integration\Base as BaseServiceTest; |
14
|
|
|
use eZ\Publish\Core\Repository\Values\Content\VersionInfo; |
15
|
|
|
use eZ\Publish\API\Repository\Values\Content\LocationCreateStruct; |
16
|
|
|
use eZ\Publish\API\Repository\Values\Content\Content as APIContent; |
17
|
|
|
use eZ\Publish\API\Repository\Values\Content\Relation; |
18
|
|
|
use eZ\Publish\API\Repository\Exceptions\NotFoundException; |
19
|
|
|
use eZ\Publish\API\Repository\Tests\BaseTest as APIBaseTest; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Test case for Content service. |
23
|
|
|
*/ |
24
|
|
|
abstract class ContentBase extends BaseServiceTest |
25
|
|
|
{ |
26
|
|
|
protected $testContentType; |
27
|
|
|
|
28
|
|
|
protected function getContentInfoExpectedValues() |
29
|
|
|
{ |
30
|
|
|
// Legacy fixture content ID=4 values |
31
|
|
|
return array( |
32
|
|
|
'id' => 4, |
33
|
|
|
'name' => 'Users', |
34
|
|
|
'sectionId' => 2, |
35
|
|
|
'currentVersionNo' => 1, |
36
|
|
|
'published' => true, |
37
|
|
|
'ownerId' => 14, |
38
|
|
|
'modificationDate' => $this->getDateTime(1033917596), |
39
|
|
|
'publishedDate' => $this->getDateTime(1033917596), |
40
|
|
|
'alwaysAvailable' => true, |
41
|
|
|
'remoteId' => 'f5c88a2209584891056f987fd965b0ba', |
42
|
|
|
'mainLanguageCode' => 'eng-US', |
43
|
|
|
'mainLocationId' => 5, |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param bool $draft |
49
|
|
|
* |
50
|
|
|
* @return array |
51
|
|
|
*/ |
52
|
|
|
protected function getVersionInfoExpectedValues($draft = false) |
53
|
|
|
{ |
54
|
|
|
// Legacy fixture content 4 current version (1) values |
55
|
|
|
$values = array( |
56
|
|
|
//"id" => 4, |
57
|
|
|
'versionNo' => 1, |
58
|
|
|
'modificationDate' => $this->getDateTime(0), |
59
|
|
|
'creatorId' => 14, |
60
|
|
|
'creationDate' => $this->getDateTime(0), |
61
|
|
|
'status' => VersionInfo::STATUS_PUBLISHED, |
62
|
|
|
'initialLanguageCode' => 'eng-US', |
63
|
|
|
'languageCodes' => array('eng-US'), |
64
|
|
|
// Implementation properties |
65
|
|
|
'names' => array('eng-US' => 'Users'), |
66
|
|
|
); |
67
|
|
|
|
68
|
|
|
if ($draft) { |
69
|
|
|
//$values["id"] = 675; |
70
|
|
|
$values['creatorId'] = $this->repository->getCurrentUserReference()->getUserId(); |
|
|
|
|
71
|
|
|
$values['versionNo'] = 2; |
72
|
|
|
$values['status'] = VersionInfo::STATUS_DRAFT; |
73
|
|
|
unset($values['modificationDate']); |
74
|
|
|
unset($values['creationDate']); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
return $values; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param array $languages |
82
|
|
|
* |
83
|
|
|
* @return mixed |
84
|
|
|
*/ |
85
|
|
|
protected function getFieldValuesExpectedValues(array $languages = null) |
86
|
|
|
{ |
87
|
|
|
// Legacy fixture content ID=4 field values |
88
|
|
|
$fieldValues = array( |
89
|
|
|
'eng-US' => array( |
90
|
|
|
'name' => array('eng-US' => 'Users'), |
91
|
|
|
'description' => array('eng-US' => 'Main group'), |
92
|
|
|
), |
93
|
|
|
); |
94
|
|
|
|
95
|
|
|
$returnArray = array(); |
96
|
|
|
foreach ($fieldValues as $languageCode => $languageFieldValues) { |
97
|
|
|
if (!empty($languages) && !in_array($languageCode, $languages)) { |
98
|
|
|
continue; |
99
|
|
|
} |
100
|
|
|
$returnArray = array_merge_recursive($returnArray, $languageFieldValues); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
return $returnArray; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
protected function getExpectedContentType() |
107
|
|
|
{ |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Test for the loadContentInfo() method. |
112
|
|
|
* |
113
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadContentInfo |
114
|
|
|
* |
115
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
116
|
|
|
*/ |
117
|
|
|
public function testLoadContentInfo() |
118
|
|
|
{ |
119
|
|
|
/* BEGIN: Use Case */ |
120
|
|
|
$contentService = $this->repository->getContentService(); |
121
|
|
|
|
122
|
|
|
$contentInfo = $contentService->loadContentInfo(4); |
123
|
|
|
/* END: Use Case */ |
124
|
|
|
|
125
|
|
|
$this->assertInstanceOf( |
126
|
|
|
'eZ\\Publish\\API\\Repository\\Values\\Content\\ContentInfo', |
127
|
|
|
$contentInfo |
128
|
|
|
); |
129
|
|
|
|
130
|
|
|
return $contentInfo; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Test for the loadContentInfo() method. |
135
|
|
|
* |
136
|
|
|
* @depends testLoadContentInfo |
137
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadContentInfo |
138
|
|
|
* |
139
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
140
|
|
|
*/ |
141
|
|
|
public function testLoadContentInfoValues($contentInfo) |
142
|
|
|
{ |
143
|
|
|
$this->assertPropertiesCorrect( |
144
|
|
|
$this->getContentInfoExpectedValues(), |
145
|
|
|
$contentInfo |
146
|
|
|
); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* Test for the loadContentInfo() method. |
151
|
|
|
* |
152
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadContentInfo |
153
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
154
|
|
|
*/ |
155
|
|
|
public function testLoadContentInfoThrowsNotFoundException() |
156
|
|
|
{ |
157
|
|
|
/* BEGIN: Use Case */ |
158
|
|
|
$contentService = $this->repository->getContentService(); |
159
|
|
|
|
160
|
|
|
// Throws an exception because given contentId does not exist |
161
|
|
|
$contentInfo = $contentService->loadContentInfo(APIBaseTest::DB_INT_MAX); |
|
|
|
|
162
|
|
|
/* END: Use Case */ |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Test for the loadContentInfo() method. |
167
|
|
|
* |
168
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadContentInfo |
169
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
170
|
|
|
*/ |
171
|
|
|
public function testLoadContentInfoThrowsUnauthorizedException() |
172
|
|
|
{ |
173
|
|
|
// Set anonymous as current user |
174
|
|
|
$this->repository->setCurrentUser($this->getStubbedUser(10)); |
|
|
|
|
175
|
|
|
|
176
|
|
|
$this->repository->getContentService()->loadContentInfo(4); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Test for the loadContentInfoByRemoteId() method. |
181
|
|
|
* |
182
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadContentInfoByRemoteId |
183
|
|
|
* |
184
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
185
|
|
|
*/ |
186
|
|
|
public function testLoadContentInfoByRemoteId() |
187
|
|
|
{ |
188
|
|
|
/* BEGIN: Use Case */ |
189
|
|
|
$contentService = $this->repository->getContentService(); |
190
|
|
|
|
191
|
|
|
$contentInfo = $contentService->loadContentInfoByRemoteId('f5c88a2209584891056f987fd965b0ba'); |
192
|
|
|
/* END: Use Case */ |
193
|
|
|
|
194
|
|
|
$this->assertInstanceOf( |
195
|
|
|
'eZ\\Publish\\API\\Repository\\Values\\Content\\ContentInfo', |
196
|
|
|
$contentInfo |
197
|
|
|
); |
198
|
|
|
|
199
|
|
|
return $contentInfo; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* Test for the loadContentInfoByRemoteId() method. |
204
|
|
|
* |
205
|
|
|
* @depends testLoadContentInfoByRemoteId |
206
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadContentInfoByRemoteId |
207
|
|
|
* |
208
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
209
|
|
|
*/ |
210
|
|
|
public function testLoadContentInfoByRemoteIdValues($contentInfo) |
211
|
|
|
{ |
212
|
|
|
$this->assertPropertiesCorrect( |
213
|
|
|
$this->getContentInfoExpectedValues(), |
214
|
|
|
$contentInfo |
215
|
|
|
); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* Test for the loadContentInfoByRemoteId() method. |
220
|
|
|
* |
221
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadContentInfoByRemoteId |
222
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
223
|
|
|
*/ |
224
|
|
|
public function testLoadContentInfoByRemoteIdThrowsNotFoundException() |
225
|
|
|
{ |
226
|
|
|
/* BEGIN: Use Case */ |
227
|
|
|
$contentService = $this->repository->getContentService(); |
228
|
|
|
|
229
|
|
|
// Throws an exception because remoteId does not exist |
230
|
|
|
$contentInfo = $contentService->loadContentInfoByRemoteId('this-remote-id-does-not-exist'); |
|
|
|
|
231
|
|
|
/* END: Use Case */ |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* Test for the loadContentInfoByRemoteId() method. |
236
|
|
|
* |
237
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadContentInfoByRemoteId |
238
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
239
|
|
|
*/ |
240
|
|
|
public function testLoadContentInfoByRemoteIdThrowsUnauthorizedException() |
241
|
|
|
{ |
242
|
|
|
// Set anonymous as current user |
243
|
|
|
$this->repository->setCurrentUser($this->getStubbedUser(10)); |
|
|
|
|
244
|
|
|
|
245
|
|
|
$this->repository->getContentService()->loadContentInfoByRemoteId('f5c88a2209584891056f987fd965b0ba'); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* Test for the loadVersionInfoById() method. |
250
|
|
|
* |
251
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadVersionInfoById |
252
|
|
|
* |
253
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\VersionInfo |
254
|
|
|
*/ |
255
|
|
View Code Duplication |
public function testLoadVersionInfoById() |
256
|
|
|
{ |
257
|
|
|
/* BEGIN: Use Case */ |
258
|
|
|
$contentService = $this->repository->getContentService(); |
259
|
|
|
|
260
|
|
|
$versionInfo = $contentService->loadVersionInfoById(4); |
261
|
|
|
/* END: Use Case */ |
262
|
|
|
|
263
|
|
|
$this->assertInstanceOf( |
264
|
|
|
'eZ\\Publish\\API\\Repository\\Values\\Content\\VersionInfo', |
265
|
|
|
$versionInfo |
266
|
|
|
); |
267
|
|
|
|
268
|
|
|
return $versionInfo; |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* Test for the loadVersionInfoById() method. |
273
|
|
|
* |
274
|
|
|
* @depends testLoadVersionInfoById |
275
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadVersionInfoById |
276
|
|
|
* |
277
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
278
|
|
|
*/ |
279
|
|
|
public function testLoadVersionInfoByIdValues($versionInfo) |
280
|
|
|
{ |
281
|
|
|
$this->assertPropertiesCorrect( |
282
|
|
|
$this->getVersionInfoExpectedValues(), |
283
|
|
|
$versionInfo |
284
|
|
|
); |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* Test for the loadVersionInfoById() method. |
289
|
|
|
* |
290
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadVersionInfoById |
291
|
|
|
* |
292
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\VersionInfo |
293
|
|
|
*/ |
294
|
|
View Code Duplication |
public function testLoadVersionInfoByIdWithSecondParameter() |
295
|
|
|
{ |
296
|
|
|
/* BEGIN: Use Case */ |
297
|
|
|
$contentService = $this->repository->getContentService(); |
298
|
|
|
|
299
|
|
|
$versionInfo = $contentService->loadVersionInfoById(4, 1); |
300
|
|
|
/* END: Use Case */ |
301
|
|
|
|
302
|
|
|
$this->assertInstanceOf( |
303
|
|
|
'eZ\\Publish\\API\\Repository\\Values\\Content\\VersionInfo', |
304
|
|
|
$versionInfo |
305
|
|
|
); |
306
|
|
|
|
307
|
|
|
return $versionInfo; |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* Test for the loadVersionInfoById() method. |
312
|
|
|
* |
313
|
|
|
* @depends testLoadVersionInfoByIdWithSecondParameter |
314
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadVersionInfoById |
315
|
|
|
* |
316
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
317
|
|
|
*/ |
318
|
|
|
public function testLoadVersionInfoByIdWithSecondParameterValues($versionInfo) |
319
|
|
|
{ |
320
|
|
|
$this->assertPropertiesCorrect( |
321
|
|
|
$this->getVersionInfoExpectedValues(), |
322
|
|
|
$versionInfo |
323
|
|
|
); |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
/** |
327
|
|
|
* Test for the loadVersionInfoById() method. |
328
|
|
|
* |
329
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadVersionInfoById |
330
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
331
|
|
|
*/ |
332
|
|
|
public function testLoadVersionInfoByIdThrowsNotFoundException() |
333
|
|
|
{ |
334
|
|
|
/* BEGIN: Use Case */ |
335
|
|
|
$contentService = $this->repository->getContentService(); |
336
|
|
|
|
337
|
|
|
// Throws an exception because version with given number does not exists |
338
|
|
|
$versionInfo = $contentService->loadVersionInfoById(4, APIBaseTest::DB_INT_MAX); |
|
|
|
|
339
|
|
|
/* END: Use Case */ |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
/** |
343
|
|
|
* Test for the loadVersionInfoById() method. |
344
|
|
|
* |
345
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadVersionInfoById |
346
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
347
|
|
|
*/ |
348
|
|
|
public function testLoadVersionInfoByIdThrowsUnauthorizedException() |
349
|
|
|
{ |
350
|
|
|
// Set anonymous as current user |
351
|
|
|
$this->repository->setCurrentUser($this->getStubbedUser(10)); |
|
|
|
|
352
|
|
|
|
353
|
|
|
$this->repository->getContentService()->loadVersionInfoById(4); |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
/** |
357
|
|
|
* Data provider for testLoadContent(). |
358
|
|
|
* |
359
|
|
|
* @return array |
360
|
|
|
*/ |
361
|
|
|
public function testLoadContentArgumentsProvider() |
362
|
|
|
{ |
363
|
|
|
return array( |
364
|
|
|
array(4, null, null), |
365
|
|
|
array(4, array('eng-US'), null), |
366
|
|
|
array(4, array('eng-US', 'fre-FR'), null), |
367
|
|
|
array(4, null, 1), |
368
|
|
|
array(4, array('eng-US', 'fre-FR', 'nor-NO', 'eng-DE'), 1), |
369
|
|
|
array(4, array('eng-US'), 1), |
370
|
|
|
); |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
/** |
374
|
|
|
* Test for the loadContent() method. |
375
|
|
|
* |
376
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadContent |
377
|
|
|
* @dataProvider testLoadContentArgumentsProvider |
378
|
|
|
* |
379
|
|
|
* @param int $contentId |
380
|
|
|
* @param array $languages |
381
|
|
|
* @param int $versionNo |
382
|
|
|
* |
383
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Content |
384
|
|
|
*/ |
385
|
|
View Code Duplication |
public function testLoadContent($contentId, array $languages = null, $versionNo = null) |
386
|
|
|
{ |
387
|
|
|
/* BEGIN: Use Case */ |
388
|
|
|
$contentService = $this->repository->getContentService(); |
389
|
|
|
|
390
|
|
|
$content = $contentService->loadContent($contentId, $languages, $versionNo); |
391
|
|
|
/* END: Use Case */ |
392
|
|
|
|
393
|
|
|
$this->assertInstanceOf( |
394
|
|
|
'eZ\\Publish\\API\\Repository\\Values\\Content\\Content', |
395
|
|
|
$content |
396
|
|
|
); |
397
|
|
|
|
398
|
|
|
$this->assertContentValues($content, $languages); |
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
/** |
402
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Content $content |
403
|
|
|
* @param array $languages |
404
|
|
|
* @param bool $draft |
405
|
|
|
*/ |
406
|
|
|
protected function assertContentValues(APIContent $content, array $languages = null, $draft = false) |
407
|
|
|
{ |
408
|
|
|
$versionInfoValues = $this->getVersionInfoExpectedValues($draft); |
409
|
|
|
$contentInfoValues = $this->getContentInfoExpectedValues(); |
410
|
|
|
$fieldValuesValues = $this->getFieldValuesExpectedValues($languages); |
411
|
|
|
|
412
|
|
|
$this->assertPropertiesCorrect( |
413
|
|
|
$versionInfoValues, |
414
|
|
|
$content->getVersionInfo() |
415
|
|
|
); |
416
|
|
|
|
417
|
|
|
$this->assertPropertiesCorrect( |
418
|
|
|
$contentInfoValues, |
419
|
|
|
$content->contentInfo |
420
|
|
|
); |
421
|
|
|
|
422
|
|
|
$this->assertEquals( |
423
|
|
|
$fieldValuesValues, |
424
|
|
|
$content->fields |
425
|
|
|
); |
426
|
|
|
|
427
|
|
|
// @todo assert relations |
428
|
|
|
|
429
|
|
|
$this->assertEquals($content->id, $content->contentInfo->id); |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
/** |
433
|
|
|
* Test for the loadContent() method. |
434
|
|
|
* |
435
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadContent |
436
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
437
|
|
|
*/ |
438
|
|
|
public function testLoadContentThrowsUnauthorizedException() |
439
|
|
|
{ |
440
|
|
|
// Set anonymous as current user |
441
|
|
|
$this->repository->setCurrentUser($this->getStubbedUser(10)); |
|
|
|
|
442
|
|
|
|
443
|
|
|
$this->repository->getContentService()->loadContent(4); |
444
|
|
|
} |
445
|
|
|
|
446
|
|
|
/** |
447
|
|
|
* Test for the loadContent() method. |
448
|
|
|
* |
449
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadContent |
450
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
451
|
|
|
*/ |
452
|
|
View Code Duplication |
public function testLoadContentWithVersionThrowsUnauthorizedException() |
453
|
|
|
{ |
454
|
|
|
list($draft) = $this->createTestContent(); |
455
|
|
|
$this->repository->setCurrentUser($this->getStubbedUser(10)); |
|
|
|
|
456
|
|
|
|
457
|
|
|
$this->repository->getContentService()->loadContent( |
458
|
|
|
$draft->id, |
459
|
|
|
null, |
460
|
|
|
$draft->versionInfo->versionNo |
461
|
|
|
); |
462
|
|
|
} |
463
|
|
|
|
464
|
|
|
/** |
465
|
|
|
* Test for the loadContent() method. |
466
|
|
|
* |
467
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadContent |
468
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
469
|
|
|
*/ |
470
|
|
|
public function testLoadContentThrowsNotFoundExceptionContentNotFound() |
471
|
|
|
{ |
472
|
|
|
/* BEGIN: Use Case */ |
473
|
|
|
$contentService = $this->repository->getContentService(); |
474
|
|
|
|
475
|
|
|
// Throws an exception because content with id APIBaseTest::DB_INT_MAX does not exist |
476
|
|
|
$content = $contentService->loadContent(APIBaseTest::DB_INT_MAX); |
|
|
|
|
477
|
|
|
/* END: Use Case */ |
478
|
|
|
} |
479
|
|
|
|
480
|
|
|
/** |
481
|
|
|
* Test for the loadContent() method. |
482
|
|
|
* |
483
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadContent |
484
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
485
|
|
|
*/ |
486
|
|
|
public function testLoadContentThrowsNotFoundExceptionVersionNotFound() |
487
|
|
|
{ |
488
|
|
|
/* BEGIN: Use Case */ |
489
|
|
|
$contentService = $this->repository->getContentService(); |
490
|
|
|
|
491
|
|
|
// Throws an exception because version number APIBaseTest::DB_INT_MAX for content with id 4 does not exist |
492
|
|
|
$content = $contentService->loadContent(4, null, APIBaseTest::DB_INT_MAX); |
|
|
|
|
493
|
|
|
/* END: Use Case */ |
494
|
|
|
} |
495
|
|
|
|
496
|
|
|
/** |
497
|
|
|
* Test for the loadContent() method. |
498
|
|
|
* |
499
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadContent |
500
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
501
|
|
|
*/ |
502
|
|
|
public function testLoadContentThrowsNotFoundExceptionLanguageNotFound() |
503
|
|
|
{ |
504
|
|
|
/* BEGIN: Use Case */ |
505
|
|
|
$contentService = $this->repository->getContentService(); |
506
|
|
|
|
507
|
|
|
// Throws an exception because content does not exists in "fre-FR" language |
508
|
|
|
$content = $contentService->loadContent(4, array('fre-FR'), null, false); |
|
|
|
|
509
|
|
|
/* END: Use Case */ |
510
|
|
|
} |
511
|
|
|
|
512
|
|
|
/** |
513
|
|
|
* Test for the loadContent() method. |
514
|
|
|
* |
515
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadContent |
516
|
|
|
*/ |
517
|
|
|
public function testLoadContentThrowsNotFoundExceptionLanguageNotFoundVariation() |
518
|
|
|
{ |
519
|
|
|
/* BEGIN: Use Case */ |
520
|
|
|
$contentService = $this->repository->getContentService(); |
521
|
|
|
|
522
|
|
|
// Content only exists in eng-US, so we should only have it in eng-US. |
523
|
|
|
$content = $contentService->loadContent(4, array('eng-US', 'eng-GB')); |
524
|
|
|
$this->assertInstanceOf( |
525
|
|
|
'eZ\\Publish\\API\\Repository\\Values\\Content\\Content', |
526
|
|
|
$content |
527
|
|
|
); |
528
|
|
|
$this->assertContentValues($content, array('eng-US')); |
529
|
|
|
/* END: Use Case */ |
530
|
|
|
} |
531
|
|
|
|
532
|
|
|
/** |
533
|
|
|
* Data provider for testLoadContentByRemoteId(). |
534
|
|
|
* |
535
|
|
|
* @return array |
536
|
|
|
*/ |
537
|
|
|
public function testLoadContentByRemoteIdArgumentsProvider() |
538
|
|
|
{ |
539
|
|
|
return array( |
540
|
|
|
array('f5c88a2209584891056f987fd965b0ba', null, null), |
541
|
|
|
array('f5c88a2209584891056f987fd965b0ba', array('eng-US'), null), |
542
|
|
|
array('f5c88a2209584891056f987fd965b0ba', null, 1), |
543
|
|
|
array('f5c88a2209584891056f987fd965b0ba', array('eng-US'), 1), |
544
|
|
|
); |
545
|
|
|
} |
546
|
|
|
|
547
|
|
|
/** |
548
|
|
|
* Test for the loadContentByRemoteId() method. |
549
|
|
|
* |
550
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadContentByRemoteId |
551
|
|
|
* @dataProvider testLoadContentByRemoteIdArgumentsProvider |
552
|
|
|
* |
553
|
|
|
* @param string $remoteId |
554
|
|
|
* @param array|null $languages |
555
|
|
|
* @param int $versionNo |
556
|
|
|
* |
557
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Content |
558
|
|
|
*/ |
559
|
|
View Code Duplication |
public function testLoadContentByRemoteId($remoteId, $languages, $versionNo) |
560
|
|
|
{ |
561
|
|
|
/* BEGIN: Use Case */ |
562
|
|
|
$contentService = $this->repository->getContentService(); |
563
|
|
|
|
564
|
|
|
$content = $contentService->loadContentByRemoteId($remoteId, $languages, $versionNo); |
565
|
|
|
/* END: Use Case */ |
566
|
|
|
|
567
|
|
|
$this->assertInstanceOf( |
568
|
|
|
'eZ\\Publish\\API\\Repository\\Values\\Content\\Content', |
569
|
|
|
$content |
570
|
|
|
); |
571
|
|
|
|
572
|
|
|
$this->assertContentValues($content, $languages); |
573
|
|
|
} |
574
|
|
|
|
575
|
|
|
/** |
576
|
|
|
* Test for the loadContentByRemoteId() method. |
577
|
|
|
* |
578
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadContentByRemoteId |
579
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
580
|
|
|
*/ |
581
|
|
|
public function testLoadContentByRemoteIdThrowsNotFoundException() |
582
|
|
|
{ |
583
|
|
|
/* BEGIN: Use Case */ |
584
|
|
|
$contentService = $this->repository->getContentService(); |
585
|
|
|
|
586
|
|
|
// Throws an exception because given remoteId does not exist |
587
|
|
|
$content = $contentService->loadContentByRemoteId('non-existent-remote-id'); |
|
|
|
|
588
|
|
|
/* END: Use Case */ |
589
|
|
|
} |
590
|
|
|
|
591
|
|
|
/** |
592
|
|
|
* Test for the loadContentByRemoteId() method. |
593
|
|
|
* |
594
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadContentByRemoteId |
595
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
596
|
|
|
*/ |
597
|
|
|
public function testLoadContentByRemoteIdThrowsUnauthorizedException() |
598
|
|
|
{ |
599
|
|
|
// Set anonymous as current user |
600
|
|
|
$this->repository->setCurrentUser($this->getStubbedUser(10)); |
|
|
|
|
601
|
|
|
|
602
|
|
|
$this->repository->getContentService()->loadContentByRemoteId('f5c88a2209584891056f987fd965b0ba'); |
603
|
|
|
} |
604
|
|
|
|
605
|
|
|
/** |
606
|
|
|
* Test for the loadContentByRemoteId() method. |
607
|
|
|
* |
608
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadContentByRemoteId |
609
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
610
|
|
|
*/ |
611
|
|
|
public function testLoadContentByRemoteIdWithVersionThrowsUnauthorizedException() |
612
|
|
|
{ |
613
|
|
|
$contentService = $this->repository->getContentService(); |
614
|
|
|
|
615
|
|
|
$content = $contentService->loadContent(4); |
616
|
|
|
$draft = $contentService->createContentDraft($content->contentInfo); |
617
|
|
|
$this->repository->setCurrentUser($this->getStubbedUser(10)); |
|
|
|
|
618
|
|
|
|
619
|
|
|
$contentService->loadContentByRemoteId( |
620
|
|
|
$draft->contentInfo->remoteId, |
621
|
|
|
null, |
622
|
|
|
$draft->versionInfo->versionNo |
623
|
|
|
); |
624
|
|
|
} |
625
|
|
|
|
626
|
|
|
/** |
627
|
|
|
* Test for the newContentCreateStruct() method. |
628
|
|
|
* |
629
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::newContentCreateStruct |
630
|
|
|
* |
631
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct |
632
|
|
|
*/ |
633
|
|
|
public function testNewContentCreateStruct() |
634
|
|
|
{ |
635
|
|
|
/* BEGIN: Use Case */ |
636
|
|
|
$contentService = $this->repository->getContentService(); |
637
|
|
|
$contentTypeService = $this->repository->getContentTypeService(); |
638
|
|
|
|
639
|
|
|
$folderContentType = $contentTypeService->loadContentType(1); |
640
|
|
|
|
641
|
|
|
$contentCreateStruct = $contentService->newContentCreateStruct( |
642
|
|
|
$folderContentType, |
643
|
|
|
'eng-GB' |
644
|
|
|
); |
645
|
|
|
/* END: Use Case */ |
646
|
|
|
|
647
|
|
|
$this->assertInstanceOf( |
648
|
|
|
'eZ\\Publish\\API\\Repository\\Values\\Content\\ContentCreateStruct', |
649
|
|
|
$contentCreateStruct |
650
|
|
|
); |
651
|
|
|
|
652
|
|
|
return array( |
653
|
|
|
'contentType' => $folderContentType, |
654
|
|
|
'contentCreateStruct' => $contentCreateStruct, |
655
|
|
|
); |
656
|
|
|
} |
657
|
|
|
|
658
|
|
|
/** |
659
|
|
|
* Test for the newContentCreateStruct() method. |
660
|
|
|
* |
661
|
|
|
* @depends testNewContentCreateStruct |
662
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::newContentCreateStruct |
663
|
|
|
* |
664
|
|
|
* @param array $data |
665
|
|
|
*/ |
666
|
|
|
public function testNewContentCreateStructValues(array $data) |
667
|
|
|
{ |
668
|
|
|
$contentType = $data['contentType']; |
669
|
|
|
$contentCreateStruct = $data['contentCreateStruct']; |
670
|
|
|
|
671
|
|
|
$expectedValues = array( |
672
|
|
|
'fields' => array(), |
673
|
|
|
'contentType' => $contentType, |
674
|
|
|
'sectionId' => null, |
675
|
|
|
'ownerId' => null, |
676
|
|
|
'alwaysAvailable' => null, |
677
|
|
|
'remoteId' => null, |
678
|
|
|
'mainLanguageCode' => 'eng-GB', |
679
|
|
|
'modificationDate' => null, |
680
|
|
|
); |
681
|
|
|
|
682
|
|
|
$this->assertPropertiesCorrect( |
683
|
|
|
$expectedValues, |
684
|
|
|
$contentCreateStruct |
685
|
|
|
); |
686
|
|
|
} |
687
|
|
|
|
688
|
|
|
/** |
689
|
|
|
* Test for the createContent() method. |
690
|
|
|
* |
691
|
|
|
* @depends testNewContentCreateStruct |
692
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::createContent |
693
|
|
|
* |
694
|
|
|
* @return array |
695
|
|
|
*/ |
696
|
|
|
public function testCreateContent() |
697
|
|
|
{ |
698
|
|
|
$time = time(); |
699
|
|
|
$testContentType = $this->createTestContentType(); |
700
|
|
|
|
701
|
|
|
/* BEGIN: Use Case */ |
702
|
|
|
$contentService = $this->repository->getContentService(); |
703
|
|
|
|
704
|
|
|
$contentCreate = $contentService->newContentCreateStruct($testContentType, 'eng-GB'); |
705
|
|
|
$contentCreate->setField('test_required_empty', 'value for field definition with empty default value'); |
706
|
|
|
$contentCreate->setField('test_translatable', 'and thumbs opposable', 'eng-US'); |
707
|
|
|
$contentCreate->sectionId = 1; |
708
|
|
|
$contentCreate->ownerId = $this->repository->getCurrentUserReference()->getUserId(); |
|
|
|
|
709
|
|
|
$contentCreate->remoteId = 'abcdef0123456789abcdef0123456789'; |
710
|
|
|
$contentCreate->alwaysAvailable = true; |
711
|
|
|
|
712
|
|
|
$locationCreates = array( |
713
|
|
|
new LocationCreateStruct( |
714
|
|
|
array( |
715
|
|
|
//priority = 0 |
716
|
|
|
//hidden = false |
717
|
|
|
'remoteId' => 'db787a9143f57828dd4331573466a013', |
718
|
|
|
//sortField = Location::SORT_FIELD_NAME |
719
|
|
|
//sortOrder = Location::SORT_ORDER_ASC |
720
|
|
|
'parentLocationId' => 2, |
721
|
|
|
) |
722
|
|
|
), |
723
|
|
|
new LocationCreateStruct( |
724
|
|
|
array( |
725
|
|
|
//priority = 0 |
726
|
|
|
//hidden = false |
727
|
|
|
'remoteId' => 'a3dd7c1c9e04c89e446a70f647286e6b', |
728
|
|
|
//sortField = Location::SORT_FIELD_NAME |
729
|
|
|
//sortOrder = Location::SORT_ORDER_ASC |
730
|
|
|
'parentLocationId' => 5, |
731
|
|
|
) |
732
|
|
|
), |
733
|
|
|
); |
734
|
|
|
|
735
|
|
|
$contentDraft = $contentService->createContent($contentCreate, $locationCreates); |
736
|
|
|
/* END: Use Case */ |
737
|
|
|
|
738
|
|
|
$this->assertInstanceOf('eZ\\Publish\\API\\Repository\\Values\\Content\\Content', $contentDraft); |
739
|
|
|
|
740
|
|
|
return array( |
741
|
|
|
'expected' => $contentCreate, |
742
|
|
|
'actual' => $contentDraft, |
743
|
|
|
'loadedActual' => $contentService->loadContent($contentDraft->id, null, 1), |
744
|
|
|
'contentType' => $testContentType, |
745
|
|
|
'time' => $time, |
746
|
|
|
); |
747
|
|
|
} |
748
|
|
|
|
749
|
|
|
/** |
750
|
|
|
* Test for the createContent() method. |
751
|
|
|
* |
752
|
|
|
* @depends testCreateContent |
753
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::createContent |
754
|
|
|
* |
755
|
|
|
* @param array $data |
756
|
|
|
*/ |
757
|
|
|
public function testCreateContentStructValues(array $data) |
758
|
|
|
{ |
759
|
|
|
$this->assertCreateContentStructValues($data); |
760
|
|
|
} |
761
|
|
|
|
762
|
|
|
/** |
763
|
|
|
* Test for the createContent() method. |
764
|
|
|
* |
765
|
|
|
* Because of the way ContentHandler::create() is implemented and tested in legacy storage it is also necessary to |
766
|
|
|
* test loaded content object, not only the one returned by ContentService::createContent |
767
|
|
|
* |
768
|
|
|
* @depends testCreateContent |
769
|
|
|
* @depends testLoadContent |
770
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::createContent |
771
|
|
|
* |
772
|
|
|
* @param array $data |
773
|
|
|
*/ |
774
|
|
|
public function testCreateContentStructValuesLoaded(array $data) |
775
|
|
|
{ |
776
|
|
|
$data['actual'] = $data['loadedActual']; |
777
|
|
|
|
778
|
|
|
$this->assertCreateContentStructValues($data); |
779
|
|
|
} |
780
|
|
|
|
781
|
|
|
/** |
782
|
|
|
* Test for the createContent() method. |
783
|
|
|
* |
784
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::createContent |
785
|
|
|
* |
786
|
|
|
* @param array $data |
787
|
|
|
*/ |
788
|
|
|
protected function assertCreateContentStructValues(array $data) |
789
|
|
|
{ |
790
|
|
|
$this->assertCreateContentStructValuesContentInfo($data); |
791
|
|
|
$this->assertCreateContentStructValuesVersionInfo($data); |
792
|
|
|
$this->assertCreateContentStructValuesRelations($data); |
793
|
|
|
$this->assertCreateContentStructValuesFields($data); |
794
|
|
|
} |
795
|
|
|
|
796
|
|
|
/** |
797
|
|
|
* Asserts that ContentInfo is valid after Content creation. |
798
|
|
|
* |
799
|
|
|
* @param array $data |
800
|
|
|
*/ |
801
|
|
|
protected function assertCreateContentStructValuesContentInfo(array $data) |
802
|
|
|
{ |
803
|
|
|
/** @var $contentDraft \eZ\Publish\API\Repository\Values\Content\Content */ |
804
|
|
|
$contentDraft = $data['actual']; |
805
|
|
|
/** @var $contentCreate \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct */ |
806
|
|
|
$contentCreate = $data['expected']; |
807
|
|
|
|
808
|
|
|
$this->assertPropertiesCorrect( |
809
|
|
|
array( |
810
|
|
|
'id' => $contentDraft->id, |
811
|
|
|
'name' => $contentCreate->fields[0]->value, |
|
|
|
|
812
|
|
|
'sectionId' => $contentCreate->sectionId, |
813
|
|
|
'currentVersionNo' => 1, |
814
|
|
|
'published' => false, |
815
|
|
|
'ownerId' => $contentCreate->ownerId, |
816
|
|
|
'modificationDate' => null, |
817
|
|
|
'publishedDate' => null, |
818
|
|
|
'alwaysAvailable' => $contentCreate->alwaysAvailable, |
819
|
|
|
'remoteId' => $contentCreate->remoteId, |
820
|
|
|
'mainLanguageCode' => $contentCreate->mainLanguageCode, |
821
|
|
|
// @todo: should be null, InMemory skips creating node assignments and creates locations right away |
822
|
|
|
//"mainLocationId" => null, |
823
|
|
|
//"contentType" |
824
|
|
|
), |
825
|
|
|
$contentDraft->versionInfo->contentInfo |
826
|
|
|
); |
827
|
|
|
$this->assertNotNull($contentDraft->id); |
828
|
|
|
$this->assertEquals( |
829
|
|
|
$contentCreate->contentType->id, |
830
|
|
|
$contentDraft->versionInfo->contentInfo->contentTypeId |
831
|
|
|
); |
832
|
|
|
} |
833
|
|
|
|
834
|
|
|
/** |
835
|
|
|
* Asserts that VersionInfo is valid after Content creation. |
836
|
|
|
* |
837
|
|
|
* @param array $data |
838
|
|
|
*/ |
839
|
|
|
protected function assertCreateContentStructValuesVersionInfo(array $data) |
840
|
|
|
{ |
841
|
|
|
/** @var $contentDraft \eZ\Publish\API\Repository\Values\Content\Content */ |
842
|
|
|
$contentDraft = $data['actual']; |
843
|
|
|
/** @var $contentCreate \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct */ |
844
|
|
|
$contentCreate = $data['expected']; |
845
|
|
|
$time = $data['time']; |
846
|
|
|
|
847
|
|
|
$this->assertPropertiesCorrect( |
848
|
|
|
array( |
849
|
|
|
//"id" |
850
|
|
|
'versionNo' => 1, |
851
|
|
|
//"creationDate" |
852
|
|
|
//"modificationDate" |
853
|
|
|
'creatorId' => $contentCreate->ownerId, |
854
|
|
|
'status' => VersionInfo::STATUS_DRAFT, |
855
|
|
|
'initialLanguageCode' => $contentCreate->mainLanguageCode, |
856
|
|
|
//"languageCodes" |
857
|
|
|
'names' => array( |
858
|
|
|
'eng-GB' => 'value for field definition with empty default value', |
859
|
|
|
'eng-US' => 'value for field definition with empty default value', |
860
|
|
|
), |
861
|
|
|
), |
862
|
|
|
$contentDraft->versionInfo |
863
|
|
|
); |
864
|
|
|
|
865
|
|
|
$languageCodes = $this->getLanguageCodesFromFields($contentCreate->fields, $contentCreate->mainLanguageCode); |
866
|
|
|
|
867
|
|
|
$this->assertCount(count($languageCodes), $contentDraft->versionInfo->languageCodes); |
868
|
|
|
foreach ($contentDraft->versionInfo->languageCodes as $languageCode) { |
869
|
|
|
$this->assertTrue(in_array($languageCode, $languageCodes)); |
870
|
|
|
} |
871
|
|
|
$this->assertNotNull($contentDraft->versionInfo->id); |
872
|
|
|
$this->assertGreaterThanOrEqual($this->getDateTime($time), $contentDraft->versionInfo->creationDate); |
873
|
|
|
$this->assertGreaterThanOrEqual($this->getDateTime($time), $contentDraft->versionInfo->modificationDate); |
874
|
|
|
} |
875
|
|
|
|
876
|
|
|
/** |
877
|
|
|
* @param array $data |
878
|
|
|
*/ |
879
|
|
|
protected function assertCreateContentStructValuesRelations(array $data) |
|
|
|
|
880
|
|
|
{ |
881
|
|
|
// @todo: relations not implemented yet |
882
|
|
|
} |
883
|
|
|
|
884
|
|
|
/** |
885
|
|
|
* Asserts that fields are valid after Content creation. |
886
|
|
|
* |
887
|
|
|
* @param array $data |
888
|
|
|
*/ |
889
|
|
|
protected function assertCreateContentStructValuesFields(array $data) |
890
|
|
|
{ |
891
|
|
|
/** @var $contentDraft \eZ\Publish\API\Repository\Values\Content\Content */ |
892
|
|
|
$contentDraft = $data['actual']; |
893
|
|
|
/** @var $contentCreate \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct */ |
894
|
|
|
$contentCreate = $data['expected']; |
895
|
|
|
/** @var $contentType \eZ\Publish\API\Repository\Values\ContentType\ContentType */ |
896
|
|
|
$contentType = $data['contentType']; |
897
|
|
|
|
898
|
|
|
$createdFields = $contentDraft->getFields(); |
899
|
|
|
$createdInLanguageCodes = $this->getLanguageCodesFromFields( |
900
|
|
|
$contentCreate->fields, |
901
|
|
|
$contentCreate->mainLanguageCode |
902
|
|
|
); |
903
|
|
|
|
904
|
|
|
$this->assertCount( |
905
|
|
|
count($contentType->fieldDefinitions) * count($createdInLanguageCodes), |
906
|
|
|
$createdFields, |
907
|
|
|
'Number of created fields does not match number of content type field definitions multiplied by number of languages the content is created in' |
908
|
|
|
); |
909
|
|
|
|
910
|
|
|
// Check field values |
911
|
|
|
$structFields = array(); |
912
|
|
|
foreach ($contentCreate->fields as $field) { |
913
|
|
|
$structFields[$field->fieldDefIdentifier][$field->languageCode] = $field; |
914
|
|
|
} |
915
|
|
|
foreach ($contentType->fieldDefinitions as $fieldDefinition) { |
916
|
|
|
$this->assertArrayHasKey( |
917
|
|
|
$fieldDefinition->identifier, |
918
|
|
|
$contentDraft->fields, |
919
|
|
|
"Field values are missing for field definition '{$fieldDefinition->identifier}'" |
920
|
|
|
); |
921
|
|
|
|
922
|
|
|
foreach ($createdInLanguageCodes as $languageCode) { |
923
|
|
|
$this->assertArrayHasKey( |
924
|
|
|
$languageCode, |
925
|
|
|
$contentDraft->fields[$fieldDefinition->identifier], |
926
|
|
|
"Field value is missing for field definition '{$fieldDefinition->identifier}' in language '{$languageCode}'" |
927
|
|
|
); |
928
|
|
|
|
929
|
|
|
// If field is not set in create struct, it should have default value |
930
|
|
|
$valueLanguageCode = $fieldDefinition->isTranslatable ? $languageCode : $contentCreate->mainLanguageCode; |
931
|
|
|
if (isset($structFields[$fieldDefinition->identifier][$valueLanguageCode])) { |
932
|
|
|
$this->assertEquals( |
933
|
|
|
$structFields[$fieldDefinition->identifier][$valueLanguageCode]->value, |
934
|
|
|
$contentDraft->fields[$fieldDefinition->identifier][$languageCode], |
935
|
|
|
"Field value for field definition '{$fieldDefinition->identifier}' in language '{$languageCode}' is not equal to given struct field value" |
936
|
|
|
); |
937
|
|
|
} else { |
938
|
|
|
$this->assertEquals( |
939
|
|
|
$fieldDefinition->defaultValue, |
|
|
|
|
940
|
|
|
$contentDraft->fields[$fieldDefinition->identifier][$languageCode], |
941
|
|
|
"Field value for field definition '{$fieldDefinition->identifier}' in language '{$languageCode}' is not equal to default value" |
942
|
|
|
); |
943
|
|
|
} |
944
|
|
|
} |
945
|
|
|
} |
946
|
|
|
} |
947
|
|
|
|
948
|
|
|
/** |
949
|
|
|
* Gathers language codes from an array of fields. |
950
|
|
|
* |
951
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Field[] $fields |
952
|
|
|
* @param string $mainLanguageCode |
953
|
|
|
* |
954
|
|
|
* @return array an array of language code strings |
955
|
|
|
*/ |
956
|
|
|
protected function getLanguageCodesFromFields(array $fields, $mainLanguageCode) |
957
|
|
|
{ |
958
|
|
|
$languageCodes = array($mainLanguageCode); |
959
|
|
|
foreach ($fields as $field) { |
960
|
|
|
$languageCodes[] = $field->languageCode; |
961
|
|
|
} |
962
|
|
|
|
963
|
|
|
return array_unique($languageCodes); |
964
|
|
|
} |
965
|
|
|
|
966
|
|
|
/** |
967
|
|
|
* Test for the createContent() method. |
968
|
|
|
* |
969
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::createContent |
970
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
971
|
|
|
*/ |
972
|
|
|
public function testCreateContentThrowsUnauthorizedException() |
973
|
|
|
{ |
974
|
|
|
$testContentType = $this->createTestContentType(); |
975
|
|
|
$contentService = $this->repository->getContentService(); |
976
|
|
|
|
977
|
|
|
$contentCreate = $contentService->newContentCreateStruct($testContentType, 'eng-GB'); |
978
|
|
|
$contentCreate->setField('test_required_empty', 'value for field definition with empty default value'); |
979
|
|
|
$contentCreate->setField('test_translatable', 'and thumbs opposable', 'eng-US'); |
980
|
|
|
$contentCreate->sectionId = 1; |
981
|
|
|
$contentCreate->ownerId = $this->repository->getCurrentUserReference()->getUserId(); |
|
|
|
|
982
|
|
|
$contentCreate->remoteId = 'abcdef0123456789abcdef0123456789'; |
983
|
|
|
$contentCreate->alwaysAvailable = true; |
984
|
|
|
|
985
|
|
|
$locationCreates = array( |
986
|
|
|
new LocationCreateStruct( |
987
|
|
|
array( |
988
|
|
|
'remoteId' => 'db787a9143f57828dd4331573466a013', |
989
|
|
|
'parentLocationId' => 2, |
990
|
|
|
) |
991
|
|
|
), |
992
|
|
|
); |
993
|
|
|
|
994
|
|
|
// Set anonymous as current user |
995
|
|
|
$this->repository->setCurrentUser($this->getStubbedUser(10)); |
|
|
|
|
996
|
|
|
|
997
|
|
|
$contentService->createContent($contentCreate, $locationCreates); |
998
|
|
|
} |
999
|
|
|
|
1000
|
|
|
/** |
1001
|
|
|
* Test for the createContent() method. |
1002
|
|
|
* |
1003
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::createContent |
1004
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
1005
|
|
|
*/ |
1006
|
|
|
public function testCreateContentWithoutLocationsThrowsUnauthorizedException() |
1007
|
|
|
{ |
1008
|
|
|
$testContentType = $this->createTestContentType(); |
1009
|
|
|
$contentService = $this->repository->getContentService(); |
1010
|
|
|
|
1011
|
|
|
$contentCreate = $contentService->newContentCreateStruct($testContentType, 'eng-GB'); |
1012
|
|
|
$contentCreate->setField('test_required_empty', 'value for field definition with empty default value'); |
1013
|
|
|
$contentCreate->setField('test_translatable', 'and thumbs opposable', 'eng-US'); |
1014
|
|
|
$contentCreate->sectionId = 1; |
1015
|
|
|
$contentCreate->ownerId = $this->repository->getCurrentUserReference()->getUserId(); |
|
|
|
|
1016
|
|
|
$contentCreate->remoteId = 'abcdef0123456789abcdef0123456789'; |
1017
|
|
|
$contentCreate->alwaysAvailable = true; |
1018
|
|
|
|
1019
|
|
|
// Set anonymous as current user |
1020
|
|
|
$this->repository->setCurrentUser($this->getStubbedUser(10)); |
|
|
|
|
1021
|
|
|
|
1022
|
|
|
$contentService->createContent($contentCreate, array()); |
1023
|
|
|
} |
1024
|
|
|
|
1025
|
|
|
/** |
1026
|
|
|
* Test for the createContent() method. |
1027
|
|
|
* |
1028
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::createContent |
1029
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
1030
|
|
|
*/ |
1031
|
|
|
public function testCreateContentThrowsInvalidArgumentException() |
1032
|
|
|
{ |
1033
|
|
|
$testContentType = $this->createTestContentType(); |
1034
|
|
|
|
1035
|
|
|
/* BEGIN: Use Case */ |
1036
|
|
|
$contentService = $this->repository->getContentService(); |
1037
|
|
|
|
1038
|
|
|
$contentCreate = $contentService->newContentCreateStruct($testContentType, 'eng-GB'); |
1039
|
|
|
$contentCreate->setField('test_required_empty', 'value for field definition with empty default value'); |
1040
|
|
|
$contentCreate->sectionId = 1; |
1041
|
|
|
$contentCreate->ownerId = 14; |
1042
|
|
|
$contentCreate->remoteId = 'f5c88a2209584891056f987fd965b0ba'; |
1043
|
|
|
$contentCreate->alwaysAvailable = true; |
1044
|
|
|
|
1045
|
|
|
// Throws an exception because remoteId "f5c88a2209584891056f987fd965b0ba" already exists |
1046
|
|
|
$contentService->createContent($contentCreate); |
1047
|
|
|
/* END: Use Case */ |
1048
|
|
|
} |
1049
|
|
|
|
1050
|
|
|
/** |
1051
|
|
|
* Test for the createContent() method. |
1052
|
|
|
* |
1053
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::createContent |
1054
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\ContentValidationException |
1055
|
|
|
* |
1056
|
|
|
* @return array |
1057
|
|
|
*/ |
1058
|
|
View Code Duplication |
public function testCreateContentThrowsContentValidationExceptionFieldDefinitionUnexisting() |
1059
|
|
|
{ |
1060
|
|
|
$testContentType = $this->createTestContentType(); |
1061
|
|
|
|
1062
|
|
|
/* BEGIN: Use Case */ |
1063
|
|
|
$contentService = $this->repository->getContentService(); |
1064
|
|
|
|
1065
|
|
|
$contentCreate = $contentService->newContentCreateStruct($testContentType, 'eng-GB'); |
1066
|
|
|
$contentCreate->setField('test_required_empty', 'value for field definition with empty default value'); |
1067
|
|
|
$contentCreate->setField('humpty_dumpty', 'no such field definition'); |
1068
|
|
|
$contentCreate->sectionId = 1; |
1069
|
|
|
$contentCreate->ownerId = 14; |
1070
|
|
|
$contentCreate->remoteId = 'abcdef0123456789abcdef0123456789'; |
1071
|
|
|
$contentCreate->alwaysAvailable = true; |
1072
|
|
|
|
1073
|
|
|
// Throws an exception because field definition with identifier "humpty_dumpty" does not exist |
1074
|
|
|
$contentService->createContent($contentCreate); |
1075
|
|
|
/* END: Use Case */ |
1076
|
|
|
} |
1077
|
|
|
|
1078
|
|
|
/** |
1079
|
|
|
* Test for the createContent() method. |
1080
|
|
|
* |
1081
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::createContent |
1082
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\ContentValidationException |
1083
|
|
|
* |
1084
|
|
|
* @return array |
1085
|
|
|
*/ |
1086
|
|
View Code Duplication |
public function testCreateContentThrowsContentValidationExceptionUntranslatableField() |
1087
|
|
|
{ |
1088
|
|
|
$testContentType = $this->createTestContentType(); |
1089
|
|
|
|
1090
|
|
|
/* BEGIN: Use Case */ |
1091
|
|
|
$contentService = $this->repository->getContentService(); |
1092
|
|
|
|
1093
|
|
|
$contentCreate = $contentService->newContentCreateStruct($testContentType, 'eng-GB'); |
1094
|
|
|
$contentCreate->setField('test_required_empty', 'value for field definition with empty default value'); |
1095
|
|
|
$contentCreate->setField('test_untranslatable', 'Bandersnatch', 'eng-US'); |
1096
|
|
|
$contentCreate->sectionId = 1; |
1097
|
|
|
$contentCreate->ownerId = 14; |
1098
|
|
|
$contentCreate->remoteId = 'abcdef0123456789abcdef0123456789'; |
1099
|
|
|
$contentCreate->alwaysAvailable = true; |
1100
|
|
|
|
1101
|
|
|
// Throws an exception because translation was given for a untranslatable field |
1102
|
|
|
// Note that it is still permissible to set untranslatable field with main language |
1103
|
|
|
$contentService->createContent($contentCreate); |
1104
|
|
|
/* END: Use Case */ |
1105
|
|
|
} |
1106
|
|
|
|
1107
|
|
|
/** |
1108
|
|
|
* Test for the createContent() method. |
1109
|
|
|
* |
1110
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::createContent |
1111
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException |
1112
|
|
|
* |
1113
|
|
|
* @return array |
1114
|
|
|
*/ |
1115
|
|
|
public function testCreateContentRequiredFieldDefaultValueEmpty() |
1116
|
|
|
{ |
1117
|
|
|
$testContentType = $this->createTestContentType(); |
1118
|
|
|
|
1119
|
|
|
/* BEGIN: Use Case */ |
1120
|
|
|
$contentService = $this->repository->getContentService(); |
1121
|
|
|
|
1122
|
|
|
$contentCreate = $contentService->newContentCreateStruct($testContentType, 'eng-GB'); |
1123
|
|
|
$contentCreate->setField('test_translatable', 'Jabberwock'); |
1124
|
|
|
$contentCreate->sectionId = 1; |
1125
|
|
|
$contentCreate->ownerId = 14; |
1126
|
|
|
$contentCreate->remoteId = 'abcdef0123456789abcdef0123456789'; |
1127
|
|
|
$contentCreate->alwaysAvailable = true; |
1128
|
|
|
|
1129
|
|
|
// Throws an exception because required field is not set and its default value is empty |
1130
|
|
|
$contentService->createContent($contentCreate); |
1131
|
|
|
/* END: Use Case */ |
1132
|
|
|
} |
1133
|
|
|
|
1134
|
|
|
/** |
1135
|
|
|
* Test for the createContent() method. |
1136
|
|
|
* |
1137
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::createContent |
1138
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException |
1139
|
|
|
*/ |
1140
|
|
View Code Duplication |
public function testCreateContentThrowsContentFieldValidationException() |
1141
|
|
|
{ |
1142
|
|
|
$testContentType = $this->createTestContentType(); |
1143
|
|
|
|
1144
|
|
|
/* BEGIN: Use Case */ |
1145
|
|
|
$contentService = $this->repository->getContentService(); |
1146
|
|
|
|
1147
|
|
|
$contentCreate = $contentService->newContentCreateStruct($testContentType, 'eng-GB'); |
1148
|
|
|
$contentCreate->setField( |
1149
|
|
|
'test_required_empty', |
1150
|
|
|
'a string that is too long and will not validate 12345678901234567890123456789012345678901234567890' |
1151
|
|
|
); |
1152
|
|
|
$contentCreate->setField('test_translatable', 'and thumbs opposable', 'eng-US'); |
1153
|
|
|
$contentCreate->sectionId = 1; |
1154
|
|
|
$contentCreate->ownerId = 14; |
1155
|
|
|
$contentCreate->remoteId = 'abcdef0123456789abcdef0123456789'; |
1156
|
|
|
$contentCreate->alwaysAvailable = true; |
1157
|
|
|
|
1158
|
|
|
// Throws an exception because "test_required_empty" field value is too long and fails |
1159
|
|
|
// field definition's string length validator |
1160
|
|
|
$contentService->createContent($contentCreate); |
1161
|
|
|
/* END: Use Case */ |
1162
|
|
|
} |
1163
|
|
|
|
1164
|
|
|
/** |
1165
|
|
|
* Test for the newContentMetadataUpdateStruct() method. |
1166
|
|
|
* |
1167
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::newContentMetadataUpdateStruct |
1168
|
|
|
*/ |
1169
|
|
View Code Duplication |
public function testNewContentMetadataUpdateStruct() |
1170
|
|
|
{ |
1171
|
|
|
/* BEGIN: Use Case */ |
1172
|
|
|
$contentService = $this->repository->getContentService(); |
1173
|
|
|
|
1174
|
|
|
$contentMetadataUpdateStruct = $contentService->newContentMetadataUpdateStruct(); |
1175
|
|
|
/* END: Use Case */ |
1176
|
|
|
|
1177
|
|
|
$this->assertInstanceOf( |
1178
|
|
|
'eZ\\Publish\\API\\Repository\\Values\\Content\\ContentMetadataUpdateStruct', |
1179
|
|
|
$contentMetadataUpdateStruct |
1180
|
|
|
); |
1181
|
|
|
|
1182
|
|
|
foreach ($contentMetadataUpdateStruct as $propertyName => $propertyValue) { |
|
|
|
|
1183
|
|
|
$this->assertNull($propertyValue, "Property '{$propertyName}' initial value should be null'"); |
1184
|
|
|
} |
1185
|
|
|
} |
1186
|
|
|
|
1187
|
|
|
/** |
1188
|
|
|
* Test for the updateContentMetadata() method. |
1189
|
|
|
* |
1190
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::updateContentMetadata |
1191
|
|
|
* @depends testNewContentMetadataUpdateStruct |
1192
|
|
|
* |
1193
|
|
|
* @return array |
1194
|
|
|
*/ |
1195
|
|
|
public function testUpdateContentMetadata() |
1196
|
|
|
{ |
1197
|
|
|
// Create one additional location for content to be set as main location |
1198
|
|
|
$locationService = $this->repository->getLocationService(); |
1199
|
|
|
$contentInfo = $this->repository->getContentService()->loadContentInfo(12); |
1200
|
|
|
$locationCreateStruct = $locationService->newLocationCreateStruct(44); |
1201
|
|
|
$locationCreateStruct->remoteId = 'test-location-remote-id-1234'; |
1202
|
|
|
$newLocation = $locationService->createLocation( |
1203
|
|
|
$contentInfo, |
1204
|
|
|
$locationCreateStruct |
1205
|
|
|
); |
1206
|
|
|
$newSectionId = $this->repository->getContentService()->loadContentInfo( |
1207
|
|
|
$locationService->loadLocation($newLocation->parentLocationId)->contentId |
1208
|
|
|
)->sectionId; |
1209
|
|
|
// Change content section to be different from new main location parent location content |
1210
|
|
|
$sectionService = $this->repository->getSectionService(); |
1211
|
|
|
$sectionService->assignSection( |
1212
|
|
|
$contentInfo, |
1213
|
|
|
$sectionService->loadSection($newSectionId === 1 ? $newSectionId + 1 : $newSectionId - 1) |
1214
|
|
|
); |
1215
|
|
|
|
1216
|
|
|
/* BEGIN: Use Case */ |
1217
|
|
|
$contentService = $this->repository->getContentService(); |
1218
|
|
|
|
1219
|
|
|
$contentInfo = $contentService->loadContentInfo(12); |
1220
|
|
|
|
1221
|
|
|
$newMainLocationId = $newLocation->id; |
1222
|
|
|
$time = time(); |
1223
|
|
|
$contentMetadataUpdateStruct = $contentService->newContentMetadataUpdateStruct(); |
1224
|
|
|
$contentMetadataUpdateStruct->ownerId = 10; |
1225
|
|
|
$contentMetadataUpdateStruct->publishedDate = $this->getDateTime($time); |
1226
|
|
|
$contentMetadataUpdateStruct->modificationDate = $this->getDateTime($time); |
1227
|
|
|
$contentMetadataUpdateStruct->mainLanguageCode = 'eng-GB'; |
1228
|
|
|
$contentMetadataUpdateStruct->alwaysAvailable = false; |
1229
|
|
|
$contentMetadataUpdateStruct->remoteId = 'the-all-new-remoteid'; |
1230
|
|
|
$contentMetadataUpdateStruct->mainLocationId = $newMainLocationId; |
1231
|
|
|
|
1232
|
|
|
$content = $contentService->updateContentMetadata($contentInfo, $contentMetadataUpdateStruct); |
1233
|
|
|
/* END: Use Case */ |
1234
|
|
|
|
1235
|
|
|
$this->assertInstanceOf('eZ\\Publish\\API\\Repository\\Values\\Content\\Content', $content); |
1236
|
|
|
|
1237
|
|
|
return array( |
1238
|
|
|
'expected' => $contentMetadataUpdateStruct, |
1239
|
|
|
'actual' => $content, |
1240
|
|
|
'newSectionId' => $newSectionId, |
1241
|
|
|
); |
1242
|
|
|
} |
1243
|
|
|
|
1244
|
|
|
/** |
1245
|
|
|
* Test for the updateContentMetadata() method. |
1246
|
|
|
* |
1247
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::updateContentMetadata |
1248
|
|
|
* @depends testUpdateContentMetadata |
1249
|
|
|
* |
1250
|
|
|
* @param array $data |
1251
|
|
|
*/ |
1252
|
|
|
public function testUpdateContentMetadataStructValues(array $data) |
1253
|
|
|
{ |
1254
|
|
|
/** @var $updateStruct \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct */ |
1255
|
|
|
$updateStruct = $data['expected']; |
1256
|
|
|
/** @var $content \eZ\Publish\API\Repository\Values\Content\Content */ |
1257
|
|
|
$content = $data['actual']; |
1258
|
|
|
|
1259
|
|
|
$this->assertPropertiesCorrect( |
1260
|
|
|
array( |
1261
|
|
|
'ownerId' => $updateStruct->ownerId, |
1262
|
|
|
// not changeable through MetadataUpdateStruct |
1263
|
|
|
//"name" |
1264
|
|
|
'publishedDate' => $updateStruct->publishedDate, |
1265
|
|
|
'modificationDate' => $updateStruct->modificationDate, |
1266
|
|
|
'mainLanguageCode' => $updateStruct->mainLanguageCode, |
1267
|
|
|
'alwaysAvailable' => $updateStruct->alwaysAvailable, |
1268
|
|
|
'remoteId' => $updateStruct->remoteId, |
1269
|
|
|
'mainLocationId' => $updateStruct->mainLocationId, |
1270
|
|
|
'sectionId' => $data['newSectionId'], |
1271
|
|
|
), |
1272
|
|
|
$content->contentInfo |
1273
|
|
|
); |
1274
|
|
|
} |
1275
|
|
|
|
1276
|
|
|
/** |
1277
|
|
|
* Test for the updateContentMetadata() method. |
1278
|
|
|
* |
1279
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::updateContentMetadata |
1280
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
1281
|
|
|
*/ |
1282
|
|
|
public function testUpdateContentMetadataThrowsUnauthorizedException() |
1283
|
|
|
{ |
1284
|
|
|
$contentInfo = $this->repository->getContentService()->loadContentInfo(12); |
1285
|
|
|
$contentMetadataUpdateStruct = $this->repository->getContentService()->newContentMetadataUpdateStruct(); |
1286
|
|
|
$contentMetadataUpdateStruct->remoteId = 'the-all-new-remoteid'; |
1287
|
|
|
|
1288
|
|
|
// Set anonymous as current user |
1289
|
|
|
$this->repository->setCurrentUser($this->getStubbedUser(10)); |
|
|
|
|
1290
|
|
|
|
1291
|
|
|
$this->repository->getContentService()->updateContentMetadata($contentInfo, $contentMetadataUpdateStruct); |
1292
|
|
|
} |
1293
|
|
|
|
1294
|
|
|
/** |
1295
|
|
|
* Test for the updateContentMetadata() method. |
1296
|
|
|
* |
1297
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::updateContentMetadata |
1298
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
1299
|
|
|
* @depends testNewContentMetadataUpdateStruct |
1300
|
|
|
*/ |
1301
|
|
|
public function testUpdateContentMetadataThrowsInvalidArgumentExceptionDuplicateRemoteId() |
1302
|
|
|
{ |
1303
|
|
|
/* BEGIN: Use Case */ |
1304
|
|
|
$contentService = $this->repository->getContentService(); |
1305
|
|
|
$contentInfo = $contentService->loadContentInfo(4); |
1306
|
|
|
$contentMetadataUpdateStruct = $contentService->newContentMetadataUpdateStruct(); |
1307
|
|
|
$contentMetadataUpdateStruct->remoteId = '9b47a45624b023b1a76c73b74d704acf'; |
1308
|
|
|
|
1309
|
|
|
// Throws an exception because remoteId "9b47a45624b023b1a76c73b74d704acf" is already in use |
1310
|
|
|
$contentService->updateContentMetadata($contentInfo, $contentMetadataUpdateStruct); |
1311
|
|
|
/* END: Use Case */ |
1312
|
|
|
} |
1313
|
|
|
|
1314
|
|
|
/** |
1315
|
|
|
* Test for the updateContentMetadata() method. |
1316
|
|
|
* |
1317
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::updateContentMetadata |
1318
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
1319
|
|
|
* @depends testNewContentMetadataUpdateStruct |
1320
|
|
|
*/ |
1321
|
|
|
public function testUpdateContentMetadataThrowsInvalidArgumentExceptionNoMetadataPropertiesSet() |
1322
|
|
|
{ |
1323
|
|
|
/* BEGIN: Use Case */ |
1324
|
|
|
$contentService = $this->repository->getContentService(); |
1325
|
|
|
$contentInfo = $contentService->loadContentInfo(4); |
1326
|
|
|
$contentMetadataUpdateStruct = $contentService->newContentMetadataUpdateStruct(); |
1327
|
|
|
|
1328
|
|
|
// Throws an exception because no properties are set in $contentMetadataUpdateStruct |
1329
|
|
|
$contentService->updateContentMetadata($contentInfo, $contentMetadataUpdateStruct); |
1330
|
|
|
/* END: Use Case */ |
1331
|
|
|
} |
1332
|
|
|
|
1333
|
|
|
/** |
1334
|
|
|
* Test for the newContentUpdateStruct() method. |
1335
|
|
|
* |
1336
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::newContentUpdateStruct |
1337
|
|
|
*/ |
1338
|
|
View Code Duplication |
public function testNewContentUpdateStruct() |
1339
|
|
|
{ |
1340
|
|
|
/* BEGIN: Use Case */ |
1341
|
|
|
$contentService = $this->repository->getContentService(); |
1342
|
|
|
|
1343
|
|
|
$contentUpdateStruct = $contentService->newContentUpdateStruct(); |
1344
|
|
|
/* END: Use Case */ |
1345
|
|
|
|
1346
|
|
|
$this->assertInstanceOf( |
1347
|
|
|
'eZ\\Publish\\API\\Repository\\Values\\Content\\ContentUpdateStruct', |
1348
|
|
|
$contentUpdateStruct |
1349
|
|
|
); |
1350
|
|
|
|
1351
|
|
|
$this->assertPropertiesCorrect( |
1352
|
|
|
array( |
1353
|
|
|
'initialLanguageCode' => null, |
1354
|
|
|
'fields' => array(), |
1355
|
|
|
), |
1356
|
|
|
$contentUpdateStruct |
1357
|
|
|
); |
1358
|
|
|
} |
1359
|
|
|
|
1360
|
|
|
/** |
1361
|
|
|
* Test for the updateContent() method. |
1362
|
|
|
* |
1363
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::updateContent |
1364
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
1365
|
|
|
*/ |
1366
|
|
|
public function testUpdateContentThrowsUnauthorizedException() |
1367
|
|
|
{ |
1368
|
|
|
list($content, $contentType) = $this->createTestContent(); |
|
|
|
|
1369
|
|
|
|
1370
|
|
|
$contentUpdateStruct = $this->repository->getContentService()->newContentUpdateStruct(); |
1371
|
|
|
$contentUpdateStruct->initialLanguageCode = 'eng-US'; |
1372
|
|
|
$contentUpdateStruct->setField('test_required_empty', 'new value for test_required_empty'); |
1373
|
|
|
|
1374
|
|
|
// Set anonymous as current user |
1375
|
|
|
$this->repository->setCurrentUser($this->getStubbedUser(10)); |
|
|
|
|
1376
|
|
|
|
1377
|
|
|
$this->repository->getContentService()->updateContent( |
1378
|
|
|
$content->versionInfo, |
1379
|
|
|
$contentUpdateStruct |
1380
|
|
|
); |
1381
|
|
|
} |
1382
|
|
|
|
1383
|
|
|
/** |
1384
|
|
|
* Test for the updateContent() method. |
1385
|
|
|
* |
1386
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::updateContent |
1387
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException |
1388
|
|
|
*/ |
1389
|
|
|
public function testUpdateContentThrowsBadStateException() |
1390
|
|
|
{ |
1391
|
|
|
/* BEGIN: Use Case */ |
1392
|
|
|
$contentService = $this->repository->getContentService(); |
1393
|
|
|
|
1394
|
|
|
$versionInfo = $contentService->loadVersionInfoById(4); |
1395
|
|
|
$contentUpdateStruct = $contentService->newContentUpdateStruct(); |
1396
|
|
|
|
1397
|
|
|
// Throws an exception because version is not a draft |
1398
|
|
|
$updatedContent = $contentService->updateContent($versionInfo, $contentUpdateStruct); |
|
|
|
|
1399
|
|
|
/* END: Use Case */ |
1400
|
|
|
} |
1401
|
|
|
|
1402
|
|
|
/** |
1403
|
|
|
* Test for the updateContent() method. |
1404
|
|
|
* |
1405
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::updateContent |
1406
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException |
1407
|
|
|
*/ |
1408
|
|
View Code Duplication |
public function testUpdateContentThrowsContentFieldValidationException() |
1409
|
|
|
{ |
1410
|
|
|
list($content, $contentType) = $this->createTestContent(); |
|
|
|
|
1411
|
|
|
|
1412
|
|
|
/* BEGIN: Use Case */ |
1413
|
|
|
$contentService = $this->repository->getContentService(); |
1414
|
|
|
|
1415
|
|
|
$versionInfo = $contentService->loadVersionInfoById( |
1416
|
|
|
$content->id, |
1417
|
|
|
$content->getVersionInfo()->versionNo |
1418
|
|
|
); |
1419
|
|
|
|
1420
|
|
|
$contentUpdateStruct = $contentService->newContentUpdateStruct(); |
1421
|
|
|
$contentUpdateStruct->initialLanguageCode = 'eng-US'; |
1422
|
|
|
$contentUpdateStruct->setField( |
1423
|
|
|
'test_required_empty', |
1424
|
|
|
'a string that is too long and will not validate 12345678901234567890123456789012345678901234567890' |
1425
|
|
|
); |
1426
|
|
|
|
1427
|
|
|
// Throws an exception because "test_required_empty" field value is too long and fails |
1428
|
|
|
// field definition's string length validator |
1429
|
|
|
$updatedContent = $contentService->updateContent($versionInfo, $contentUpdateStruct); |
|
|
|
|
1430
|
|
|
/* END: Use Case */ |
1431
|
|
|
} |
1432
|
|
|
|
1433
|
|
|
/** |
1434
|
|
|
* Test for the updateContent() method. |
1435
|
|
|
* |
1436
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::updateContent |
1437
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException |
1438
|
|
|
*/ |
1439
|
|
View Code Duplication |
public function testUpdateContentRequiredFieldEmpty() |
1440
|
|
|
{ |
1441
|
|
|
list($content, $contentType) = $this->createTestContent(); |
|
|
|
|
1442
|
|
|
|
1443
|
|
|
/* BEGIN: Use Case */ |
1444
|
|
|
$contentService = $this->repository->getContentService(); |
1445
|
|
|
|
1446
|
|
|
$versionInfo = $contentService->loadVersionInfoById( |
1447
|
|
|
$content->id, |
1448
|
|
|
$content->getVersionInfo()->versionNo |
1449
|
|
|
); |
1450
|
|
|
|
1451
|
|
|
$contentUpdateStruct = $contentService->newContentUpdateStruct(); |
1452
|
|
|
$contentUpdateStruct->initialLanguageCode = 'eng-GB'; |
1453
|
|
|
$contentUpdateStruct->setField('test_required_empty', ''); |
1454
|
|
|
|
1455
|
|
|
// Throws an exception because required field is being updated with empty value |
1456
|
|
|
$updatedContent = $contentService->updateContent($versionInfo, $contentUpdateStruct); |
|
|
|
|
1457
|
|
|
/* END: Use Case */ |
1458
|
|
|
} |
1459
|
|
|
|
1460
|
|
|
/** |
1461
|
|
|
* Test for the updateContent() method. |
1462
|
|
|
* |
1463
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::updateContent |
1464
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\ContentValidationException |
1465
|
|
|
*/ |
1466
|
|
View Code Duplication |
public function testUpdateContentThrowsContentValidationExceptionFieldDefinitionNonexistent() |
1467
|
|
|
{ |
1468
|
|
|
list($content, $contentType) = $this->createTestContent(); |
|
|
|
|
1469
|
|
|
|
1470
|
|
|
/* BEGIN: Use Case */ |
1471
|
|
|
$contentService = $this->repository->getContentService(); |
1472
|
|
|
|
1473
|
|
|
$versionInfo = $contentService->loadVersionInfoById( |
1474
|
|
|
$content->id, |
1475
|
|
|
$content->getVersionInfo()->versionNo |
1476
|
|
|
); |
1477
|
|
|
|
1478
|
|
|
$contentUpdateStruct = $contentService->newContentUpdateStruct(); |
1479
|
|
|
$contentUpdateStruct->initialLanguageCode = 'eng-GB'; |
1480
|
|
|
$contentUpdateStruct->setField('nonexistent_field_definition_identifier', 'eng-GB'); |
1481
|
|
|
|
1482
|
|
|
// Throws an exception because field definition with identifier "nonexistent_field_definition_identifier" |
1483
|
|
|
// does not exist in content draft content type |
1484
|
|
|
$updatedContent = $contentService->updateContent($versionInfo, $contentUpdateStruct); |
|
|
|
|
1485
|
|
|
/* END: Use Case */ |
1486
|
|
|
} |
1487
|
|
|
|
1488
|
|
|
/** |
1489
|
|
|
* Test for the updateContent() method. |
1490
|
|
|
* |
1491
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::updateContent |
1492
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\ContentValidationException |
1493
|
|
|
* |
1494
|
|
|
* @return array |
1495
|
|
|
*/ |
1496
|
|
View Code Duplication |
public function testUpdateContentThrowsContentValidationExceptionUntranslatableField() |
1497
|
|
|
{ |
1498
|
|
|
list($content, $contentType) = $this->createTestContent(); |
|
|
|
|
1499
|
|
|
|
1500
|
|
|
/* BEGIN: Use Case */ |
1501
|
|
|
$contentService = $this->repository->getContentService(); |
1502
|
|
|
|
1503
|
|
|
$versionInfo = $contentService->loadVersionInfoById( |
1504
|
|
|
$content->id, |
1505
|
|
|
$content->getVersionInfo()->versionNo |
1506
|
|
|
); |
1507
|
|
|
|
1508
|
|
|
$contentUpdateStruct = $contentService->newContentUpdateStruct(); |
1509
|
|
|
$contentUpdateStruct->initialLanguageCode = 'eng-GB'; |
1510
|
|
|
$contentUpdateStruct->setField('test_untranslatable', 'Jabberwock', 'eng-US'); |
1511
|
|
|
|
1512
|
|
|
// Throws an exception because translation was given for a untranslatable field |
1513
|
|
|
// Note that it is still permissible to set untranslatable field with main language |
1514
|
|
|
$updatedContent = $contentService->updateContent($versionInfo, $contentUpdateStruct); |
|
|
|
|
1515
|
|
|
/* END: Use Case */ |
1516
|
|
|
} |
1517
|
|
|
|
1518
|
|
|
/** |
1519
|
|
|
* Test for the publishVersion() method. |
1520
|
|
|
* |
1521
|
|
|
* @depends testCreateContent |
1522
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::publishVersion |
1523
|
|
|
*/ |
1524
|
|
|
public function testPublishVersion() |
1525
|
|
|
{ |
1526
|
|
|
$time = time(); |
1527
|
|
|
list($draftContent, $contentType) = $this->createTestContent(); |
|
|
|
|
1528
|
|
|
|
1529
|
|
|
/* BEGIN: Use Case */ |
1530
|
|
|
$contentService = $this->repository->getContentService(); |
1531
|
|
|
|
1532
|
|
|
$versionInfo = $contentService->loadVersionInfoById( |
1533
|
|
|
$draftContent->id, |
1534
|
|
|
$draftContent->getVersionInfo()->versionNo |
1535
|
|
|
); |
1536
|
|
|
|
1537
|
|
|
$publishedContent = $contentService->publishVersion($versionInfo); |
1538
|
|
|
/* END: Use Case */ |
1539
|
|
|
|
1540
|
|
|
$this->assertInstanceOf('eZ\\Publish\\API\\Repository\\Values\\Content\\Content', $publishedContent); |
1541
|
|
|
$this->assertTrue($publishedContent->contentInfo->published); |
1542
|
|
|
$this->assertEquals(VersionInfo::STATUS_PUBLISHED, $publishedContent->versionInfo->status); |
1543
|
|
|
$this->assertGreaterThanOrEqual($time, $publishedContent->contentInfo->publishedDate->getTimestamp()); |
1544
|
|
|
$this->assertGreaterThanOrEqual($time, $publishedContent->contentInfo->modificationDate->getTimestamp()); |
1545
|
|
|
} |
1546
|
|
|
|
1547
|
|
|
public function testPublishVersionDoesNotChangePublishedDate() |
1548
|
|
|
{ |
1549
|
|
|
list($draftContent, $contentType) = $this->createTestContent(); |
|
|
|
|
1550
|
|
|
|
1551
|
|
|
$contentService = $this->repository->getContentService(); |
1552
|
|
|
|
1553
|
|
|
$versionInfo = $contentService->loadVersionInfoById( |
1554
|
|
|
$draftContent->id, |
1555
|
|
|
$draftContent->getVersionInfo()->versionNo |
1556
|
|
|
); |
1557
|
|
|
|
1558
|
|
|
$publishedContent = $contentService->publishVersion($versionInfo); |
1559
|
|
|
|
1560
|
|
|
sleep(1); |
1561
|
|
|
|
1562
|
|
|
/* BEGIN: Use Case */ |
1563
|
|
|
$contentDraft = $contentService->createContentDraft($publishedContent->contentInfo); |
1564
|
|
|
$contentUpdateStruct = $contentService->newContentUpdateStruct(); |
1565
|
|
|
$contentUpdateStruct->initialLanguageCode = 'eng-GB'; |
1566
|
|
|
$contentDraft = $contentService->updateContent($contentDraft->versionInfo, $contentUpdateStruct); |
1567
|
|
|
$republishedContent = $contentService->publishVersion($contentDraft->versionInfo); |
1568
|
|
|
/* END: Use Case */ |
1569
|
|
|
|
1570
|
|
|
$this->assertEquals( |
1571
|
|
|
$publishedContent->contentInfo->publishedDate->getTimestamp(), |
1572
|
|
|
$republishedContent->contentInfo->publishedDate->getTimestamp() |
1573
|
|
|
); |
1574
|
|
|
$this->assertGreaterThan( |
1575
|
|
|
$publishedContent->contentInfo->modificationDate->getTimestamp(), |
1576
|
|
|
$republishedContent->contentInfo->modificationDate->getTimestamp() |
1577
|
|
|
); |
1578
|
|
|
} |
1579
|
|
|
|
1580
|
|
|
/** |
1581
|
|
|
* Test for the publishVersion() method. |
1582
|
|
|
* |
1583
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::publishVersion |
1584
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException |
1585
|
|
|
*/ |
1586
|
|
|
public function testPublishVersionThrowsBadStateException() |
1587
|
|
|
{ |
1588
|
|
|
/* BEGIN: Use Case */ |
1589
|
|
|
$contentService = $this->repository->getContentService(); |
1590
|
|
|
|
1591
|
|
|
$versionInfo = $contentService->loadVersionInfoById(4); |
1592
|
|
|
|
1593
|
|
|
// Throws an exception because version is already published |
1594
|
|
|
$publishedContent = $contentService->publishVersion($versionInfo); |
|
|
|
|
1595
|
|
|
/* END: Use Case */ |
1596
|
|
|
} |
1597
|
|
|
|
1598
|
|
|
/** |
1599
|
|
|
* Test for the publishVersion() method. |
1600
|
|
|
* |
1601
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::publishVersion |
1602
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
1603
|
|
|
*/ |
1604
|
|
View Code Duplication |
public function testPublishVersionThrowsUnauthorizedException() |
1605
|
|
|
{ |
1606
|
|
|
list($draftContent, $contentType) = $this->createTestContent(); |
|
|
|
|
1607
|
|
|
|
1608
|
|
|
// Set anonymous as current user |
1609
|
|
|
$this->repository->setCurrentUser($this->getStubbedUser(10)); |
|
|
|
|
1610
|
|
|
|
1611
|
|
|
$this->repository->getContentService()->publishVersion($draftContent->versionInfo); |
1612
|
|
|
} |
1613
|
|
|
|
1614
|
|
|
/** |
1615
|
|
|
* Test for the createContentDraft() method. |
1616
|
|
|
* |
1617
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::createContentDraft |
1618
|
|
|
* |
1619
|
|
|
* @return array |
1620
|
|
|
*/ |
1621
|
|
View Code Duplication |
public function testCreateContentDraft() |
1622
|
|
|
{ |
1623
|
|
|
$time = time(); |
1624
|
|
|
|
1625
|
|
|
/* BEGIN: Use Case */ |
1626
|
|
|
$contentService = $this->repository->getContentService(); |
1627
|
|
|
|
1628
|
|
|
$contentInfo = $contentService->loadContentInfo(4); |
1629
|
|
|
|
1630
|
|
|
$draftContent = $contentService->createContentDraft($contentInfo); |
1631
|
|
|
/* END: Use Case */ |
1632
|
|
|
|
1633
|
|
|
$this->assertInstanceOf( |
1634
|
|
|
'eZ\\Publish\\API\\Repository\\Values\\Content\\Content', |
1635
|
|
|
$draftContent |
1636
|
|
|
); |
1637
|
|
|
|
1638
|
|
|
return array( |
1639
|
|
|
'draftContent' => $draftContent, |
1640
|
|
|
'time' => $time, |
1641
|
|
|
); |
1642
|
|
|
} |
1643
|
|
|
|
1644
|
|
|
/** |
1645
|
|
|
* @param array $data |
1646
|
|
|
*/ |
1647
|
|
|
protected function assertDraftContentValues(array $data) |
1648
|
|
|
{ |
1649
|
|
|
/** @var $draftContent \eZ\Publish\API\Repository\Values\Content\Content */ |
1650
|
|
|
$draftContent = $data['draftContent']; |
1651
|
|
|
$time = $data['time']; |
1652
|
|
|
|
1653
|
|
|
$this->assertContentValues($data['draftContent'], null, true); |
1654
|
|
|
$this->assertGreaterThanOrEqual( |
1655
|
|
|
$this->getDateTime($time), |
1656
|
|
|
$draftContent->getVersionInfo()->creationDate |
1657
|
|
|
); |
1658
|
|
|
$this->assertGreaterThanOrEqual( |
1659
|
|
|
$this->getDateTime($time), |
1660
|
|
|
$draftContent->getVersionInfo()->modificationDate |
1661
|
|
|
); |
1662
|
|
|
} |
1663
|
|
|
|
1664
|
|
|
/** |
1665
|
|
|
* Test for the createContentDraft() method. |
1666
|
|
|
* |
1667
|
|
|
* @depends testCreateContentDraft |
1668
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::createContentDraft |
1669
|
|
|
* |
1670
|
|
|
* @param array $data |
1671
|
|
|
*/ |
1672
|
|
|
public function testCreateContentDraftValues(array $data) |
1673
|
|
|
{ |
1674
|
|
|
$this->assertDraftContentValues($data); |
1675
|
|
|
} |
1676
|
|
|
|
1677
|
|
|
/** |
1678
|
|
|
* Test for the createContentDraft() method. |
1679
|
|
|
* |
1680
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::createContentDraft |
1681
|
|
|
* |
1682
|
|
|
* @return array |
1683
|
|
|
*/ |
1684
|
|
View Code Duplication |
public function testCreateContentDraftWithSecondArgument() |
1685
|
|
|
{ |
1686
|
|
|
$time = time(); |
1687
|
|
|
|
1688
|
|
|
/* BEGIN: Use Case */ |
1689
|
|
|
$contentService = $this->repository->getContentService(); |
1690
|
|
|
$content = $contentService->loadContent(4); |
1691
|
|
|
|
1692
|
|
|
$draftContent = $contentService->createContentDraft( |
1693
|
|
|
$content->contentInfo, |
1694
|
|
|
$content->getVersionInfo() |
1695
|
|
|
); |
1696
|
|
|
/* END: Use Case */ |
1697
|
|
|
|
1698
|
|
|
$this->assertInstanceOf( |
1699
|
|
|
'eZ\\Publish\\API\\Repository\\Values\\Content\\Content', |
1700
|
|
|
$draftContent |
1701
|
|
|
); |
1702
|
|
|
|
1703
|
|
|
return array( |
1704
|
|
|
'draftContent' => $draftContent, |
1705
|
|
|
'time' => $time, |
1706
|
|
|
); |
1707
|
|
|
} |
1708
|
|
|
|
1709
|
|
|
/** |
1710
|
|
|
* Test for the createContentDraft() method. |
1711
|
|
|
* |
1712
|
|
|
* @depends testCreateContentDraftWithSecondArgument |
1713
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::createContentDraft |
1714
|
|
|
* |
1715
|
|
|
* @param array $data |
1716
|
|
|
*/ |
1717
|
|
|
public function testCreateContentDraftWithSecondArgumentValues(array $data) |
1718
|
|
|
{ |
1719
|
|
|
$this->assertDraftContentValues($data); |
1720
|
|
|
} |
1721
|
|
|
|
1722
|
|
|
/** |
1723
|
|
|
* Test for the createContentDraft() method. |
1724
|
|
|
* |
1725
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::createContentDraft |
1726
|
|
|
* |
1727
|
|
|
* @return array |
1728
|
|
|
*/ |
1729
|
|
|
public function testCreateContentDraftWithThirdArgument() |
1730
|
|
|
{ |
1731
|
|
|
$time = time(); |
1732
|
|
|
|
1733
|
|
|
/* BEGIN: Use Case */ |
1734
|
|
|
$contentService = $this->repository->getContentService(); |
1735
|
|
|
$content = $contentService->loadContent(4); |
1736
|
|
|
|
1737
|
|
|
$draftContent = $contentService->createContentDraft( |
1738
|
|
|
$content->contentInfo, |
1739
|
|
|
$content->getVersionInfo(), |
1740
|
|
|
$this->repository->getCurrentUser() |
|
|
|
|
1741
|
|
|
); |
1742
|
|
|
/* END: Use Case */ |
1743
|
|
|
|
1744
|
|
|
$this->assertInstanceOf( |
1745
|
|
|
'eZ\\Publish\\API\\Repository\\Values\\Content\\Content', |
1746
|
|
|
$draftContent |
1747
|
|
|
); |
1748
|
|
|
|
1749
|
|
|
return array( |
1750
|
|
|
'draftContent' => $draftContent, |
1751
|
|
|
'time' => $time, |
1752
|
|
|
); |
1753
|
|
|
} |
1754
|
|
|
|
1755
|
|
|
/** |
1756
|
|
|
* Test for the createContentDraft() method. |
1757
|
|
|
* |
1758
|
|
|
* @depends testCreateContentDraftWithThirdArgument |
1759
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::createContentDraft |
1760
|
|
|
* |
1761
|
|
|
* @param array $data |
1762
|
|
|
*/ |
1763
|
|
|
public function testCreateContentDraftWithThirdArgumentValues(array $data) |
1764
|
|
|
{ |
1765
|
|
|
$this->assertDraftContentValues($data); |
1766
|
|
|
} |
1767
|
|
|
|
1768
|
|
|
/** |
1769
|
|
|
* Test for the createContentDraft() method. |
1770
|
|
|
* |
1771
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::createContentDraft |
1772
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException |
1773
|
|
|
*/ |
1774
|
|
View Code Duplication |
public function testCreateContentDraftThrowsBadStateException() |
1775
|
|
|
{ |
1776
|
|
|
$contentService = $this->repository->getContentService(); |
1777
|
|
|
$contentInfo = $contentService->loadContentInfo(4); |
1778
|
|
|
$draftContent = $contentService->createContentDraft($contentInfo); |
1779
|
|
|
|
1780
|
|
|
// Throws an exception because version status is not |
1781
|
|
|
// VersionInfo::STATUS_PUBLISHED nor VersionInfo::STATUS_ARCHIVED |
1782
|
|
|
$draftContent = $contentService->createContentDraft( |
|
|
|
|
1783
|
|
|
$draftContent->contentInfo, |
1784
|
|
|
$draftContent->getVersionInfo() |
1785
|
|
|
); |
1786
|
|
|
} |
1787
|
|
|
|
1788
|
|
|
/** |
1789
|
|
|
* Test for the createContentDraft() method. |
1790
|
|
|
* |
1791
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::createContentDraft |
1792
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
1793
|
|
|
*/ |
1794
|
|
View Code Duplication |
public function testCreateContentDraftThrowsUnauthorizedException() |
1795
|
|
|
{ |
1796
|
|
|
$contentService = $this->repository->getContentService(); |
1797
|
|
|
|
1798
|
|
|
$contentInfo = $contentService->loadContentInfo(4); |
1799
|
|
|
|
1800
|
|
|
// Set anonymous as current user |
1801
|
|
|
$this->repository->setCurrentUser($this->getStubbedUser(10)); |
|
|
|
|
1802
|
|
|
|
1803
|
|
|
$contentService->createContentDraft($contentInfo); |
1804
|
|
|
} |
1805
|
|
|
|
1806
|
|
|
/** |
1807
|
|
|
* Test for the loadContentDrafts() method. |
1808
|
|
|
* |
1809
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadContentDrafts |
1810
|
|
|
*/ |
1811
|
|
|
public function testLoadContentDrafts() |
1812
|
|
|
{ |
1813
|
|
|
$contentService = $this->repository->getContentService(); |
1814
|
|
|
|
1815
|
|
|
// delete existing drafts before we begin |
1816
|
|
|
$draftedVersions = $contentService->loadContentDrafts(); |
1817
|
|
|
foreach ($draftedVersions as $draftedVersion) { |
1818
|
|
|
$contentService->deleteVersion($draftedVersion); |
1819
|
|
|
} |
1820
|
|
|
|
1821
|
|
|
/* BEGIN: Use Case */ |
1822
|
|
|
// Remote ids of the "Users" user group of a eZ Publish demo installation. |
1823
|
|
|
$usersUserGroupRemoteId = 'f5c88a2209584891056f987fd965b0ba'; |
1824
|
|
|
$membersUserGroupRemoteId = '5f7f0bdb3381d6a461d8c29ff53d908f'; |
1825
|
|
|
|
1826
|
|
|
// "Users" user group content object |
1827
|
|
|
$usersUserGroupContentInfo = $contentService->loadContentInfoByRemoteId($usersUserGroupRemoteId); |
1828
|
|
|
$membersUserGroupContentInfo = $contentService->loadContentInfoByRemoteId($membersUserGroupRemoteId); |
1829
|
|
|
|
1830
|
|
|
// Create some drafts |
1831
|
|
|
$contentService->createContentDraft($usersUserGroupContentInfo); |
1832
|
|
|
$contentService->createContentDraft($membersUserGroupContentInfo); |
1833
|
|
|
|
1834
|
|
|
// Now $contentDrafts should contain two drafted versions |
1835
|
|
|
$draftedVersions = $contentService->loadContentDrafts(); |
1836
|
|
|
/* END: Use Case */ |
1837
|
|
|
|
1838
|
|
|
$actual = array( |
1839
|
|
|
$draftedVersions[0]->status, |
1840
|
|
|
$draftedVersions[1]->status, |
1841
|
|
|
count($draftedVersions), |
1842
|
|
|
$draftedVersions[0]->getContentInfo()->remoteId, |
1843
|
|
|
$draftedVersions[1]->getContentInfo()->remoteId, |
1844
|
|
|
); |
1845
|
|
|
|
1846
|
|
|
$this->assertEquals( |
1847
|
|
|
array( |
1848
|
|
|
VersionInfo::STATUS_DRAFT, |
1849
|
|
|
VersionInfo::STATUS_DRAFT, |
1850
|
|
|
2, |
1851
|
|
|
$usersUserGroupRemoteId, |
1852
|
|
|
$membersUserGroupRemoteId, |
1853
|
|
|
), |
1854
|
|
|
$actual |
1855
|
|
|
); |
1856
|
|
|
} |
1857
|
|
|
|
1858
|
|
|
/** |
1859
|
|
|
* Test for the loadContentDrafts() method. |
1860
|
|
|
* |
1861
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadContentDrafts |
1862
|
|
|
*/ |
1863
|
|
|
public function testLoadContentDraftsWithFirstArgument() |
1864
|
|
|
{ |
1865
|
|
|
} |
1866
|
|
|
|
1867
|
|
|
/** |
1868
|
|
|
* Test for the loadContentDrafts() method. |
1869
|
|
|
* |
1870
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadContentDrafts |
1871
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
1872
|
|
|
*/ |
1873
|
|
|
public function testLoadContentDraftsThrowsUnauthorizedException() |
1874
|
|
|
{ |
1875
|
|
|
// Set anonymous as current user |
1876
|
|
|
$this->repository->setCurrentUser($this->getStubbedUser(10)); |
|
|
|
|
1877
|
|
|
|
1878
|
|
|
// Now $contentDrafts should contain two drafted versions |
1879
|
|
|
$this->repository->getContentService()->loadContentDrafts(); |
1880
|
|
|
} |
1881
|
|
|
|
1882
|
|
|
/** |
1883
|
|
|
* Test for the loadVersions() method. |
1884
|
|
|
* |
1885
|
|
|
* @depends testLoadContentInfo |
1886
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadVersions |
1887
|
|
|
* |
1888
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] |
1889
|
|
|
*/ |
1890
|
|
|
public function testLoadVersions() |
1891
|
|
|
{ |
1892
|
|
|
/* BEGIN: Use Case */ |
1893
|
|
|
$contentService = $this->repository->getContentService(); |
1894
|
|
|
|
1895
|
|
|
$contentInfo = $contentService->loadContentInfo(4); |
1896
|
|
|
$versions = $contentService->loadVersions($contentInfo); |
1897
|
|
|
/* END: Use Case */ |
1898
|
|
|
|
1899
|
|
|
return $versions; |
1900
|
|
|
} |
1901
|
|
|
|
1902
|
|
|
/** |
1903
|
|
|
* Test for the loadVersions() method. |
1904
|
|
|
* |
1905
|
|
|
* @depends testLoadVersions |
1906
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadVersions |
1907
|
|
|
* |
1908
|
|
|
* @param array $versions |
1909
|
|
|
*/ |
1910
|
|
|
public function testLoadVersionsValues(array $versions) |
1911
|
|
|
{ |
1912
|
|
|
$versionInfoValues = $this->getVersionInfoExpectedValues(); |
1913
|
|
|
|
1914
|
|
|
$this->assertPropertiesCorrect( |
1915
|
|
|
$versionInfoValues, |
1916
|
|
|
$versions[0] |
1917
|
|
|
); |
1918
|
|
|
} |
1919
|
|
|
|
1920
|
|
|
/** |
1921
|
|
|
* Test for the loadVersions() method. |
1922
|
|
|
* |
1923
|
|
|
* @depends testLoadContentInfo |
1924
|
|
|
* @depends testCreateContentDraft |
1925
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadVersions |
1926
|
|
|
* |
1927
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] |
1928
|
|
|
*/ |
1929
|
|
View Code Duplication |
public function testLoadVersionsMultiple() |
1930
|
|
|
{ |
1931
|
|
|
$time = time(); |
1932
|
|
|
|
1933
|
|
|
/* BEGIN: Use Case */ |
1934
|
|
|
$contentService = $this->repository->getContentService(); |
1935
|
|
|
|
1936
|
|
|
$contentInfo = $contentService->loadContentInfo(4); |
1937
|
|
|
// Create one additional version |
1938
|
|
|
$draftContent = $contentService->createContentDraft($contentInfo); |
|
|
|
|
1939
|
|
|
$versions = $contentService->loadVersions($contentInfo); |
1940
|
|
|
/* END: Use Case */ |
1941
|
|
|
|
1942
|
|
|
return array( |
1943
|
|
|
'versions' => $versions, |
1944
|
|
|
'time' => $time, |
1945
|
|
|
); |
1946
|
|
|
} |
1947
|
|
|
|
1948
|
|
|
/** |
1949
|
|
|
* Test for the loadVersions() method. |
1950
|
|
|
* |
1951
|
|
|
* @depends testLoadVersionsMultiple |
1952
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadVersions |
1953
|
|
|
* |
1954
|
|
|
* @param array $data |
1955
|
|
|
*/ |
1956
|
|
|
public function testLoadVersionsMultipleValues(array $data) |
1957
|
|
|
{ |
1958
|
|
|
$versions = $data['versions']; |
1959
|
|
|
$time = $data['time']; |
1960
|
|
|
|
1961
|
|
|
$versionInfoValues = $this->getVersionInfoExpectedValues(); |
1962
|
|
|
$this->assertPropertiesCorrect( |
1963
|
|
|
$versionInfoValues, |
1964
|
|
|
$versions[0] |
1965
|
|
|
); |
1966
|
|
|
|
1967
|
|
|
$versionInfoValues = $this->getVersionInfoExpectedValues(true); |
1968
|
|
|
$this->assertPropertiesCorrect( |
1969
|
|
|
$versionInfoValues, |
1970
|
|
|
$versions[1] |
1971
|
|
|
); |
1972
|
|
|
$this->assertGreaterThanOrEqual( |
1973
|
|
|
$this->getDateTime($time), |
1974
|
|
|
$versions[1]->creationDate |
1975
|
|
|
); |
1976
|
|
|
$this->assertGreaterThanOrEqual( |
1977
|
|
|
$this->getDateTime($time), |
1978
|
|
|
$versions[1]->modificationDate |
1979
|
|
|
); |
1980
|
|
|
} |
1981
|
|
|
|
1982
|
|
|
/** |
1983
|
|
|
* Test for the loadVersions() method. |
1984
|
|
|
* |
1985
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadVersions |
1986
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
1987
|
|
|
*/ |
1988
|
|
View Code Duplication |
public function testLoadVersionsThrowsUnauthorizedException() |
1989
|
|
|
{ |
1990
|
|
|
$contentService = $this->repository->getContentService(); |
1991
|
|
|
|
1992
|
|
|
$contentInfo = $contentService->loadContentInfo(4); |
1993
|
|
|
|
1994
|
|
|
// Set anonymous as current user |
1995
|
|
|
$this->repository->setCurrentUser($this->getStubbedUser(10)); |
|
|
|
|
1996
|
|
|
|
1997
|
|
|
$contentService->loadVersions($contentInfo); |
1998
|
|
|
} |
1999
|
|
|
|
2000
|
|
|
/** |
2001
|
|
|
* Test for the deleteVersion() method. |
2002
|
|
|
* |
2003
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::deleteVersion |
2004
|
|
|
*/ |
2005
|
|
|
public function testDeleteVersion() |
2006
|
|
|
{ |
2007
|
|
|
/* BEGIN: Use Case */ |
2008
|
|
|
$contentService = $this->repository->getContentService(); |
2009
|
|
|
|
2010
|
|
|
$contentInfo = $contentService->loadContentInfo(4); |
2011
|
|
|
|
2012
|
|
|
// Create a version to delete |
2013
|
|
|
$draftContent = $contentService->createContentDraft($contentInfo); |
2014
|
|
|
|
2015
|
|
|
$contentService->deleteVersion($draftContent->versionInfo); |
2016
|
|
|
/* END: Use Case */ |
2017
|
|
|
|
2018
|
|
|
try { |
2019
|
|
|
$contentService->loadVersionInfo( |
2020
|
|
|
$draftContent->contentInfo, |
2021
|
|
|
$draftContent->versionInfo->versionNo |
2022
|
|
|
); |
2023
|
|
|
|
2024
|
|
|
$this->fail('Version was not successfully deleted!'); |
2025
|
|
|
} catch (NotFoundException $e) { |
2026
|
|
|
// Do nothing |
2027
|
|
|
} |
2028
|
|
|
} |
2029
|
|
|
|
2030
|
|
|
/** |
2031
|
|
|
* Test for the deleteVersion() method. |
2032
|
|
|
* |
2033
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::deleteVersion |
2034
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException |
2035
|
|
|
*/ |
2036
|
|
|
public function testDeleteVersionThrowsBadStateException() |
2037
|
|
|
{ |
2038
|
|
|
/* BEGIN: Use Case */ |
2039
|
|
|
$contentService = $this->repository->getContentService(); |
2040
|
|
|
|
2041
|
|
|
$versionInfo = $contentService->loadVersionInfoById(4); |
2042
|
|
|
|
2043
|
|
|
// Throws an exception because version is published |
2044
|
|
|
$contentService->deleteVersion($versionInfo); |
2045
|
|
|
/* END: Use Case */ |
2046
|
|
|
} |
2047
|
|
|
|
2048
|
|
|
/** |
2049
|
|
|
* Test for the deleteVersion() method. |
2050
|
|
|
* |
2051
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::deleteVersion |
2052
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
2053
|
|
|
*/ |
2054
|
|
View Code Duplication |
public function testDeleteVersionThrowsUnauthorizedException() |
2055
|
|
|
{ |
2056
|
|
|
$contentService = $this->repository->getContentService(); |
2057
|
|
|
|
2058
|
|
|
$contentInfo = $contentService->loadContentInfo(4); |
2059
|
|
|
|
2060
|
|
|
// Create a version to delete |
2061
|
|
|
$draftContent = $contentService->createContentDraft($contentInfo); |
2062
|
|
|
|
2063
|
|
|
// Set anonymous as current user |
2064
|
|
|
$this->repository->setCurrentUser($this->getStubbedUser(10)); |
|
|
|
|
2065
|
|
|
|
2066
|
|
|
$contentService->deleteVersion($draftContent->versionInfo); |
2067
|
|
|
} |
2068
|
|
|
|
2069
|
|
|
/** |
2070
|
|
|
* Test for the copyContent() method. |
2071
|
|
|
* |
2072
|
|
|
* @dep_ends testCreate |
2073
|
|
|
* @dep_ends testLoadContentInfo |
2074
|
|
|
* @dep_ends testLoadVersionInfoById |
2075
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::copyContent |
2076
|
|
|
*/ |
2077
|
|
|
public function testCopyContentSingleVersion() |
2078
|
|
|
{ |
2079
|
|
|
$time = time(); |
2080
|
|
|
|
2081
|
|
|
/* BEGIN: Use Case */ |
2082
|
|
|
$contentService = $this->repository->getContentService(); |
2083
|
|
|
$locationService = $this->repository->getLocationService(); |
2084
|
|
|
|
2085
|
|
|
$contentInfo = $contentService->loadContentInfo(11); |
2086
|
|
|
$versionInfo = $contentService->loadVersionInfoById(11, 1); |
2087
|
|
|
$destinationLocationCreateStruct = $locationService->newLocationCreateStruct(5); |
2088
|
|
|
|
2089
|
|
|
$copiedContent = $contentService->copyContent( |
2090
|
|
|
$contentInfo, |
2091
|
|
|
$destinationLocationCreateStruct, |
2092
|
|
|
$versionInfo |
2093
|
|
|
); |
2094
|
|
|
/* END: Use Case */ |
2095
|
|
|
|
2096
|
|
|
$this->assertInstanceOf( |
2097
|
|
|
'eZ\\Publish\\Core\\Repository\\Values\\Content\\Content', |
2098
|
|
|
$copiedContent |
2099
|
|
|
); |
2100
|
|
|
|
2101
|
|
|
$this->assertEquals(1, $copiedContent->contentInfo->currentVersionNo); |
2102
|
|
|
$this->assertGreaterThanOrEqual($time, $copiedContent->contentInfo->modificationDate->getTimestamp()); |
2103
|
|
|
$this->assertGreaterThanOrEqual($time, $copiedContent->contentInfo->publishedDate->getTimestamp()); |
2104
|
|
|
$this->assertCopyContentValues( |
2105
|
|
|
$contentService->loadContent(11, null, 1), |
2106
|
|
|
$copiedContent |
2107
|
|
|
); |
2108
|
|
|
} |
2109
|
|
|
|
2110
|
|
|
/** |
2111
|
|
|
* Test for the copyContent() method. |
2112
|
|
|
* |
2113
|
|
|
* @dep_ends testLoadVersions |
2114
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::copyContent |
2115
|
|
|
*/ |
2116
|
|
|
public function testCopyContentAllVersions() |
2117
|
|
|
{ |
2118
|
|
|
$time = time(); |
2119
|
|
|
|
2120
|
|
|
/* BEGIN: Use Case */ |
2121
|
|
|
$contentService = $this->repository->getContentService(); |
2122
|
|
|
$locationService = $this->repository->getLocationService(); |
2123
|
|
|
|
2124
|
|
|
$contentInfo = $contentService->loadContentInfo(11); |
2125
|
|
|
$destinationLocationCreateStruct = $locationService->newLocationCreateStruct(5); |
2126
|
|
|
|
2127
|
|
|
$copiedContent = $contentService->copyContent( |
2128
|
|
|
$contentInfo, |
2129
|
|
|
$destinationLocationCreateStruct |
2130
|
|
|
); |
2131
|
|
|
/* END: Use Case */ |
2132
|
|
|
|
2133
|
|
|
$this->assertInstanceOf( |
2134
|
|
|
'eZ\\Publish\\Core\\Repository\\Values\\Content\\Content', |
2135
|
|
|
$copiedContent |
2136
|
|
|
); |
2137
|
|
|
|
2138
|
|
|
$this->assertGreaterThanOrEqual($time, $copiedContent->contentInfo->modificationDate->getTimestamp()); |
2139
|
|
|
$this->assertGreaterThanOrEqual($time, $copiedContent->contentInfo->publishedDate->getTimestamp()); |
2140
|
|
|
|
2141
|
|
|
$originalVersionInfos = $contentService->loadVersions($contentInfo); |
2142
|
|
|
$copiedVersionInfos = $contentService->loadVersions($copiedContent->contentInfo); |
2143
|
|
|
$sorter = |
2144
|
|
|
function (VersionInfo $a, VersionInfo $b) { |
2145
|
|
|
return strcmp($a->versionNo, $b->versionNo); |
2146
|
|
|
}; |
2147
|
|
|
usort($originalVersionInfos, $sorter); |
2148
|
|
|
usort($copiedVersionInfos, $sorter); |
2149
|
|
|
$this->assertCount( |
2150
|
|
|
count($originalVersionInfos), |
2151
|
|
|
$copiedVersionInfos, |
2152
|
|
|
'Count of versions copied does not match the count of original versions' |
2153
|
|
|
); |
2154
|
|
|
$this->assertEquals($contentInfo->currentVersionNo, $copiedContent->contentInfo->currentVersionNo); |
2155
|
|
|
foreach ($originalVersionInfos as $index => $versionInfo) { |
2156
|
|
|
$this->assertEquals($versionInfo->versionNo, $copiedVersionInfos[$index]->versionNo); |
2157
|
|
|
$this->assertCopyContentValues( |
2158
|
|
|
$contentService->loadContent( |
2159
|
|
|
$contentInfo->id, |
2160
|
|
|
null, |
2161
|
|
|
$versionInfo->versionNo |
2162
|
|
|
), |
2163
|
|
|
$contentService->loadContent( |
2164
|
|
|
$copiedContent->id, |
2165
|
|
|
null, |
2166
|
|
|
$copiedVersionInfos[$index]->versionNo |
2167
|
|
|
) |
2168
|
|
|
); |
2169
|
|
|
} |
2170
|
|
|
} |
2171
|
|
|
|
2172
|
|
|
/** |
2173
|
|
|
* Asserts that $copiedContent is valid copy of $originalContent. |
2174
|
|
|
* |
2175
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Content $originalContent |
2176
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Content $copiedContent |
2177
|
|
|
*/ |
2178
|
|
|
protected function assertCopyContentValues(APIContent $originalContent, APIContent $copiedContent) |
2179
|
|
|
{ |
2180
|
|
|
$this->assertNotEquals( |
2181
|
|
|
$originalContent->id, |
2182
|
|
|
$copiedContent->id, |
2183
|
|
|
'Id of content copy is equal to id od original content' |
2184
|
|
|
); |
2185
|
|
|
|
2186
|
|
|
$this->assertSameClassPropertiesCorrect( |
2187
|
|
|
array( |
2188
|
|
|
//"name", |
2189
|
|
|
'contentTypeId', |
2190
|
|
|
'sectionId', |
2191
|
|
|
//"currentVersionNo", |
2192
|
|
|
'published', |
2193
|
|
|
'ownerId', |
2194
|
|
|
'alwaysAvailable', |
2195
|
|
|
'mainLanguageCode', |
2196
|
|
|
//"mainLocationId" |
2197
|
|
|
), |
2198
|
|
|
$originalContent->contentInfo, |
2199
|
|
|
$copiedContent->contentInfo |
2200
|
|
|
); |
2201
|
|
|
$this->assertNotEquals($originalContent->contentInfo->id, $copiedContent->contentInfo->id); |
2202
|
|
|
$this->assertNotEquals($originalContent->contentInfo->remoteId, $copiedContent->contentInfo->remoteId); |
2203
|
|
|
|
2204
|
|
|
$this->assertSameClassPropertiesCorrect( |
2205
|
|
|
array( |
2206
|
|
|
'versionNo', |
2207
|
|
|
//"contentId", |
2208
|
|
|
'names', |
2209
|
|
|
//"creationDate", |
2210
|
|
|
//"modificationDate", |
2211
|
|
|
'creatorId', |
2212
|
|
|
//"status", |
2213
|
|
|
'initialLanguageCode', |
2214
|
|
|
'languageCodes', |
2215
|
|
|
), |
2216
|
|
|
$originalContent->versionInfo, |
2217
|
|
|
$copiedContent->versionInfo |
2218
|
|
|
); |
2219
|
|
|
$this->assertNotEquals($originalContent->versionInfo->id, $copiedContent->versionInfo->id); |
2220
|
|
|
|
2221
|
|
|
$originalFields = $originalContent->getFields(); |
2222
|
|
|
$copiedFields = $copiedContent->getFields(); |
2223
|
|
|
$this->assertCount( |
2224
|
|
|
count($originalFields), |
2225
|
|
|
$copiedFields, |
2226
|
|
|
'Count of fields copied does not match the count of original fields' |
2227
|
|
|
); |
2228
|
|
|
foreach ($originalFields as $fieldIndex => $originalField) { |
2229
|
|
|
$this->assertSameClassPropertiesCorrect( |
2230
|
|
|
array( |
2231
|
|
|
'fieldDefIdentifier', |
2232
|
|
|
'value', |
2233
|
|
|
'languageCode', |
2234
|
|
|
), |
2235
|
|
|
$originalField, |
2236
|
|
|
$copiedFields[$fieldIndex] |
2237
|
|
|
); |
2238
|
|
|
$this->assertNotEquals( |
2239
|
|
|
$originalField->id, |
2240
|
|
|
$copiedFields[$fieldIndex]->id |
2241
|
|
|
); |
2242
|
|
|
} |
2243
|
|
|
} |
2244
|
|
|
|
2245
|
|
|
/** |
2246
|
|
|
* Test for the copyContent() method. |
2247
|
|
|
* |
2248
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::copyContent |
2249
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
2250
|
|
|
*/ |
2251
|
|
View Code Duplication |
public function testCopyContentThrowsUnauthorizedException() |
2252
|
|
|
{ |
2253
|
|
|
$contentService = $this->repository->getContentService(); |
2254
|
|
|
$locationService = $this->repository->getLocationService(); |
2255
|
|
|
|
2256
|
|
|
$contentInfo = $contentService->loadContentInfo(11); |
2257
|
|
|
$destinationLocationCreateStruct = $locationService->newLocationCreateStruct(5); |
2258
|
|
|
|
2259
|
|
|
// Set anonymous as current user |
2260
|
|
|
$this->repository->setCurrentUser($this->getStubbedUser(10)); |
|
|
|
|
2261
|
|
|
|
2262
|
|
|
$contentService->copyContent($contentInfo, $destinationLocationCreateStruct); |
2263
|
|
|
} |
2264
|
|
|
|
2265
|
|
|
/** |
2266
|
|
|
* Test for the newTranslationInfo() method. |
2267
|
|
|
* |
2268
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::newTranslationInfo |
2269
|
|
|
*/ |
2270
|
|
View Code Duplication |
public function testNewTranslationInfo() |
2271
|
|
|
{ |
2272
|
|
|
/* BEGIN: Use Case */ |
2273
|
|
|
$contentService = $this->repository->getContentService(); |
2274
|
|
|
|
2275
|
|
|
$translationInfo = $contentService->newTranslationInfo(); |
2276
|
|
|
/* END: Use Case */ |
2277
|
|
|
|
2278
|
|
|
$this->assertInstanceOf( |
2279
|
|
|
'eZ\\Publish\\API\\Repository\\Values\\Content\\TranslationInfo', |
2280
|
|
|
$translationInfo |
2281
|
|
|
); |
2282
|
|
|
|
2283
|
|
|
foreach ($translationInfo as $propertyName => $propertyValue) { |
|
|
|
|
2284
|
|
|
$this->assertNull($propertyValue, "Property '{$propertyName}' initial value should be null'"); |
2285
|
|
|
} |
2286
|
|
|
} |
2287
|
|
|
|
2288
|
|
|
/** |
2289
|
|
|
* Test for the newTranslationValues() method. |
2290
|
|
|
* |
2291
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::newTranslationValues |
2292
|
|
|
*/ |
2293
|
|
View Code Duplication |
public function testNewTranslationValues() |
2294
|
|
|
{ |
2295
|
|
|
/* BEGIN: Use Case */ |
2296
|
|
|
$contentService = $this->repository->getContentService(); |
2297
|
|
|
|
2298
|
|
|
$translationValues = $contentService->newTranslationValues(); |
2299
|
|
|
/* END: Use Case */ |
2300
|
|
|
|
2301
|
|
|
$this->assertInstanceOf( |
2302
|
|
|
'eZ\\Publish\\API\\Repository\\Values\\Content\\TranslationValues', |
2303
|
|
|
$translationValues |
2304
|
|
|
); |
2305
|
|
|
|
2306
|
|
|
foreach ($translationValues as $propertyName => $propertyValue) { |
|
|
|
|
2307
|
|
|
$this->assertNull($propertyValue, "Property '{$propertyName}' initial value should be null'"); |
2308
|
|
|
} |
2309
|
|
|
} |
2310
|
|
|
|
2311
|
|
|
/** |
2312
|
|
|
* Test for the loadRelations() method. |
2313
|
|
|
* |
2314
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadRelations |
2315
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::addRelation |
2316
|
|
|
*/ |
2317
|
|
View Code Duplication |
public function testLoadRelations() |
2318
|
|
|
{ |
2319
|
|
|
list($contentDraft, $contentType) = $this->createTestContent(); |
|
|
|
|
2320
|
|
|
$contentService = $this->repository->getContentService(); |
2321
|
|
|
|
2322
|
|
|
$mediaContentInfo = $contentService->loadContentInfoByRemoteId('a6e35cbcb7cd6ae4b691f3eee30cd262'); |
2323
|
|
|
|
2324
|
|
|
$contentService->addRelation( |
2325
|
|
|
$contentDraft->getVersionInfo(), |
2326
|
|
|
$mediaContentInfo |
2327
|
|
|
); |
2328
|
|
|
|
2329
|
|
|
$relations = $contentService->loadRelations($contentDraft->versionInfo); |
2330
|
|
|
|
2331
|
|
|
$this->assertRelations($relations, $contentDraft->contentInfo, $mediaContentInfo); |
2332
|
|
|
} |
2333
|
|
|
|
2334
|
|
|
protected function assertRelations($relations, $sourceContentInfo, $destinationContentInfo) |
2335
|
|
|
{ |
2336
|
|
|
self::assertInternalType('array', $relations); |
2337
|
|
|
self::assertCount(1, $relations); |
2338
|
|
|
self::assertInstanceOf('eZ\\Publish\\API\\Repository\\Values\\Content\\Relation', $relations[0]); |
2339
|
|
|
self::assertNotNull($relations[0]->id); |
2340
|
|
|
self::assertEquals(Relation::COMMON, $relations[0]->type); |
2341
|
|
|
self::assertNull($relations[0]->sourceFieldDefinitionIdentifier); |
2342
|
|
|
self::assertEquals($sourceContentInfo, $relations[0]->sourceContentInfo); |
2343
|
|
|
self::assertEquals($destinationContentInfo, $relations[0]->destinationContentInfo); |
2344
|
|
|
} |
2345
|
|
|
|
2346
|
|
|
/** |
2347
|
|
|
* Test for the loadRelations() method. |
2348
|
|
|
* |
2349
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadRelations |
2350
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
2351
|
|
|
*/ |
2352
|
|
View Code Duplication |
public function testLoadRelationsThrowsUnauthorizedException() |
2353
|
|
|
{ |
2354
|
|
|
list($contentDraft, $contentType) = $this->createTestContent(); |
|
|
|
|
2355
|
|
|
$contentService = $this->repository->getContentService(); |
2356
|
|
|
|
2357
|
|
|
$mediaContentInfo = $contentService->loadContentInfoByRemoteId('a6e35cbcb7cd6ae4b691f3eee30cd262'); |
2358
|
|
|
|
2359
|
|
|
$contentService->addRelation( |
2360
|
|
|
$contentDraft->getVersionInfo(), |
2361
|
|
|
$mediaContentInfo |
2362
|
|
|
); |
2363
|
|
|
|
2364
|
|
|
// Set anonymous as current user |
2365
|
|
|
$this->repository->setCurrentUser($this->getStubbedUser(10)); |
|
|
|
|
2366
|
|
|
|
2367
|
|
|
$contentService->loadRelations($contentDraft->versionInfo); |
2368
|
|
|
} |
2369
|
|
|
|
2370
|
|
|
/** |
2371
|
|
|
* Test for the loadReverseRelations() method. |
2372
|
|
|
* |
2373
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadReverseRelations |
2374
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
2375
|
|
|
*/ |
2376
|
|
|
public function testLoadReverseRelationsThrowsUnauthorizedException() |
2377
|
|
|
{ |
2378
|
|
|
list($contentDraft, $contentType) = $this->createTestContent(); |
|
|
|
|
2379
|
|
|
$contentService = $this->repository->getContentService(); |
2380
|
|
|
|
2381
|
|
|
$mediaContentInfo = $contentService->loadContentInfoByRemoteId('a6e35cbcb7cd6ae4b691f3eee30cd262'); |
2382
|
|
|
|
2383
|
|
|
$contentService->addRelation( |
2384
|
|
|
$contentDraft->getVersionInfo(), |
2385
|
|
|
$mediaContentInfo |
2386
|
|
|
); |
2387
|
|
|
|
2388
|
|
|
// Set anonymous as current user |
2389
|
|
|
$this->repository->setCurrentUser($this->getStubbedUser(10)); |
|
|
|
|
2390
|
|
|
|
2391
|
|
|
$contentService->loadReverseRelations($mediaContentInfo); |
2392
|
|
|
} |
2393
|
|
|
|
2394
|
|
|
/** |
2395
|
|
|
* Test for the addRelation() method. |
2396
|
|
|
* |
2397
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::addRelation |
2398
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
2399
|
|
|
*/ |
2400
|
|
|
public function testAddRelationThrowsUnauthorizedException() |
2401
|
|
|
{ |
2402
|
|
|
list($contentDraft, $contentType) = $this->createTestContent(); |
|
|
|
|
2403
|
|
|
$contentService = $this->repository->getContentService(); |
2404
|
|
|
|
2405
|
|
|
$mediaContentInfo = $contentService->loadContentInfoByRemoteId('a6e35cbcb7cd6ae4b691f3eee30cd262'); |
2406
|
|
|
|
2407
|
|
|
// Set anonymous as current user |
2408
|
|
|
$this->repository->setCurrentUser($this->getStubbedUser(10)); |
|
|
|
|
2409
|
|
|
|
2410
|
|
|
$contentService->addRelation( |
2411
|
|
|
$contentDraft->getVersionInfo(), |
2412
|
|
|
$mediaContentInfo |
2413
|
|
|
); |
2414
|
|
|
} |
2415
|
|
|
|
2416
|
|
|
/** |
2417
|
|
|
* Test for the addRelation() method. |
2418
|
|
|
* |
2419
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::addRelation |
2420
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException |
2421
|
|
|
*/ |
2422
|
|
View Code Duplication |
public function testAddRelationThrowsBadStateException() |
2423
|
|
|
{ |
2424
|
|
|
$contentService = $this->repository->getContentService(); |
2425
|
|
|
list($contentDraft, $contentType) = $this->createTestContent(); |
|
|
|
|
2426
|
|
|
$publishedContent = $contentService->publishVersion($contentDraft->versionInfo); |
2427
|
|
|
|
2428
|
|
|
$mediaContentInfo = $contentService->loadContentInfoByRemoteId('a6e35cbcb7cd6ae4b691f3eee30cd262'); |
2429
|
|
|
|
2430
|
|
|
$contentService->addRelation( |
2431
|
|
|
$publishedContent->getVersionInfo(), |
2432
|
|
|
$mediaContentInfo |
2433
|
|
|
); |
2434
|
|
|
} |
2435
|
|
|
|
2436
|
|
|
/** |
2437
|
|
|
* Test for the deleteRelation() method. |
2438
|
|
|
* |
2439
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::deleteRelation |
2440
|
|
|
*/ |
2441
|
|
View Code Duplication |
public function testDeleteRelation() |
2442
|
|
|
{ |
2443
|
|
|
list($contentDraft, $contentType) = $this->createTestContent(); |
|
|
|
|
2444
|
|
|
$contentService = $this->repository->getContentService(); |
2445
|
|
|
|
2446
|
|
|
$mediaContentInfo = $contentService->loadContentInfoByRemoteId('a6e35cbcb7cd6ae4b691f3eee30cd262'); |
2447
|
|
|
|
2448
|
|
|
$contentService->addRelation( |
2449
|
|
|
$contentDraft->getVersionInfo(), |
2450
|
|
|
$mediaContentInfo |
2451
|
|
|
); |
2452
|
|
|
|
2453
|
|
|
$contentService->deleteRelation( |
2454
|
|
|
$contentDraft->getVersionInfo(), |
2455
|
|
|
$mediaContentInfo |
2456
|
|
|
); |
2457
|
|
|
|
2458
|
|
|
$relations = $contentService->loadRelations($contentDraft->versionInfo); |
2459
|
|
|
|
2460
|
|
|
self::assertCount(0, $relations); |
2461
|
|
|
} |
2462
|
|
|
|
2463
|
|
|
/** |
2464
|
|
|
* Test for the deleteRelation() method. |
2465
|
|
|
* |
2466
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::deleteRelation |
2467
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
2468
|
|
|
*/ |
2469
|
|
View Code Duplication |
public function testDeleteRelationThrowsUnauthorizedException() |
2470
|
|
|
{ |
2471
|
|
|
list($contentDraft, $contentType) = $this->createTestContent(); |
|
|
|
|
2472
|
|
|
$contentService = $this->repository->getContentService(); |
2473
|
|
|
|
2474
|
|
|
$mediaContentInfo = $contentService->loadContentInfoByRemoteId('a6e35cbcb7cd6ae4b691f3eee30cd262'); |
2475
|
|
|
|
2476
|
|
|
$contentService->addRelation( |
2477
|
|
|
$contentDraft->getVersionInfo(), |
2478
|
|
|
$mediaContentInfo |
2479
|
|
|
); |
2480
|
|
|
|
2481
|
|
|
// Set anonymous as current user |
2482
|
|
|
$this->repository->setCurrentUser($this->getStubbedUser(10)); |
|
|
|
|
2483
|
|
|
|
2484
|
|
|
$contentService->deleteRelation( |
2485
|
|
|
$contentDraft->getVersionInfo(), |
2486
|
|
|
$mediaContentInfo |
2487
|
|
|
); |
2488
|
|
|
} |
2489
|
|
|
|
2490
|
|
|
/** |
2491
|
|
|
* Test for the deleteRelation() method. |
2492
|
|
|
* |
2493
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::deleteRelation |
2494
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException |
2495
|
|
|
*/ |
2496
|
|
View Code Duplication |
public function testDeleteRelationThrowsBadStateException() |
2497
|
|
|
{ |
2498
|
|
|
$contentService = $this->repository->getContentService(); |
2499
|
|
|
list($contentDraft, $contentType) = $this->createTestContent(); |
|
|
|
|
2500
|
|
|
|
2501
|
|
|
$mediaContentInfo = $contentService->loadContentInfoByRemoteId('a6e35cbcb7cd6ae4b691f3eee30cd262'); |
2502
|
|
|
|
2503
|
|
|
$contentService->addRelation( |
2504
|
|
|
$contentDraft->getVersionInfo(), |
2505
|
|
|
$mediaContentInfo |
2506
|
|
|
); |
2507
|
|
|
|
2508
|
|
|
$publishedContent = $contentService->publishVersion($contentDraft->versionInfo); |
2509
|
|
|
|
2510
|
|
|
$contentService->deleteRelation( |
2511
|
|
|
$publishedContent->getVersionInfo(), |
2512
|
|
|
$mediaContentInfo |
2513
|
|
|
); |
2514
|
|
|
} |
2515
|
|
|
|
2516
|
|
|
/** |
2517
|
|
|
* Test for the deleteRelation() method. |
2518
|
|
|
* |
2519
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::deleteRelation |
2520
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
2521
|
|
|
*/ |
2522
|
|
|
public function testDeleteRelationThrowsInvalidArgumentException() |
2523
|
|
|
{ |
2524
|
|
|
list($contentDraft, $contentType) = $this->createTestContent(); |
|
|
|
|
2525
|
|
|
$contentService = $this->repository->getContentService(); |
2526
|
|
|
|
2527
|
|
|
$mediaContentInfo = $contentService->loadContentInfoByRemoteId('a6e35cbcb7cd6ae4b691f3eee30cd262'); |
2528
|
|
|
|
2529
|
|
|
$contentService->deleteRelation( |
2530
|
|
|
$contentDraft->getVersionInfo(), |
2531
|
|
|
$mediaContentInfo |
2532
|
|
|
); |
2533
|
|
|
} |
2534
|
|
|
|
2535
|
|
|
/** |
2536
|
|
|
* Creates and returns content draft used in testing. |
2537
|
|
|
* |
2538
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Content |
2539
|
|
|
*/ |
2540
|
|
|
protected function createTestContent() |
2541
|
|
|
{ |
2542
|
|
|
$contentService = $this->repository->getContentService(); |
2543
|
|
|
$testContentType = $this->createTestContentType(); |
2544
|
|
|
|
2545
|
|
|
$contentCreate = $contentService->newContentCreateStruct($testContentType, 'eng-GB'); |
2546
|
|
|
$contentCreate->setField('test_required_empty', 'val-11'); |
2547
|
|
|
$contentCreate->setField('test_required_not_empty', 'val-12'); |
2548
|
|
|
$contentCreate->setField('test_translatable', 'val-13'); |
2549
|
|
|
$contentCreate->setField('test_untranslatable', 'val-14'); |
2550
|
|
|
$contentCreate->setField('test_translatable', 'val-23', 'eng-US'); |
2551
|
|
|
$contentCreate->sectionId = 1; |
2552
|
|
|
$contentCreate->ownerId = 14; |
2553
|
|
|
$contentCreate->remoteId = 'abcdef0123456789abcdef0123456789'; |
2554
|
|
|
$contentCreate->alwaysAvailable = true; |
2555
|
|
|
|
2556
|
|
|
$locationCreates = array( |
2557
|
|
|
new LocationCreateStruct( |
2558
|
|
|
array( |
2559
|
|
|
//priority = 0 |
2560
|
|
|
//hidden = false |
2561
|
|
|
'remoteId' => 'db787a9143f57828dd4331573466a013', |
2562
|
|
|
//sortField = Location::SORT_FIELD_NAME |
2563
|
|
|
//sortOrder = Location::SORT_ORDER_ASC |
2564
|
|
|
'parentLocationId' => 2, |
2565
|
|
|
) |
2566
|
|
|
), |
2567
|
|
|
new LocationCreateStruct( |
2568
|
|
|
array( |
2569
|
|
|
//priority = 0 |
2570
|
|
|
//hidden = false |
2571
|
|
|
'remoteId' => 'a3dd7c1c9e04c89e446a70f647286e6b', |
2572
|
|
|
//sortField = Location::SORT_FIELD_NAME |
2573
|
|
|
//sortOrder = Location::SORT_ORDER_ASC |
2574
|
|
|
'parentLocationId' => 5, |
2575
|
|
|
) |
2576
|
|
|
), |
2577
|
|
|
); |
2578
|
|
|
|
2579
|
|
|
return array($contentService->createContent($contentCreate, $locationCreates), $testContentType); |
2580
|
|
|
} |
2581
|
|
|
|
2582
|
|
|
/** |
2583
|
|
|
* Returns ContentType used in testing. |
2584
|
|
|
* |
2585
|
|
|
* @return \eZ\Publish\API\Repository\Values\ContentType\ContentType |
2586
|
|
|
*/ |
2587
|
|
|
protected function createTestContentType() |
2588
|
|
|
{ |
2589
|
|
|
$contentTypeService = $this->repository->getContentTypeService(); |
2590
|
|
|
$typeCreateStruct = $contentTypeService->newContentTypeCreateStruct( |
2591
|
|
|
'test-type' |
2592
|
|
|
); |
2593
|
|
|
$typeCreateStruct->names = array('eng-GB' => 'Test type name'); |
2594
|
|
|
$typeCreateStruct->descriptions = array('eng-GB' => 'Test type description'); |
2595
|
|
|
$typeCreateStruct->remoteId = 'test-type-remoteid'; |
2596
|
|
|
$typeCreateStruct->creatorId = $this->repository->getCurrentUserReference()->getUserId(); |
|
|
|
|
2597
|
|
|
$typeCreateStruct->creationDate = $this->getDateTime(0); |
2598
|
|
|
$typeCreateStruct->mainLanguageCode = 'eng-GB'; |
2599
|
|
|
$typeCreateStruct->nameSchema = '<test_required_empty>'; |
2600
|
|
|
$typeCreateStruct->urlAliasSchema = '<test_required_empty>'; |
2601
|
|
|
|
2602
|
|
|
$fieldCreate = $contentTypeService->newFieldDefinitionCreateStruct('test_required_empty', 'ezstring'); |
2603
|
|
|
$fieldCreate->names = array('eng-GB' => 'Test required empty'); |
2604
|
|
|
$fieldCreate->descriptions = array('eng-GB' => 'Required field with empty default value'); |
2605
|
|
|
$fieldCreate->fieldGroup = 'test-field-group'; |
2606
|
|
|
$fieldCreate->position = 1; |
2607
|
|
|
$fieldCreate->isTranslatable = false; |
2608
|
|
|
$fieldCreate->isRequired = true; |
2609
|
|
|
$fieldCreate->isInfoCollector = false; |
2610
|
|
|
$fieldCreate->isSearchable = true; |
2611
|
|
|
$fieldCreate->defaultValue = ''; |
2612
|
|
|
//$validator = new StringLengthValidator(); |
2613
|
|
|
//$validator->maxStringLength = 64; |
2614
|
|
|
//$fieldCreate->validatorConfiguration = array( $validator ); |
2615
|
|
|
$fieldCreate->validatorConfiguration = array( |
2616
|
|
|
'StringLengthValidator' => array( |
2617
|
|
|
'maxStringLength' => 64, |
2618
|
|
|
), |
2619
|
|
|
); |
2620
|
|
|
//$fieldCreate->fieldSettings |
2621
|
|
|
$typeCreateStruct->addFieldDefinition($fieldCreate); |
2622
|
|
|
|
2623
|
|
|
$fieldCreate = $contentTypeService->newFieldDefinitionCreateStruct('test_required_not_empty', 'ezstring'); |
2624
|
|
|
$fieldCreate->names = array('eng-GB' => 'Test required not empty'); |
2625
|
|
|
$fieldCreate->descriptions = array('eng-GB' => 'Required field with default value not empty'); |
2626
|
|
|
$fieldCreate->fieldGroup = 'test-field-group'; |
2627
|
|
|
$fieldCreate->position = 2; |
2628
|
|
|
$fieldCreate->isTranslatable = false; |
2629
|
|
|
$fieldCreate->isRequired = true; |
2630
|
|
|
$fieldCreate->isInfoCollector = false; |
2631
|
|
|
$fieldCreate->isSearchable = true; |
2632
|
|
|
$fieldCreate->defaultValue = 'dummy default data'; |
2633
|
|
|
//$fieldCreate->validators |
2634
|
|
|
//$fieldCreate->fieldSettings |
2635
|
|
|
$typeCreateStruct->addFieldDefinition($fieldCreate); |
2636
|
|
|
|
2637
|
|
|
$fieldCreate = $contentTypeService->newFieldDefinitionCreateStruct('test_translatable', 'ezstring'); |
2638
|
|
|
$fieldCreate->names = array('eng-GB' => 'Test translatable'); |
2639
|
|
|
$fieldCreate->descriptions = array('eng-GB' => 'Translatable field'); |
2640
|
|
|
$fieldCreate->fieldGroup = 'test-field-group'; |
2641
|
|
|
$fieldCreate->position = 3; |
2642
|
|
|
$fieldCreate->isTranslatable = true; |
2643
|
|
|
$fieldCreate->isRequired = false; |
2644
|
|
|
$fieldCreate->isInfoCollector = false; |
2645
|
|
|
$fieldCreate->isSearchable = true; |
2646
|
|
|
$fieldCreate->defaultValue = ''; |
2647
|
|
|
//$fieldCreate->validators |
2648
|
|
|
//$fieldCreate->fieldSettings |
2649
|
|
|
$typeCreateStruct->addFieldDefinition($fieldCreate); |
2650
|
|
|
|
2651
|
|
|
$fieldCreate = $contentTypeService->newFieldDefinitionCreateStruct('test_untranslatable', 'ezstring'); |
2652
|
|
|
$fieldCreate->names = array('eng-GB' => 'Test not translatable'); |
2653
|
|
|
$fieldCreate->descriptions = array('eng-GB' => 'Untranslatable field'); |
2654
|
|
|
$fieldCreate->fieldGroup = 'test-field-group'; |
2655
|
|
|
$fieldCreate->position = 4; |
2656
|
|
|
$fieldCreate->isTranslatable = false; |
2657
|
|
|
$fieldCreate->isRequired = false; |
2658
|
|
|
$fieldCreate->isInfoCollector = false; |
2659
|
|
|
$fieldCreate->isSearchable = true; |
2660
|
|
|
$fieldCreate->defaultValue = ''; |
2661
|
|
|
//$fieldCreate->validators |
2662
|
|
|
//$fieldCreate->fieldSettings |
2663
|
|
|
$typeCreateStruct->addFieldDefinition($fieldCreate); |
2664
|
|
|
|
2665
|
|
|
$contentTypeDraft = $contentTypeService->createContentType( |
2666
|
|
|
$typeCreateStruct, |
2667
|
|
|
array($contentTypeService->loadContentTypeGroup(1)) |
2668
|
|
|
); |
2669
|
|
|
$contentTypeId = $contentTypeDraft->id; |
|
|
|
|
2670
|
|
|
|
2671
|
|
|
$contentTypeService->publishContentTypeDraft($contentTypeDraft); |
2672
|
|
|
|
2673
|
|
|
return $contentTypeService->loadContentType($contentTypeId); |
2674
|
|
|
} |
2675
|
|
|
} |
2676
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.