1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing the BaseContentServiceTest 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
|
|
|
namespace eZ\Publish\API\Repository\Tests; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\API\Repository\Values\Content\Location; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Base class for content specific tests. |
15
|
|
|
*/ |
16
|
|
|
abstract class BaseContentServiceTest extends BaseTest |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Creates a fresh clean content draft. |
20
|
|
|
* |
21
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Content |
22
|
|
|
*/ |
23
|
|
View Code Duplication |
protected function createContentVersion1EmptyBinaryField() |
24
|
|
|
{ |
25
|
|
|
$repository = $this->getRepository(); |
26
|
|
|
|
27
|
|
|
$parentLocationId = $this->generateId('location', 56); |
28
|
|
|
$sectionId = $this->generateId('section', 1); |
29
|
|
|
/* BEGIN: Inline */ |
30
|
|
|
// $parentLocationId is the id of the /Design/eZ-publish node |
31
|
|
|
|
32
|
|
|
$contentService = $repository->getContentService(); |
33
|
|
|
$contentTypeService = $repository->getContentTypeService(); |
34
|
|
|
$locationService = $repository->getLocationService(); |
35
|
|
|
|
36
|
|
|
// Configure new location |
37
|
|
|
$locationCreate = $locationService->newLocationCreateStruct($parentLocationId); |
38
|
|
|
|
39
|
|
|
$locationCreate->priority = 23; |
40
|
|
|
$locationCreate->hidden = true; |
41
|
|
|
$locationCreate->remoteId = '0123456789abcdef0123456789abcdefgh'; |
42
|
|
|
$locationCreate->sortField = Location::SORT_FIELD_NODE_ID; |
43
|
|
|
$locationCreate->sortOrder = Location::SORT_ORDER_DESC; |
44
|
|
|
|
45
|
|
|
// Load content type |
46
|
|
|
$contentType = $contentTypeService->loadContentTypeByIdentifier('video'); |
47
|
|
|
|
48
|
|
|
// Configure new content object |
49
|
|
|
$contentCreate = $contentService->newContentCreateStruct($contentType, 'eng-US'); |
50
|
|
|
|
51
|
|
|
$contentCreate->setField('name', 'An empty file'); |
52
|
|
|
$contentCreate->remoteId = 'abcdef0123456789abcdef0123456789gh'; |
53
|
|
|
// $sectionId is the ID of section 1 |
54
|
|
|
$contentCreate->sectionId = $sectionId; |
55
|
|
|
$contentCreate->alwaysAvailable = true; |
56
|
|
|
|
57
|
|
|
// Create a draft |
58
|
|
|
$draft = $contentService->createContent($contentCreate, array($locationCreate)); |
59
|
|
|
|
60
|
|
|
$content = $contentService->publishVersion($draft->getVersionInfo()); |
61
|
|
|
/* END: Inline */ |
62
|
|
|
|
63
|
|
|
return $content; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Creates a fresh clean content draft. |
68
|
|
|
* |
69
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Content |
70
|
|
|
*/ |
71
|
|
View Code Duplication |
protected function createContentDraftVersion1($locationId = 56, $contentTypeIdentifier = 'forum', $contentFieldNameIdentifier = 'name') |
72
|
|
|
{ |
73
|
|
|
$repository = $this->getRepository(); |
74
|
|
|
|
75
|
|
|
$parentLocationId = $this->generateId('location', $locationId); |
76
|
|
|
$sectionId = $this->generateId('section', 1); |
77
|
|
|
/* BEGIN: Inline */ |
78
|
|
|
// $parentLocationId is the id of the /Design/eZ-publish node |
79
|
|
|
|
80
|
|
|
$contentService = $repository->getContentService(); |
81
|
|
|
$contentTypeService = $repository->getContentTypeService(); |
82
|
|
|
$locationService = $repository->getLocationService(); |
83
|
|
|
|
84
|
|
|
// Configure new location |
85
|
|
|
$locationCreate = $locationService->newLocationCreateStruct($parentLocationId); |
86
|
|
|
|
87
|
|
|
$locationCreate->priority = 23; |
88
|
|
|
$locationCreate->hidden = true; |
89
|
|
|
$locationCreate->remoteId = '0123456789abcdef0123456789abcdef'; |
90
|
|
|
$locationCreate->sortField = Location::SORT_FIELD_NODE_ID; |
91
|
|
|
$locationCreate->sortOrder = Location::SORT_ORDER_DESC; |
92
|
|
|
|
93
|
|
|
// Load content type |
94
|
|
|
$contentType = $contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier); |
95
|
|
|
|
96
|
|
|
// Configure new content object |
97
|
|
|
$contentCreate = $contentService->newContentCreateStruct($contentType, 'eng-US'); |
98
|
|
|
|
99
|
|
|
$contentCreate->setField($contentFieldNameIdentifier, "An awesome {$contentTypeIdentifier}"); |
100
|
|
|
$contentCreate->remoteId = 'abcdef0123456789abcdef0123456789'; |
101
|
|
|
// $sectionId is the ID of section 1 |
102
|
|
|
$contentCreate->sectionId = $sectionId; |
103
|
|
|
$contentCreate->alwaysAvailable = true; |
104
|
|
|
|
105
|
|
|
// Create a draft |
106
|
|
|
$draft = $contentService->createContent($contentCreate, array($locationCreate)); |
107
|
|
|
/* END: Inline */ |
108
|
|
|
|
109
|
|
|
return $draft; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Creates a fresh clean published content instance. |
114
|
|
|
* |
115
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Content |
116
|
|
|
*/ |
117
|
|
View Code Duplication |
protected function createContentVersion1() |
118
|
|
|
{ |
119
|
|
|
$repository = $this->getRepository(); |
120
|
|
|
|
121
|
|
|
$contentService = $repository->getContentService(); |
122
|
|
|
|
123
|
|
|
/* BEGIN: Inline */ |
124
|
|
|
$draft = $this->createContentDraftVersion1(); |
125
|
|
|
|
126
|
|
|
// Publish this draft |
127
|
|
|
$content = $contentService->publishVersion($draft->getVersionInfo()); |
128
|
|
|
/* END: Inline */ |
129
|
|
|
|
130
|
|
|
return $content; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Creates a new content draft named <b>$draftVersion2</b> from a currently |
135
|
|
|
* published content object. |
136
|
|
|
* |
137
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Content |
138
|
|
|
*/ |
139
|
|
View Code Duplication |
protected function createContentDraftVersion2() |
140
|
|
|
{ |
141
|
|
|
$repository = $this->getRepository(); |
142
|
|
|
|
143
|
|
|
$contentService = $repository->getContentService(); |
144
|
|
|
|
145
|
|
|
/* BEGIN: Inline */ |
146
|
|
|
$content = $this->createContentVersion1(); |
147
|
|
|
|
148
|
|
|
// Create a new draft from the published content |
149
|
|
|
$draftVersion2 = $contentService->createContentDraft($content->contentInfo); |
150
|
|
|
/* END: Inline */ |
151
|
|
|
|
152
|
|
|
return $draftVersion2; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Creates an updated content draft named <b>$draftVersion2</b> from |
157
|
|
|
* a currently published content object. |
158
|
|
|
* |
159
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Content |
160
|
|
|
*/ |
161
|
|
|
protected function createUpdatedDraftVersion2() |
162
|
|
|
{ |
163
|
|
|
$repository = $this->getRepository(); |
164
|
|
|
|
165
|
|
|
$contentService = $repository->getContentService(); |
166
|
|
|
|
167
|
|
|
/* BEGIN: Inline */ |
168
|
|
|
$draftVersion2 = $this->createContentDraftVersion2(); |
169
|
|
|
|
170
|
|
|
// Create an update struct and modify some fields |
171
|
|
|
$contentUpdate = $contentService->newContentUpdateStruct(); |
172
|
|
|
$contentUpdate->initialLanguageCode = 'eng-US'; |
173
|
|
|
$contentUpdate->creatorId = $this->generateId('user', 10); |
174
|
|
|
$contentUpdate->setField('name', 'An awesome forum²'); |
175
|
|
|
$contentUpdate->setField('name', 'An awesome forum²³', 'eng-GB'); |
176
|
|
|
|
177
|
|
|
// Update the content draft |
178
|
|
|
$draftVersion2 = $contentService->updateContent( |
179
|
|
|
$draftVersion2->getVersionInfo(), |
180
|
|
|
$contentUpdate |
181
|
|
|
); |
182
|
|
|
/* END: Inline */ |
183
|
|
|
|
184
|
|
|
return $draftVersion2; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* Creates an updated content draft named <b>$draftVersion2</b> from |
189
|
|
|
* a currently published content object with a user different from the |
190
|
|
|
* creator. |
191
|
|
|
* |
192
|
|
|
* @return array \eZ\Publish\API\Repository\Values\Content\Content, id |
193
|
|
|
*/ |
194
|
|
|
protected function createUpdatedDraftVersion2NotAdmin() |
195
|
|
|
{ |
196
|
|
|
$repository = $this->getRepository(); |
197
|
|
|
|
198
|
|
|
$contentService = $repository->getContentService(); |
199
|
|
|
$userService = $repository->getUserService(); |
200
|
|
|
$mainLanguageCode = 'eng-US'; |
201
|
|
|
|
202
|
|
|
// Create a new user that belongs to the Administrator users group |
203
|
|
|
$newUserCreateStruct = $userService->newUserCreateStruct('admin2', '[email protected]', 'admin2', $mainLanguageCode); |
204
|
|
|
$newUserCreateStruct->setField('first_name', 'Admin2', $mainLanguageCode); |
205
|
|
|
$newUserCreateStruct->setField('last_name', 'Admin2', $mainLanguageCode); |
206
|
|
|
|
207
|
|
|
// Load the Admin Group |
208
|
|
|
$userAdminGroup = $userService->loadUserGroup('12'); |
209
|
|
|
$userAdmin2 = $userService->createUser($newUserCreateStruct, array($userAdminGroup)); |
210
|
|
|
|
211
|
|
|
/* BEGIN: Inline */ |
212
|
|
|
$draftVersion2 = $this->createContentDraftVersion2(); |
213
|
|
|
|
214
|
|
|
// Create an update struct and modify some fields |
215
|
|
|
$contentUpdate = $contentService->newContentUpdateStruct(); |
216
|
|
|
$contentUpdate->initialLanguageCode = $mainLanguageCode; |
217
|
|
|
|
218
|
|
|
$contentUpdate->creatorId = $this->generateId('user', $userAdmin2->id); |
219
|
|
|
$contentUpdate->setField('name', 'An awesome forum²'); |
220
|
|
|
$contentUpdate->setField('name', 'An awesome forum²³', 'eng-GB'); |
221
|
|
|
|
222
|
|
|
// Update the content draft |
223
|
|
|
$draftVersion2 = $contentService->updateContent( |
224
|
|
|
$draftVersion2->getVersionInfo(), |
225
|
|
|
$contentUpdate |
226
|
|
|
); |
227
|
|
|
/* END: Inline */ |
228
|
|
|
|
229
|
|
|
return array($draftVersion2, $userAdmin2->id); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* Creates an updated content object named <b>$contentVersion2</b> from |
234
|
|
|
* a currently published content object. |
235
|
|
|
* |
236
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Content |
237
|
|
|
*/ |
238
|
|
|
protected function createContentVersion2() |
239
|
|
|
{ |
240
|
|
|
$repository = $this->getRepository(); |
241
|
|
|
|
242
|
|
|
$contentService = $repository->getContentService(); |
243
|
|
|
|
244
|
|
|
/* BEGIN: Inline */ |
245
|
|
|
$draftVersion2 = $this->createUpdatedDraftVersion2(); |
246
|
|
|
|
247
|
|
|
// Publish the updated draft |
248
|
|
|
$contentVersion2 = $contentService->publishVersion($draftVersion2->getVersionInfo()); |
249
|
|
|
/* END: Inline */ |
250
|
|
|
|
251
|
|
|
return $contentVersion2; |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* Creates an updated content draft named <b>$draft</b>. |
256
|
|
|
* |
257
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Content |
258
|
|
|
*/ |
259
|
|
|
protected function createMultipleLanguageDraftVersion1() |
260
|
|
|
{ |
261
|
|
|
$repository = $this->getRepository(); |
262
|
|
|
|
263
|
|
|
$contentService = $repository->getContentService(); |
264
|
|
|
|
265
|
|
|
/* BEGIN: Inline */ |
266
|
|
|
$draft = $this->createContentDraftVersion1(); |
267
|
|
|
|
268
|
|
|
$contentUpdate = $contentService->newContentUpdateStruct(); |
269
|
|
|
|
270
|
|
|
$contentUpdate->initialLanguageCode = 'eng-US'; |
271
|
|
|
|
272
|
|
|
$contentUpdate->setField('name', 'An awesome multi-lang forum²'); |
273
|
|
|
|
274
|
|
|
$contentUpdate->setField('name', 'An awesome multi-lang forum²³', 'eng-GB'); |
275
|
|
|
|
276
|
|
|
$draft = $contentService->updateContent( |
277
|
|
|
$draft->getVersionInfo(), |
278
|
|
|
$contentUpdate |
279
|
|
|
); |
280
|
|
|
/* END: Inline */ |
281
|
|
|
|
282
|
|
|
return $draft; |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
/** |
286
|
|
|
* Creates a published content object with versionNo=2 named |
287
|
|
|
* <b>$contentVersion2</b>. |
288
|
|
|
* |
289
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Content |
290
|
|
|
*/ |
291
|
|
|
protected function createMultipleLanguageContentVersion2() |
292
|
|
|
{ |
293
|
|
|
$repository = $this->getRepository(); |
294
|
|
|
|
295
|
|
|
$contentService = $repository->getContentService(); |
296
|
|
|
|
297
|
|
|
/* BEGIN: Inline */ |
298
|
|
|
$draft = $this->createMultipleLanguageDraftVersion1(); |
299
|
|
|
|
300
|
|
|
// Publish this version. |
301
|
|
|
$contentVersion1 = $contentService->publishVersion( |
302
|
|
|
$draft->getVersionInfo() |
303
|
|
|
); |
304
|
|
|
|
305
|
|
|
// Create a new draft and update with same values |
306
|
|
|
$draftVersion2 = $contentService->createContentDraft( |
307
|
|
|
$contentVersion1->contentInfo |
308
|
|
|
); |
309
|
|
|
|
310
|
|
|
$contentUpdate = $contentService->newContentUpdateStruct(); |
311
|
|
|
foreach ($draftVersion2->getFields() as $field) { |
312
|
|
|
$contentUpdate->setField($field->fieldDefIdentifier, $field->value, $field->languageCode); |
|
|
|
|
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
$contentService->updateContent( |
316
|
|
|
$draftVersion2->getVersionInfo(), |
317
|
|
|
$contentUpdate |
318
|
|
|
); |
319
|
|
|
|
320
|
|
|
// Finally publish version 2 |
321
|
|
|
$contentVersion2 = $contentService->publishVersion( |
322
|
|
|
$draftVersion2->getVersionInfo() |
323
|
|
|
); |
324
|
|
|
/* END: Inline */ |
325
|
|
|
|
326
|
|
|
return $contentVersion2; |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
/** |
330
|
|
|
* Create Content Draft with custom field values and generated remoteId. |
331
|
|
|
* |
332
|
|
|
* @param string $contentTypeIdentifier |
333
|
|
|
* @param int $parentLocationId |
334
|
|
|
* @param array $fieldValues map of <code>['fieldIdentifier' => 'field value']</code> |
335
|
|
|
* |
336
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Content Content Draft |
337
|
|
|
*/ |
338
|
|
|
protected function createContentDraft( |
339
|
|
|
$contentTypeIdentifier, |
340
|
|
|
$parentLocationId, |
341
|
|
|
array $fieldValues |
342
|
|
|
) { |
343
|
|
|
$repository = $this->getRepository(); |
344
|
|
|
$contentService = $repository->getContentService(); |
345
|
|
|
$contentTypeService = $repository->getContentTypeService(); |
346
|
|
|
$locationService = $repository->getLocationService(); |
347
|
|
|
|
348
|
|
|
// Load content type |
349
|
|
|
$contentType = $contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier); |
350
|
|
|
|
351
|
|
|
// Prepare new Content Object |
352
|
|
|
$contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-US'); |
353
|
|
|
|
354
|
|
|
foreach ($fieldValues as $fieldIdentifier => $fieldValue) { |
355
|
|
|
$contentCreateStruct->setField($fieldIdentifier, $fieldValue); |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
$contentCreateStruct->sectionId = $this->generateId('section', 1); |
359
|
|
|
$contentCreateStruct->alwaysAvailable = true; |
360
|
|
|
|
361
|
|
|
// Prepare Location |
362
|
|
|
$locationCreateStruct = $locationService->newLocationCreateStruct( |
363
|
|
|
$this->generateId('location', $parentLocationId) |
364
|
|
|
); |
365
|
|
|
// Create a draft |
366
|
|
|
$contentDraft = $contentService->createContent( |
367
|
|
|
$contentCreateStruct, |
368
|
|
|
[$locationCreateStruct] |
369
|
|
|
); |
370
|
|
|
|
371
|
|
|
return $contentDraft; |
372
|
|
|
} |
373
|
|
|
} |
374
|
|
|
|
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.