1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the eZ Publish Kernel package. |
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\API\Repository\Tests; |
12
|
|
|
|
13
|
|
|
use eZ\Publish\API\Repository\Exceptions\NotFoundException; |
14
|
|
|
use eZ\Publish\API\Repository\Values\Content\LocationQuery; |
15
|
|
|
use eZ\Publish\API\Repository\Values\Content\Query; |
16
|
|
|
use eZ\Publish\API\Repository\Values\Content\Query\Criterion; |
17
|
|
|
use DateTime; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Test case for indexing operations with a search engine. |
21
|
|
|
* |
22
|
|
|
* @group integration |
23
|
|
|
* @group search |
24
|
|
|
* @group indexing |
25
|
|
|
*/ |
26
|
|
|
class SearchEngineIndexingTest extends BaseTest |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* EZP-26186: Make sure index is NOT deleted on removal of version draft (affected Solr & content index on Elastic). |
30
|
|
|
*/ |
31
|
|
|
public function testDeleteVersion() |
32
|
|
|
{ |
33
|
|
|
$repository = $this->getRepository(); |
34
|
|
|
$contentService = $repository->getContentService(); |
35
|
|
|
$searchService = $repository->getSearchService(); |
36
|
|
|
|
37
|
|
|
$membersContentId = $this->generateId('content', 11); |
38
|
|
|
$contentInfo = $contentService->loadContentInfo($membersContentId); |
39
|
|
|
|
40
|
|
|
$draft = $contentService->createContentDraft($contentInfo); |
41
|
|
|
$contentService->deleteVersion($draft->getVersionInfo()); |
42
|
|
|
|
43
|
|
|
$this->refreshSearch($repository); |
44
|
|
|
|
45
|
|
|
// Found |
46
|
|
|
$criterion = new Criterion\LocationId($contentInfo->mainLocationId); |
47
|
|
|
$query = new Query(array('filter' => $criterion)); |
48
|
|
|
$result = $searchService->findContentInfo($query); |
49
|
|
|
$this->assertEquals(1, $result->totalCount); |
50
|
|
|
$this->assertEquals( |
51
|
|
|
$contentInfo->id, |
52
|
|
|
$result->searchHits[0]->valueObject->id |
|
|
|
|
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* EZP-26186: Make sure affected child locations are deleted on content deletion (affected Solr & Elastic). |
58
|
|
|
*/ |
59
|
|
|
public function testDeleteContent() |
60
|
|
|
{ |
61
|
|
|
$repository = $this->getRepository(); |
62
|
|
|
$contentService = $repository->getContentService(); |
63
|
|
|
$searchService = $repository->getSearchService(); |
64
|
|
|
|
65
|
|
|
$anonymousUsersContentId = $this->generateId('content', 42); |
66
|
|
|
$contentInfo = $contentService->loadContentInfo($anonymousUsersContentId); |
67
|
|
|
|
68
|
|
|
$contentService->deleteContent($contentInfo); |
69
|
|
|
|
70
|
|
|
$this->refreshSearch($repository); |
71
|
|
|
|
72
|
|
|
// Should not be found |
73
|
|
|
$criterion = new Criterion\ParentLocationId($contentInfo->mainLocationId); |
74
|
|
|
$query = new LocationQuery(array('filter' => $criterion)); |
75
|
|
|
$result = $searchService->findLocations($query); |
76
|
|
|
$this->assertEquals(0, $result->totalCount); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function testCreateLocation() |
80
|
|
|
{ |
81
|
|
|
$repository = $this->getRepository(); |
82
|
|
|
$locationService = $repository->getLocationService(); |
83
|
|
|
$contentService = $repository->getContentService(); |
84
|
|
|
$searchService = $repository->getSearchService(); |
85
|
|
|
|
86
|
|
|
$rootLocationId = 2; |
87
|
|
|
$membersContentId = 11; |
88
|
|
|
$membersContentInfo = $contentService->loadContentInfo($membersContentId); |
89
|
|
|
|
90
|
|
|
$locationCreateStruct = $locationService->newLocationCreateStruct($rootLocationId); |
91
|
|
|
$membersLocation = $locationService->createLocation($membersContentInfo, $locationCreateStruct); |
92
|
|
|
|
93
|
|
|
$this->refreshSearch($repository); |
94
|
|
|
|
95
|
|
|
// Found |
96
|
|
|
$criterion = new Criterion\LocationId($membersLocation->id); |
97
|
|
|
$query = new LocationQuery(array('filter' => $criterion)); |
98
|
|
|
$result = $searchService->findLocations($query); |
99
|
|
|
$this->assertEquals(1, $result->totalCount); |
100
|
|
|
$this->assertEquals( |
101
|
|
|
$membersLocation->id, |
102
|
|
|
$result->searchHits[0]->valueObject->id |
|
|
|
|
103
|
|
|
); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function testMoveSubtree() |
107
|
|
|
{ |
108
|
|
|
$repository = $this->getRepository(); |
109
|
|
|
$locationService = $repository->getLocationService(); |
110
|
|
|
$contentService = $repository->getContentService(); |
111
|
|
|
$searchService = $repository->getSearchService(); |
112
|
|
|
|
113
|
|
|
$rootLocationId = 2; |
114
|
|
|
$membersContentId = 11; |
115
|
|
|
$adminsContentId = 12; |
116
|
|
|
$editorsContentId = 13; |
117
|
|
|
$membersContentInfo = $contentService->loadContentInfo($membersContentId); |
118
|
|
|
$adminsContentInfo = $contentService->loadContentInfo($adminsContentId); |
119
|
|
|
$editorsContentInfo = $contentService->loadContentInfo($editorsContentId); |
120
|
|
|
|
121
|
|
|
$locationCreateStruct = $locationService->newLocationCreateStruct($rootLocationId); |
122
|
|
|
$membersLocation = $locationService->createLocation($membersContentInfo, $locationCreateStruct); |
123
|
|
|
$editorsLocation = $locationService->createLocation($editorsContentInfo, $locationCreateStruct); |
124
|
|
|
$adminsLocation = $locationService->createLocation( |
125
|
|
|
$adminsContentInfo, |
126
|
|
|
$locationService->newLocationCreateStruct($membersLocation->id) |
127
|
|
|
); |
128
|
|
|
|
129
|
|
|
$this->refreshSearch($repository); |
130
|
|
|
|
131
|
|
|
// Not found under Editors |
132
|
|
|
$criterion = new Criterion\ParentLocationId($editorsLocation->id); |
133
|
|
|
$query = new LocationQuery(array('filter' => $criterion)); |
134
|
|
|
$result = $searchService->findLocations($query); |
135
|
|
|
$this->assertEquals(0, $result->totalCount); |
136
|
|
|
|
137
|
|
|
// Found under Members |
138
|
|
|
$criterion = new Criterion\ParentLocationId($membersLocation->id); |
139
|
|
|
$query = new LocationQuery(array('filter' => $criterion)); |
140
|
|
|
$result = $searchService->findLocations($query); |
141
|
|
|
$this->assertEquals(1, $result->totalCount); |
142
|
|
|
$this->assertEquals( |
143
|
|
|
$adminsLocation->id, |
144
|
|
|
$result->searchHits[0]->valueObject->id |
|
|
|
|
145
|
|
|
); |
146
|
|
|
|
147
|
|
|
$locationService->moveSubtree($adminsLocation, $editorsLocation); |
148
|
|
|
$this->refreshSearch($repository); |
149
|
|
|
|
150
|
|
|
// Found under Editors |
151
|
|
|
$criterion = new Criterion\ParentLocationId($editorsLocation->id); |
152
|
|
|
$query = new LocationQuery(array('filter' => $criterion)); |
153
|
|
|
$result = $searchService->findLocations($query); |
154
|
|
|
$this->assertEquals(1, $result->totalCount); |
155
|
|
|
$this->assertEquals( |
156
|
|
|
$adminsLocation->id, |
157
|
|
|
$result->searchHits[0]->valueObject->id |
|
|
|
|
158
|
|
|
); |
159
|
|
|
|
160
|
|
|
// Not found under Members |
161
|
|
|
$criterion = new Criterion\ParentLocationId($membersLocation->id); |
162
|
|
|
$query = new LocationQuery(array('filter' => $criterion)); |
163
|
|
|
$result = $searchService->findLocations($query); |
164
|
|
|
$this->assertEquals(0, $result->totalCount); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Testing that content is indexed even when containing only fields with values |
169
|
|
|
* considered to be empty by the search engine. |
170
|
|
|
*/ |
171
|
|
|
public function testIndexContentWithNullField() |
172
|
|
|
{ |
173
|
|
|
$repository = $this->getRepository(); |
174
|
|
|
$contentService = $repository->getContentService(); |
175
|
|
|
$contentTypeService = $repository->getContentTypeService(); |
176
|
|
|
$searchService = $repository->getSearchService(); |
177
|
|
|
|
178
|
|
|
$createStruct = $contentTypeService->newContentTypeCreateStruct('test-type'); |
179
|
|
|
$createStruct->mainLanguageCode = 'eng-GB'; |
180
|
|
|
$createStruct->names = array('eng-GB' => 'Test type'); |
181
|
|
|
$createStruct->creatorId = 14; |
182
|
|
|
$createStruct->creationDate = new DateTime(); |
183
|
|
|
|
184
|
|
|
$translatableFieldCreate = $contentTypeService->newFieldDefinitionCreateStruct( |
185
|
|
|
'integer', |
186
|
|
|
'ezinteger' |
187
|
|
|
); |
188
|
|
|
$translatableFieldCreate->names = array('eng-GB' => 'Simple translatable integer field'); |
189
|
|
|
$translatableFieldCreate->fieldGroup = 'main'; |
190
|
|
|
$translatableFieldCreate->position = 1; |
191
|
|
|
$translatableFieldCreate->isTranslatable = true; |
192
|
|
|
$translatableFieldCreate->isSearchable = true; |
193
|
|
|
|
194
|
|
|
$createStruct->addFieldDefinition($translatableFieldCreate); |
195
|
|
|
|
196
|
|
|
$contentGroup = $contentTypeService->loadContentTypeGroupByIdentifier('Content'); |
197
|
|
|
$contentTypeDraft = $contentTypeService->createContentType( |
198
|
|
|
$createStruct, |
199
|
|
|
array($contentGroup) |
200
|
|
|
); |
201
|
|
|
$contentTypeService->publishContentTypeDraft($contentTypeDraft); |
202
|
|
|
$contentType = $contentTypeService->loadContentType($contentTypeDraft->id); |
|
|
|
|
203
|
|
|
|
204
|
|
|
$createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
205
|
|
|
$createStruct->alwaysAvailable = false; |
206
|
|
|
$createStruct->mainLanguageCode = 'eng-GB'; |
207
|
|
|
|
208
|
|
|
$draft = $contentService->createContent($createStruct); |
209
|
|
|
$content = $contentService->publishVersion($draft->getVersionInfo()); |
210
|
|
|
|
211
|
|
|
$this->refreshSearch($repository); |
212
|
|
|
|
213
|
|
|
// Found |
214
|
|
|
$criterion = new Criterion\ContentId($content->id); |
215
|
|
|
$query = new Query(array('filter' => $criterion)); |
216
|
|
|
$result = $searchService->findContent($query); |
217
|
|
|
$this->assertEquals(1, $result->totalCount); |
218
|
|
|
$this->assertEquals( |
219
|
|
|
$content->id, |
220
|
|
|
$result->searchHits[0]->valueObject->id |
|
|
|
|
221
|
|
|
); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
public function testUpdateLocation() |
225
|
|
|
{ |
226
|
|
|
$repository = $this->getRepository(); |
227
|
|
|
$locationService = $repository->getLocationService(); |
228
|
|
|
$searchService = $repository->getSearchService(); |
229
|
|
|
|
230
|
|
|
$rootLocationId = 2; |
231
|
|
|
$locationToUpdate = $locationService->loadLocation($rootLocationId); |
232
|
|
|
|
233
|
|
|
$criterion = new Criterion\LogicalAnd([ |
234
|
|
|
new Criterion\LocationId($rootLocationId), |
235
|
|
|
new Criterion\Location\Priority(Criterion\Operator::GT, 0), |
236
|
|
|
]); |
237
|
|
|
|
238
|
|
|
$query = new LocationQuery(array('filter' => $criterion)); |
239
|
|
|
$result = $searchService->findLocations($query); |
240
|
|
|
|
241
|
|
|
$this->assertEquals(0, $result->totalCount); |
242
|
|
|
|
243
|
|
|
$locationUpdateStruct = $locationService->newLocationUpdateStruct(); |
244
|
|
|
$locationUpdateStruct->priority = 4; |
245
|
|
|
$locationService->updateLocation($locationToUpdate, $locationUpdateStruct); |
246
|
|
|
|
247
|
|
|
$this->refreshSearch($repository); |
248
|
|
|
|
249
|
|
|
$result = $searchService->findLocations($query); |
250
|
|
|
|
251
|
|
|
$this->assertEquals(1, $result->totalCount); |
252
|
|
|
$this->assertEquals( |
253
|
|
|
$locationToUpdate->id, |
254
|
|
|
$result->searchHits[0]->valueObject->id |
|
|
|
|
255
|
|
|
); |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* Testing that content will be deleted with all of its subitems but subitems with additional location will stay as |
260
|
|
|
* they are. |
261
|
|
|
*/ |
262
|
|
|
public function testDeleteLocation() |
263
|
|
|
{ |
264
|
|
|
$repository = $this->getRepository(); |
265
|
|
|
$locationService = $repository->getLocationService(); |
266
|
|
|
|
267
|
|
|
$treeContainerContent = $this->createContentWithName('Tree Container', [2]); |
268
|
|
|
$supposeBeDeletedSubItem = $this->createContentWithName( |
269
|
|
|
'Suppose to be deleted sub-item', |
270
|
|
|
[$treeContainerContent->contentInfo->mainLocationId] |
271
|
|
|
); |
272
|
|
|
$supposeSurviveSubItem = $this->createContentWithName( |
273
|
|
|
'Suppose to Survive Item', |
274
|
|
|
[2, $treeContainerContent->contentInfo->mainLocationId] |
275
|
|
|
); |
276
|
|
|
|
277
|
|
|
$treeContainerLocation = $locationService->loadLocation($treeContainerContent->contentInfo->mainLocationId); |
278
|
|
|
|
279
|
|
|
$this->refreshSearch($repository); |
280
|
|
|
|
281
|
|
|
$this->assertContentIdSearch($treeContainerContent->id, 1); |
282
|
|
|
$this->assertContentIdSearch($supposeSurviveSubItem->id, 1); |
283
|
|
|
$this->assertContentIdSearch($supposeBeDeletedSubItem->id, 1); |
284
|
|
|
|
285
|
|
|
$locationService->deleteLocation($treeContainerLocation); |
286
|
|
|
|
287
|
|
|
$this->refreshSearch($repository); |
288
|
|
|
|
289
|
|
|
$this->assertContentIdSearch($supposeSurviveSubItem->id, 1); |
290
|
|
|
$this->assertContentIdSearch($treeContainerContent->id, 0); |
291
|
|
|
$this->assertContentIdSearch($supposeBeDeletedSubItem->id, 0); |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* Test that swapping locations affects properly Search Engine Index. |
296
|
|
|
*/ |
297
|
|
|
public function testSwapLocation() |
298
|
|
|
{ |
299
|
|
|
$repository = $this->getRepository(); |
300
|
|
|
$locationService = $repository->getLocationService(); |
301
|
|
|
$searchService = $repository->getSearchService(); |
302
|
|
|
|
303
|
|
|
$content01 = $this->createContentWithName('content01', [2]); |
304
|
|
|
$location01 = $locationService->loadLocation($content01->contentInfo->mainLocationId); |
305
|
|
|
|
306
|
|
|
$content02 = $this->createContentWithName('content02', [2]); |
307
|
|
|
$location02 = $locationService->loadLocation($content02->contentInfo->mainLocationId); |
308
|
|
|
|
309
|
|
|
$locationService->swapLocation($location01, $location02); |
310
|
|
|
$this->refreshSearch($repository); |
311
|
|
|
|
312
|
|
|
// content02 should be at location01 |
313
|
|
|
$criterion = new Criterion\LocationId($location01->id); |
314
|
|
|
$query = new Query(['filter' => $criterion]); |
315
|
|
|
$results = $searchService->findContent($query); |
316
|
|
|
$this->assertEquals(1, $results->totalCount); |
317
|
|
|
$this->assertEquals($content02->id, $results->searchHits[0]->valueObject->id); |
|
|
|
|
318
|
|
|
|
319
|
|
|
// content01 should be at location02 |
320
|
|
|
$criterion = new Criterion\LocationId($location02->id); |
321
|
|
|
$query = new Query(['filter' => $criterion]); |
322
|
|
|
$results = $searchService->findContent($query); |
323
|
|
|
$this->assertEquals(1, $results->totalCount); |
324
|
|
|
$this->assertEquals($content01->id, $results->searchHits[0]->valueObject->id); |
|
|
|
|
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
/** |
328
|
|
|
* Test that updating Content metadata affects properly Search Engine Index. |
329
|
|
|
*/ |
330
|
|
|
public function testUpdateContentMetadata() |
331
|
|
|
{ |
332
|
|
|
$repository = $this->getRepository(); |
333
|
|
|
$contentService = $repository->getContentService(); |
334
|
|
|
$locationService = $repository->getLocationService(); |
335
|
|
|
$searchService = $repository->getSearchService(); |
336
|
|
|
|
337
|
|
|
$publishedContent = $this->createContentWithName('updateMetadataTest', [2]); |
338
|
|
|
$newLocationCreateStruct = $locationService->newLocationCreateStruct(60); |
339
|
|
|
$newLocation = $locationService->createLocation($publishedContent->contentInfo, $newLocationCreateStruct); |
340
|
|
|
|
341
|
|
|
$newContentMetadataUpdateStruct = $contentService->newContentMetadataUpdateStruct(); |
342
|
|
|
$newContentMetadataUpdateStruct->remoteId = md5('Test'); |
343
|
|
|
$newContentMetadataUpdateStruct->publishedDate = new \DateTime(); |
344
|
|
|
$newContentMetadataUpdateStruct->publishedDate->add(new \DateInterval('P1D')); |
345
|
|
|
$newContentMetadataUpdateStruct->mainLocationId = $newLocation->id; |
346
|
|
|
|
347
|
|
|
$contentService->updateContentMetadata($publishedContent->contentInfo, $newContentMetadataUpdateStruct); |
348
|
|
|
$this->refreshSearch($repository); |
349
|
|
|
|
350
|
|
|
// find Content by Id, calling findContentInfo which is using the Search Index |
351
|
|
|
$criterion = new Criterion\ContentId($publishedContent->id); |
352
|
|
|
$query = new Query(['filter' => $criterion]); |
353
|
|
|
$results = $searchService->findContentInfo($query); |
354
|
|
|
$this->assertEquals(1, $results->totalCount); |
355
|
|
|
$this->assertEquals($publishedContent->contentInfo->id, $results->searchHits[0]->valueObject->id); |
|
|
|
|
356
|
|
|
|
357
|
|
|
// find Content using updated RemoteId |
358
|
|
|
$criterion = new Criterion\RemoteId($newContentMetadataUpdateStruct->remoteId); |
359
|
|
|
$query = new Query(['filter' => $criterion]); |
360
|
|
|
$results = $searchService->findContent($query); |
361
|
|
|
$this->assertEquals(1, $results->totalCount); |
362
|
|
|
$foundContentInfo = $results->searchHits[0]->valueObject->contentInfo; |
|
|
|
|
363
|
|
|
/** @var \eZ\Publish\Core\Repository\Values\Content\Content $foundContentInfo */ |
364
|
|
|
$this->assertEquals($publishedContent->id, $foundContentInfo->id); |
365
|
|
|
$this->assertEquals($newContentMetadataUpdateStruct->publishedDate, $foundContentInfo->publishedDate); |
|
|
|
|
366
|
|
|
$this->assertEquals($newLocation->id, $foundContentInfo->mainLocationId); |
|
|
|
|
367
|
|
|
$this->assertEquals($newContentMetadataUpdateStruct->remoteId, $foundContentInfo->remoteId); |
|
|
|
|
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
/** |
371
|
|
|
* Test that assigning section to content object properly affects Search Engine Index. |
372
|
|
|
*/ |
373
|
|
|
public function testAssignSection() |
374
|
|
|
{ |
375
|
|
|
$repository = $this->getRepository(); |
376
|
|
|
$sectionService = $repository->getSectionService(); |
377
|
|
|
$searchService = $repository->getSearchService(); |
378
|
|
|
|
379
|
|
|
$section = $sectionService->loadSection(2); |
380
|
|
|
$content = $this->createContentWithName('testAssignSection', [2]); |
381
|
|
|
|
382
|
|
|
$sectionService->assignSection($content->contentInfo, $section); |
383
|
|
|
$this->refreshSearch($repository); |
384
|
|
|
|
385
|
|
|
$criterion = new Criterion\ContentId($content->id); |
386
|
|
|
$query = new Query(['filter' => $criterion]); |
387
|
|
|
$results = $searchService->findContentInfo($query); |
388
|
|
|
$this->assertEquals($section->id, $results->searchHits[0]->valueObject->sectionId); |
|
|
|
|
389
|
|
|
} |
390
|
|
|
|
391
|
|
|
/** |
392
|
|
|
* Will create if not exists an simple content type for test purposes with just one required field name. |
393
|
|
|
* |
394
|
|
|
* @return \eZ\Publish\API\Repository\Values\ContentType\ContentType |
395
|
|
|
*/ |
396
|
|
|
protected function createTestContentType() |
397
|
|
|
{ |
398
|
|
|
$repository = $this->getRepository(); |
399
|
|
|
$contentTypeService = $repository->getContentTypeService(); |
400
|
|
|
$contentTypeIdentifier = 'test-type'; |
401
|
|
|
try { |
402
|
|
|
return $contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier); |
403
|
|
|
} catch (NotFoundException $e) { |
404
|
|
|
// continue creation process |
405
|
|
|
} |
406
|
|
|
|
407
|
|
|
$nameField = $contentTypeService->newFieldDefinitionCreateStruct('name', 'ezstring'); |
408
|
|
|
$nameField->fieldGroup = 'main'; |
409
|
|
|
$nameField->position = 1; |
410
|
|
|
$nameField->isTranslatable = true; |
411
|
|
|
$nameField->isSearchable = true; |
412
|
|
|
$nameField->isRequired = true; |
413
|
|
|
$contentTypeStruct = $contentTypeService->newContentTypeCreateStruct($contentTypeIdentifier); |
414
|
|
|
$contentTypeStruct->mainLanguageCode = 'eng-GB'; |
415
|
|
|
$contentTypeStruct->creatorId = 14; |
416
|
|
|
$contentTypeStruct->creationDate = new DateTime(); |
417
|
|
|
$contentTypeStruct->names = ['eng-GB' => 'Test Content Type']; |
418
|
|
|
$contentTypeStruct->addFieldDefinition($nameField); |
419
|
|
|
|
420
|
|
|
$contentTypeGroup = $contentTypeService->loadContentTypeGroupByIdentifier('Content'); |
421
|
|
|
|
422
|
|
|
$contentTypeDraft = $contentTypeService->createContentType($contentTypeStruct, [$contentTypeGroup]); |
423
|
|
|
$contentTypeService->publishContentTypeDraft($contentTypeDraft); |
424
|
|
|
|
425
|
|
|
return $contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier); |
426
|
|
|
} |
427
|
|
|
|
428
|
|
|
/** |
429
|
|
|
* Will create and publish an content with a filed with a given content name in location provided into |
430
|
|
|
* $parentLocationIdList. |
431
|
|
|
* |
432
|
|
|
* @param string $contentName |
433
|
|
|
* @param array $parentLocationIdList |
434
|
|
|
* |
435
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Content |
436
|
|
|
*/ |
437
|
|
|
protected function createContentWithName($contentName, array $parentLocationIdList = array()) |
438
|
|
|
{ |
439
|
|
|
$contentService = $this->getRepository()->getContentService(); |
440
|
|
|
$locationService = $this->getRepository()->getLocationService(); |
441
|
|
|
|
442
|
|
|
$testableContentType = $this->createTestContentType(); |
443
|
|
|
|
444
|
|
|
$rootContentStruct = $contentService->newContentCreateStruct($testableContentType, 'eng-GB'); |
445
|
|
|
$rootContentStruct->setField('name', $contentName); |
446
|
|
|
|
447
|
|
|
$parentLocationList = []; |
448
|
|
|
foreach ($parentLocationIdList as $locationID) { |
449
|
|
|
$parentLocationList[] = $locationService->newLocationCreateStruct($locationID); |
450
|
|
|
} |
451
|
|
|
|
452
|
|
|
$contentDraft = $contentService->createContent($rootContentStruct, $parentLocationList); |
453
|
|
|
$publishedContent = $contentService->publishVersion($contentDraft->getVersionInfo()); |
454
|
|
|
|
455
|
|
|
return $publishedContent; |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
/** |
459
|
|
|
* Asserts an content id if it exists still in the solr core. |
460
|
|
|
* |
461
|
|
|
* @param int $contentId |
462
|
|
|
* @param int $expectedCount |
463
|
|
|
*/ |
464
|
|
|
protected function assertContentIdSearch($contentId, $expectedCount) |
465
|
|
|
{ |
466
|
|
|
$searchService = $this->getRepository()->getSearchService(); |
467
|
|
|
|
468
|
|
|
$criterion = new Criterion\ContentId($contentId); |
469
|
|
|
$query = new Query(array('filter' => $criterion)); |
470
|
|
|
$result = $searchService->findContent($query); |
471
|
|
|
|
472
|
|
|
$this->assertEquals($expectedCount, $result->totalCount); |
473
|
|
|
if ($expectedCount == 0) { |
474
|
|
|
return; |
475
|
|
|
} |
476
|
|
|
|
477
|
|
|
$this->assertEquals( |
478
|
|
|
$contentId, |
479
|
|
|
$result->searchHits[0]->valueObject->id |
|
|
|
|
480
|
|
|
); |
481
|
|
|
} |
482
|
|
|
} |
483
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read 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.