Completed
Push — test-EZP-26707-issearchable-fu... ( 0d4c60...620f44 )
by
unknown
13:09
created

testFindContentInfoFullTextIsSearchable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 0
dl 0
loc 22
rs 9.2
c 0
b 0
f 0
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\Tests\SetupFactory\LegacyElasticsearch as LegacyElasticsearchSetupFactory;
14
use eZ\Publish\API\Repository\Exceptions\NotFoundException;
15
use eZ\Publish\API\Repository\SearchService;
16
use eZ\Publish\API\Repository\Tests\SetupFactory\LegacyElasticsearch;
17
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
18
use eZ\Publish\API\Repository\Values\Content\LocationQuery;
19
use eZ\Publish\API\Repository\Values\Content\Query;
20
use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
21
use DateTime;
22
23
/**
24
 * Test case for indexing operations with a search engine.
25
 *
26
 * @group integration
27
 * @group search
28
 * @group indexing
29
 */
30
class SearchEngineIndexingTest extends BaseTest
31
{
32
    /**
33
     * Test that indexing full text data depends on the isSearchable flag on the field definition.
34
     */
35
    public function testFindContentInfoFullTextIsSearchable()
36
    {
37
        $searchTerm = 'pamplemousse';
38
        $content = $this->createFullTextIsSearchableContent($searchTerm, true);
39
40
        $repository = $this->getRepository();
41
        $searchService = $repository->getSearchService();
42
43
        $query = new Query(
44
            [
45
                'query' => new Criterion\FullText($searchTerm),
46
            ]
47
        );
48
49
        $searchResult = $searchService->findContentInfo($query);
50
51
        $this->assertEquals(1, $searchResult->totalCount);
52
        $contentInfo = $searchResult->searchHits[0]->valueObject;
53
        $this->assertEquals($content->id, $contentInfo->id);
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
54
55
        return $contentInfo;
56
    }
57
58
    /**
59
     * Test that indexing full text data depends on the isSearchable flag on the field definition.
60
     *
61
     * @depends testFindContentInfoFullTextIsSearchable
62
     *
63
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
64
     */
65
    public function testFindLocationsFullTextIsSearchable(ContentInfo $contentInfo)
66
    {
67
        $setupFactory = $this->getSetupFactory();
68
        if ($setupFactory instanceof LegacyElasticsearchSetupFactory) {
69
            $this->markTestSkipped(
70
                'Elasticsearch Search Engine is missing full text Location search implementation'
71
            );
72
        }
73
74
        $searchTerm = 'pamplemousse';
75
76
        $repository = $this->getRepository(false);
77
        $searchService = $repository->getSearchService();
78
79
        $query = new LocationQuery(
80
            [
81
                'query' => new Criterion\FullText($searchTerm),
82
            ]
83
        );
84
85
        $searchResult = $searchService->findLocations($query);
86
87
        $this->assertEquals(1, $searchResult->totalCount);
88
        $this->assertEquals(
89
            $contentInfo->mainLocationId,
90
            $searchResult->searchHits[0]->valueObject->id
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
91
        );
92
    }
93
94
    /**
95
     * Test that indexing full text data depends on the isSearchable flag on the field definition.
96
     *
97
     * @depends testFindContentInfoFullTextIsSearchable
98
     */
99 View Code Duplication
    public function testFindContentInfoFullTextIsNotSearchable()
100
    {
101
        $searchTerm = 'pamplemousse';
102
        $this->createFullTextIsSearchableContent($searchTerm, false);
103
104
        $repository = $this->getRepository();
105
        $searchService = $repository->getSearchService();
106
107
        $query = new Query(
108
            [
109
                'query' => new Criterion\FullText($searchTerm),
110
            ]
111
        );
112
113
        $searchResult = $searchService->findContentInfo($query);
114
115
        $this->assertEquals(0, $searchResult->totalCount);
116
    }
117
118
    /**
119
     * Test that indexing full text data depends on the isSearchable flag on the field definition.
120
     *
121
     * @depends testFindLocationsFullTextIsSearchable
122
     */
123 View Code Duplication
    public function testFindLocationsFullTextIsNotSearchable()
124
    {
125
        $searchTerm = 'pamplemousse';
126
127
        $repository = $this->getRepository(false);
128
        $searchService = $repository->getSearchService();
129
130
        $query = new LocationQuery(
131
            [
132
                'query' => new Criterion\FullText($searchTerm),
133
            ]
134
        );
135
136
        $searchResult = $searchService->findLocations($query);
137
138
        $this->assertEquals(0, $searchResult->totalCount);
139
    }
140
141
    /**
142
     * Creates Content for testing full text search depending on the isSearchable flag.
143
     *
144
     * @see testFindContentInfoFullTextIsearchable
145
     * @see testFindLocationsFullTextIsSearchable
146
     * @see testFindContentInfoFullTextIsNotSearchable
147
     * @see testFindLocationsFullTextIsNotSearchable
148
     *
149
     * @param string $searchText
150
     * @param bool $isSearchable
151
     *
152
     * @return \eZ\Publish\API\Repository\Values\Content\Content
153
     */
154
    protected function createFullTextIsSearchableContent($searchText, $isSearchable)
155
    {
156
        $repository = $this->getRepository();
157
        $contentService = $repository->getContentService();
158
        $contentTypeService = $repository->getContentTypeService();
159
        $locationService = $repository->getLocationService();
160
        $contentType = $contentTypeService->loadContentTypeByIdentifier('folder');
161
162
        if (!$isSearchable) {
163
            $contentTypeDraft = $contentTypeService->createContentTypeDraft($contentType);
164
            $fieldDefinitionUpdateStruct = $contentTypeService->newFieldDefinitionUpdateStruct();
165
            $fieldDefinitionUpdateStruct->isSearchable = false;
166
167
            $fieldDefinition = $contentType->getFieldDefinition('name');
168
169
            $contentTypeService->updateFieldDefinition(
170
                $contentTypeDraft,
171
                $fieldDefinition,
172
                $fieldDefinitionUpdateStruct
173
            );
174
175
            $contentTypeService->publishContentTypeDraft($contentTypeDraft);
176
            $contentType = $contentTypeService->loadContentTypeByIdentifier('folder');
177
        }
178
179
        $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
180
181
        $contentCreateStruct->setField('name', $searchText);
182
        $contentCreateStruct->setField('short_name', 'hello world');
183
        $content = $contentService->publishVersion(
184
            $contentService->createContent(
185
                $contentCreateStruct,
186
                [$locationService->newLocationCreateStruct(2)]
187
            )->versionInfo
188
        );
189
190
        $this->refreshSearch($repository);
191
192
        return $content;
193
    }
194
195
    /**
196
     * EZP-26186: Make sure index is NOT deleted on removal of version draft (affected Solr & content index on Elastic).
197
     */
198
    public function testDeleteVersion()
199
    {
200
        $repository = $this->getRepository();
201
        $contentService = $repository->getContentService();
202
        $searchService = $repository->getSearchService();
203
204
        $membersContentId = $this->generateId('content', 11);
205
        $contentInfo = $contentService->loadContentInfo($membersContentId);
206
207
        $draft = $contentService->createContentDraft($contentInfo);
208
        $contentService->deleteVersion($draft->getVersionInfo());
209
210
        $this->refreshSearch($repository);
211
212
        // Found
213
        $criterion = new Criterion\LocationId($contentInfo->mainLocationId);
214
        $query = new Query(array('filter' => $criterion));
215
        $result = $searchService->findContentInfo($query);
216
        $this->assertEquals(1, $result->totalCount);
217
        $this->assertEquals(
218
            $contentInfo->id,
219
            $result->searchHits[0]->valueObject->id
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
220
        );
221
    }
222
223
    /**
224
     * EZP-26186: Make sure affected child locations are deleted on content deletion (affected Solr & Elastic).
225
     */
226 View Code Duplication
    public function testDeleteContent()
227
    {
228
        $repository = $this->getRepository();
229
        $contentService = $repository->getContentService();
230
        $searchService = $repository->getSearchService();
231
232
        $anonymousUsersContentId = $this->generateId('content', 42);
233
        $contentInfo = $contentService->loadContentInfo($anonymousUsersContentId);
234
235
        $contentService->deleteContent($contentInfo);
236
237
        $this->refreshSearch($repository);
238
239
        // Should not be found
240
        $criterion = new Criterion\ParentLocationId($contentInfo->mainLocationId);
241
        $query = new LocationQuery(array('filter' => $criterion));
242
        $result = $searchService->findLocations($query);
243
        $this->assertEquals(0, $result->totalCount);
244
    }
245
246
    /**
247
     * EZP-26186: Make sure index is deleted on removal of Users  (affected Solr & Elastic).
248
     */
249 View Code Duplication
    public function testDeleteUser()
250
    {
251
        $repository = $this->getRepository();
252
        $userService = $repository->getUserService();
253
        $searchService = $repository->getSearchService();
254
255
        $anonymousContentId = $this->generateId('user', 10);
256
        $user = $userService->loadUser($anonymousContentId);
257
258
        $userService->deleteUser($user);
259
260
        $this->refreshSearch($repository);
261
262
        // Should not be found
263
        $criterion = new Criterion\ContentId($user->id);
264
        $query = new Query(array('filter' => $criterion));
265
        $result = $searchService->findContentInfo($query);
266
        $this->assertEquals(0, $result->totalCount);
267
    }
268
269
    /**
270
     * EZP-26186: Make sure index is deleted on removal of UserGroups  (affected Solr & Elastic).
271
     */
272 View Code Duplication
    public function testDeleteUserGroup()
273
    {
274
        $repository = $this->getRepository();
275
        $userService = $repository->getUserService();
276
        $searchService = $repository->getSearchService();
277
278
        $membersContentId = $this->generateId('user_group', 11);
279
        $userGroup = $userService->loadUserGroup($membersContentId);
280
281
        $userService->deleteUserGroup($userGroup);
282
283
        $this->refreshSearch($repository);
284
285
        // Should not be found
286
        $criterion = new Criterion\ContentId($userGroup->id);
287
        $query = new Query(array('filter' => $criterion));
288
        $result = $searchService->findContentInfo($query);
289
        $this->assertEquals(0, $result->totalCount);
290
    }
291
292
   /*
293
    * Test that a newly created user is available for search.
294
    */
295
    public function testCreateUser()
296
    {
297
        $repository = $this->getRepository();
298
        $userService = $repository->getUserService();
299
        $searchService = $repository->getSearchService();
300
301
        // ID of the "Editors" user group
302
        $editorsGroupId = 13;
303
        $userCreate = $userService->newUserCreateStruct(
304
            'user',
305
            '[email protected]',
306
            'secret',
307
            'eng-US'
308
        );
309
        $userCreate->enabled = true;
310
        $userCreate->setField('first_name', 'Example');
311
        $userCreate->setField('last_name', 'User');
312
313
        // Load parent group for the user
314
        $group = $userService->loadUserGroup($editorsGroupId);
315
316
        // Create a new user instance.
317
        $user = $userService->createUser($userCreate, array($group));
318
319
        $this->refreshSearch($repository);
320
321
        // Should be found
322
        $criterion = new Criterion\ContentId($user->id);
323
        $query = new Query(array('filter' => $criterion));
324
        $result = $searchService->findContentInfo($query);
325
        $this->assertEquals(1, $result->totalCount);
326
    }
327
328
    /**
329
     * Test that a newly created user group is available for search.
330
     */
331
    public function testCreateUserGroup()
332
    {
333
        $repository = $this->getRepository();
334
        $userService = $repository->getUserService();
335
        $searchService = $repository->getSearchService();
336
337
        $mainGroupId = $this->generateId('group', 4);
338
339
        $parentUserGroup = $userService->loadUserGroup($mainGroupId);
340
        $userGroupCreateStruct = $userService->newUserGroupCreateStruct('eng-GB');
341
        $userGroupCreateStruct->setField('name', 'Example Group');
342
343
        // Create a new user group
344
        $userGroup = $userService->createUserGroup(
345
            $userGroupCreateStruct,
346
            $parentUserGroup
347
        );
348
349
        $this->refreshSearch($repository);
350
351
        // Should be found
352
        $criterion = new Criterion\ContentId($userGroup->id);
353
        $query = new Query(array('filter' => $criterion));
354
        $result = $searchService->findContentInfo($query);
355
        $this->assertEquals(1, $result->totalCount);
356
    }
357
358
    /**
359
     * Test that a newly created Location is available for search.
360
     */
361
    public function testCreateLocation()
362
    {
363
        $repository = $this->getRepository();
364
        $searchService = $repository->getSearchService();
365
        $membersLocation = $this->createNewTestLocation();
366
367
        $this->refreshSearch($repository);
368
369
        // Found
370
        $criterion = new Criterion\LocationId($membersLocation->id);
371
        $query = new LocationQuery(array('filter' => $criterion));
372
        $result = $searchService->findLocations($query);
373
        $this->assertEquals(1, $result->totalCount);
374
        $this->assertEquals(
375
            $membersLocation->id,
376
            $result->searchHits[0]->valueObject->id
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
377
        );
378
    }
379
380
    /**
381
     * Test that hiding a Location makes it unavailable for search.
382
     */
383
    public function testHideSubtree()
384
    {
385
        $repository = $this->getRepository();
386
        $searchService = $repository->getSearchService();
387
388
        // 5 is the ID of an existing location
389
        $locationId = $this->generateId('location', 5);
390
        $locationService = $repository->getLocationService();
391
        $location = $locationService->loadLocation($locationId);
392
        $locationService->hideLocation($location);
393
        $this->refreshSearch($repository);
394
395
        // Check if parent location is hidden
396
        $criterion = new Criterion\LocationId($locationId);
397
        $query = new LocationQuery(array('filter' => $criterion));
398
        $result = $searchService->findLocations($query);
399
        $this->assertEquals(1, $result->totalCount);
400
        $this->assertTrue($result->searchHits[0]->valueObject->hidden);
0 ignored issues
show
Documentation introduced by
The property hidden does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
401
402
        // Check if children locations are invisible
403
        $this->assertSubtreeInvisibleProperty($searchService, $locationId, true);
404
    }
405
406
    /**
407
     * Test that hiding and revealing a Location makes it available for search.
408
     */
409
    public function testRevealSubtree()
410
    {
411
        $repository = $this->getRepository();
412
        $searchService = $repository->getSearchService();
413
414
        // 5 is the ID of an existing location
415
        $locationId = $this->generateId('location', 5);
416
        $locationService = $repository->getLocationService();
417
        $location = $locationService->loadLocation($locationId);
418
        $locationService->hideLocation($location);
419
        $this->refreshSearch($repository);
420
        $locationService->unhideLocation($location);
421
        $this->refreshSearch($repository);
422
423
        // Check if parent location is not hidden
424
        $criterion = new Criterion\LocationId($locationId);
425
        $query = new LocationQuery(array('filter' => $criterion));
426
        $result = $searchService->findLocations($query);
427
        $this->assertEquals(1, $result->totalCount);
428
        $this->assertFalse($result->searchHits[0]->valueObject->hidden);
0 ignored issues
show
Documentation introduced by
The property hidden does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
429
430
        // Check if children locations are not invisible
431
        $this->assertSubtreeInvisibleProperty($searchService, $locationId, false);
432
    }
433
434
    /**
435
     * Test that a copied subtree is available for search.
436
     */
437
    public function testCopySubtree()
438
    {
439
        $repository = $this->getRepository();
440
        $locationService = $repository->getLocationService();
441
        $contentService = $repository->getContentService();
442
        $searchService = $repository->getSearchService();
443
444
        $rootLocationId = 2;
445
        $membersContentId = 11;
446
        $adminsContentId = 12;
447
        $editorsContentId = 13;
448
        $membersContentInfo = $contentService->loadContentInfo($membersContentId);
449
        $adminsContentInfo = $contentService->loadContentInfo($adminsContentId);
450
        $editorsContentInfo = $contentService->loadContentInfo($editorsContentId);
451
452
        $locationCreateStruct = $locationService->newLocationCreateStruct($rootLocationId);
453
        $membersLocation = $locationService->createLocation($membersContentInfo, $locationCreateStruct);
454
        $editorsLocation = $locationService->createLocation($editorsContentInfo, $locationCreateStruct);
455
        $adminsLocation = $locationService->createLocation(
456
            $adminsContentInfo,
457
            $locationService->newLocationCreateStruct($membersLocation->id)
458
        );
459
460
        $copiedLocation = $locationService->copySubtree($adminsLocation, $editorsLocation);
461
        $this->refreshSearch($repository);
462
463
        // Found under Members
464
        $criterion = new Criterion\ParentLocationId($membersLocation->id);
465
        $query = new LocationQuery(array('filter' => $criterion));
466
        $result = $searchService->findLocations($query);
467
        $this->assertEquals(1, $result->totalCount);
468
        $this->assertEquals(
469
            $adminsLocation->id,
470
            $result->searchHits[0]->valueObject->id
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
471
        );
472
473
        // Found under Editors
474
        $criterion = new Criterion\ParentLocationId($editorsLocation->id);
475
        $query = new LocationQuery(array('filter' => $criterion));
476
        $result = $searchService->findLocations($query);
477
        $this->assertEquals(1, $result->totalCount);
478
        $this->assertEquals(
479
            $copiedLocation->id,
480
            $result->searchHits[0]->valueObject->id
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
481
        );
482
    }
483
484
    /**
485
     * Test that moved subtree is available for search and found only under a specific parent Location.
486
     */
487
    public function testMoveSubtree()
488
    {
489
        $repository = $this->getRepository();
490
        $locationService = $repository->getLocationService();
491
        $contentService = $repository->getContentService();
492
        $searchService = $repository->getSearchService();
493
494
        $rootLocationId = 2;
495
        $membersContentId = 11;
496
        $adminsContentId = 12;
497
        $editorsContentId = 13;
498
        $membersContentInfo = $contentService->loadContentInfo($membersContentId);
499
        $adminsContentInfo = $contentService->loadContentInfo($adminsContentId);
500
        $editorsContentInfo = $contentService->loadContentInfo($editorsContentId);
501
502
        $locationCreateStruct = $locationService->newLocationCreateStruct($rootLocationId);
503
        $membersLocation = $locationService->createLocation($membersContentInfo, $locationCreateStruct);
504
        $editorsLocation = $locationService->createLocation($editorsContentInfo, $locationCreateStruct);
505
        $adminsLocation = $locationService->createLocation(
506
            $adminsContentInfo,
507
            $locationService->newLocationCreateStruct($membersLocation->id)
508
        );
509
510
        $this->refreshSearch($repository);
511
512
        // Not found under Editors
513
        $criterion = new Criterion\ParentLocationId($editorsLocation->id);
514
        $query = new LocationQuery(array('filter' => $criterion));
515
        $result = $searchService->findLocations($query);
516
        $this->assertEquals(0, $result->totalCount);
517
518
        // Found under Members
519
        $criterion = new Criterion\ParentLocationId($membersLocation->id);
520
        $query = new LocationQuery(array('filter' => $criterion));
521
        $result = $searchService->findLocations($query);
522
        $this->assertEquals(1, $result->totalCount);
523
        $this->assertEquals(
524
            $adminsLocation->id,
525
            $result->searchHits[0]->valueObject->id
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
526
        );
527
528
        $locationService->moveSubtree($adminsLocation, $editorsLocation);
529
        $this->refreshSearch($repository);
530
531
        // Found under Editors
532
        $criterion = new Criterion\ParentLocationId($editorsLocation->id);
533
        $query = new LocationQuery(array('filter' => $criterion));
534
        $result = $searchService->findLocations($query);
535
        $this->assertEquals(1, $result->totalCount);
536
        $this->assertEquals(
537
            $adminsLocation->id,
538
            $result->searchHits[0]->valueObject->id
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
539
        );
540
541
        // Not found under Members
542
        $criterion = new Criterion\ParentLocationId($membersLocation->id);
543
        $query = new LocationQuery(array('filter' => $criterion));
544
        $result = $searchService->findLocations($query);
545
        $this->assertEquals(0, $result->totalCount);
546
    }
547
548
    /**
549
     * Testing that content is indexed even when containing only fields with values
550
     * considered to be empty by the search engine.
551
     */
552
    public function testIndexContentWithNullField()
553
    {
554
        $repository = $this->getRepository();
555
        $contentService = $repository->getContentService();
556
        $contentTypeService = $repository->getContentTypeService();
557
        $searchService = $repository->getSearchService();
558
559
        $createStruct = $contentTypeService->newContentTypeCreateStruct('test-type');
560
        $createStruct->mainLanguageCode = 'eng-GB';
561
        $createStruct->names = array('eng-GB' => 'Test type');
562
        $createStruct->creatorId = 14;
563
        $createStruct->creationDate = new DateTime();
564
565
        $translatableFieldCreate = $contentTypeService->newFieldDefinitionCreateStruct(
566
            'integer',
567
            'ezinteger'
568
        );
569
        $translatableFieldCreate->names = array('eng-GB' => 'Simple translatable integer field');
570
        $translatableFieldCreate->fieldGroup = 'main';
571
        $translatableFieldCreate->position = 1;
572
        $translatableFieldCreate->isTranslatable = true;
573
        $translatableFieldCreate->isSearchable = true;
574
575
        $createStruct->addFieldDefinition($translatableFieldCreate);
576
577
        $contentGroup = $contentTypeService->loadContentTypeGroupByIdentifier('Content');
578
        $contentTypeDraft = $contentTypeService->createContentType(
579
            $createStruct,
580
            array($contentGroup)
581
        );
582
        $contentTypeService->publishContentTypeDraft($contentTypeDraft);
583
        $contentType = $contentTypeService->loadContentType($contentTypeDraft->id);
0 ignored issues
show
Documentation introduced by
The property $id is declared protected in eZ\Publish\API\Repositor...ContentType\ContentType. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
584
585
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
586
        $createStruct->alwaysAvailable = false;
587
        $createStruct->mainLanguageCode = 'eng-GB';
588
589
        $draft = $contentService->createContent($createStruct);
590
        $content = $contentService->publishVersion($draft->getVersionInfo());
591
592
        $this->refreshSearch($repository);
593
594
        // Found
595
        $criterion = new Criterion\ContentId($content->id);
596
        $query = new Query(array('filter' => $criterion));
597
        $result = $searchService->findContent($query);
598
        $this->assertEquals(1, $result->totalCount);
599
        $this->assertEquals(
600
            $content->id,
601
            $result->searchHits[0]->valueObject->id
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
602
        );
603
    }
604
605
    /**
606
     * Test that updated Location is available for search.
607
     */
608
    public function testUpdateLocation()
609
    {
610
        $repository = $this->getRepository();
611
        $locationService = $repository->getLocationService();
612
        $searchService = $repository->getSearchService();
613
614
        $rootLocationId = 2;
615
        $locationToUpdate = $locationService->loadLocation($rootLocationId);
616
617
        $criterion = new Criterion\LogicalAnd([
618
            new Criterion\LocationId($rootLocationId),
619
            new Criterion\Location\Priority(Criterion\Operator::GT, 0),
620
        ]);
621
622
        $query = new LocationQuery(array('filter' => $criterion));
623
        $result = $searchService->findLocations($query);
624
625
        $this->assertEquals(0, $result->totalCount);
626
627
        $locationUpdateStruct = $locationService->newLocationUpdateStruct();
628
        $locationUpdateStruct->priority = 4;
629
        $locationService->updateLocation($locationToUpdate, $locationUpdateStruct);
630
631
        $this->refreshSearch($repository);
632
633
        $result = $searchService->findLocations($query);
634
635
        $this->assertEquals(1, $result->totalCount);
636
        $this->assertEquals(
637
            $locationToUpdate->id,
638
            $result->searchHits[0]->valueObject->id
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
639
        );
640
    }
641
642
    /**
643
     * Testing that content will be deleted with all of its subitems but subitems with additional location will stay as
644
     * they are.
645
     */
646
    public function testDeleteLocation()
647
    {
648
        $repository = $this->getRepository();
649
        $locationService = $repository->getLocationService();
650
651
        $treeContainerContent = $this->createContentWithName('Tree Container', [2]);
652
        $supposeBeDeletedSubItem = $this->createContentWithName(
653
            'Suppose to be deleted sub-item',
654
            [$treeContainerContent->contentInfo->mainLocationId]
655
        );
656
        $supposeSurviveSubItem = $this->createContentWithName(
657
            'Suppose to Survive Item',
658
            [2, $treeContainerContent->contentInfo->mainLocationId]
659
        );
660
661
        $treeContainerLocation = $locationService->loadLocation($treeContainerContent->contentInfo->mainLocationId);
662
663
        $this->refreshSearch($repository);
664
665
        $this->assertContentIdSearch($treeContainerContent->id, 1);
666
        $this->assertContentIdSearch($supposeSurviveSubItem->id, 1);
667
        $this->assertContentIdSearch($supposeBeDeletedSubItem->id, 1);
668
669
        $locationService->deleteLocation($treeContainerLocation);
670
671
        $this->refreshSearch($repository);
672
673
        $this->assertContentIdSearch($supposeSurviveSubItem->id, 1);
674
        $this->assertContentIdSearch($treeContainerContent->id, 0);
675
        $this->assertContentIdSearch($supposeBeDeletedSubItem->id, 0);
676
    }
677
678
    /**
679
     * Test content is available for search after being published.
680
     */
681
    public function testPublishVersion()
682
    {
683
        $repository = $this->getRepository();
684
        $searchService = $repository->getSearchService();
685
686
        $publishedContent = $this->createContentWithName('publishedContent', [2]);
687
        $this->refreshSearch($repository);
688
689
        $criterion = new Criterion\FullText('publishedContent');
690
        $query = new Query(['filter' => $criterion]);
691
        $result = $searchService->findContent($query);
692
693
        $this->assertCount(1, $result->searchHits);
694
        $this->assertEquals($publishedContent->contentInfo->id, $result->searchHits[0]->valueObject->contentInfo->id);
0 ignored issues
show
Documentation introduced by
The property contentInfo does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
695
696
        // Searching for children of locationId=2 should also hit this content
697
        $criterion = new Criterion\ParentLocationId(2);
698
        $query = new LocationQuery(array('filter' => $criterion));
699
        $result = $searchService->findLocations($query);
700
701
        foreach ($result->searchHits as $searchHit) {
702
            if ($searchHit->valueObject->contentInfo->id === $publishedContent->contentInfo->id) {
0 ignored issues
show
Documentation introduced by
The property contentInfo does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
703
                return;
704
            }
705
        }
706
        $this->fail('Parent location sub-items do not contain published content');
707
    }
708
709
    /**
710
     * Test recovered content is available for search.
711
     */
712
    public function testRecoverLocation()
713
    {
714
        $repository = $this->getRepository();
715
        $locationService = $repository->getLocationService();
716
        $trashService = $repository->getTrashService();
717
        $searchService = $repository->getSearchService();
718
719
        $publishedContent = $this->createContentWithName('recovery-test', [2]);
720
        $location = $locationService->loadLocation($publishedContent->contentInfo->mainLocationId);
721
722
        $trashService->trash($location);
723
        $this->refreshSearch($repository);
724
725
        $criterion = new Criterion\LocationId($location->id);
726
        $query = new LocationQuery(['filter' => $criterion]);
727
        $locations = $searchService->findLocations($query);
728
        $this->assertEquals(0, $locations->totalCount);
729
730
        $trashItem = $trashService->loadTrashItem($location->id);
731
        $trashService->recover($trashItem);
732
        $this->refreshSearch($repository);
733
734
        $locations = $searchService->findLocations($query);
735
        $this->assertEquals(0, $locations->totalCount);
736
        $this->assertContentIdSearch($publishedContent->contentInfo->id, 1);
737
    }
738
739
    /**
740
     * Test copied content is available for search.
741
     */
742
    public function testCopyContent()
743
    {
744
        $repository = $this->getRepository();
745
        $searchService = $repository->getSearchService();
746
        $contentService = $repository->getContentService();
747
        $locationService = $repository->getLocationService();
748
749
        $publishedContent = $this->createContentWithName('copyTest', [2]);
750
        $this->refreshSearch($repository);
751
        $criterion = new Criterion\FullText('copyTest');
752
        $query = new Query(['filter' => $criterion]);
753
        $result = $searchService->findContent($query);
754
        $this->assertCount(1, $result->searchHits);
755
756
        $copiedContent = $contentService->copyContent($publishedContent->contentInfo, $locationService->newLocationCreateStruct(2));
757
        $this->refreshSearch($repository);
758
        $result = $searchService->findContent($query);
759
        $this->assertCount(2, $result->searchHits);
760
761
        $this->assertContentIdSearch($publishedContent->contentInfo->id, 1);
762
        $this->assertContentIdSearch($copiedContent->contentInfo->id, 1);
763
    }
764
765
    /**
766
     * Test that setting object content state to locked and then unlocked does not affect search index.
767
     */
768
    public function testSetContentState()
769
    {
770
        $repository = $this->getRepository();
771
        $objectStateService = $repository->getObjectStateService();
772
773
        // get Object States
774
        $stateNotLocked = $objectStateService->loadObjectState(1);
775
        $stateLocked = $objectStateService->loadObjectState(2);
776
777
        $publishedContent = $this->createContentWithName('setContentStateTest', [2]);
778
        $objectStateService->setContentState($publishedContent->contentInfo, $stateLocked->getObjectStateGroup(), $stateLocked);
779
        $this->refreshSearch($repository);
780
781
        // Setting Content State to "locked" should not affect search index
782
        $this->assertContentIdSearch($publishedContent->contentInfo->id, 1);
783
784
        $objectStateService->setContentState($publishedContent->contentInfo, $stateNotLocked->getObjectStateGroup(), $stateNotLocked);
785
        $this->refreshSearch($repository);
786
787
        // Setting Content State back to "not locked" should not affect search index
788
        $this->assertContentIdSearch($publishedContent->contentInfo->id, 1);
789
    }
790
791
    /**
792
     * Check if FullText indexing works for special cases of text.
793
     *
794
     * @param string $text Content Item field value text (to be indexed)
795
     * @param string $searchForText text based on which Content Item should be found
796
     * @param array $ignoreForSetupFactories list of SetupFactories to be ignored
797
     * @dataProvider getSpecialFullTextCases
798
     */
799
    public function testIndexingSpecialFullTextCases($text, $searchForText, array $ignoreForSetupFactories = [])
800
    {
801
        // check if provided data should be ignored for the current Search Engine (via SetupFactory)
802
        if (!empty($ignoreForSetupFactories) && in_array(get_class($this->getSetupFactory()), $ignoreForSetupFactories)) {
803
            $this->markTestIncomplete(sprintf(
804
                'Handling FullText Searching for the phrase {%s} is incomplete for %s',
805
                $searchForText,
806
                get_class($this->getSetupFactory())
807
            ));
808
        }
809
810
        $repository = $this->getRepository();
811
        $searchService = $repository->getSearchService();
812
813
        $content = $this->createContentWithName($text, [2]);
814
        $this->refreshSearch($repository);
815
816
        $criterion = new Criterion\FullText($searchForText);
817
        $query = new Query(['filter' => $criterion]);
818
        $result = $searchService->findContent($query);
819
820
        // for some cases there might be more than one hit, so check if proper one was found
821
        foreach ($result->searchHits as $searchHit) {
822
            if ($content->contentInfo->id === $searchHit->valueObject->versionInfo->contentInfo->id) {
0 ignored issues
show
Documentation introduced by
The property versionInfo does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
823
                return;
824
            }
825
        }
826
        $this->fail('Failed to find required Content in search results');
827
    }
828
829
    /**
830
     * Data Provider for {@see testIndexingSpecialFullTextCases()} method.
831
     *
832
     * @return array
833
     */
834
    public function getSpecialFullTextCases()
835
    {
836
        return [
837
            ['UPPERCASE TEXT', 'uppercase text'],
838
            ['lowercase text', 'LOWERCASE TEXT'],
839
            ['text-with-hyphens', 'text-with-hyphens'],
840
            ['text containing spaces', 'text containing spaces'],
841
            ['"quoted text"', 'quoted text'],
842
            ['ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝ', 'àáâãäåçèéêëìíîïðñòóôõöøùúûüý'],
843
            ['with boundary.', 'with boundary'],
844
            ['Folder1.', 'Folder1.'],
845
            ['whitespaces', "     whitespaces  \n \t "],
846
            // @todo: Remove as soon as elastic is updated to later version not affected
847
            ["it's", "it's", [LegacyElasticsearch::class]],
848
            ['with_underscore', 'with_underscore'],
849
        ];
850
    }
851
852
    /**
853
     * Test updating Content field value with empty value removes it from search index.
854
     */
855
    public function testRemovedContentFieldValueIsNotFound()
856
    {
857
        $repository = $this->getRepository();
858
        $contentService = $repository->getContentService();
859
        $searchService = $repository->getSearchService();
860
        $publishedContent = $this->createContentWithNameAndDescription('testRemovedContentFieldValueIsNotFound', 'descriptionToBeRemoved', [2]);
861
        $this->refreshSearch($repository);
862
863
        $contentDraft = $contentService->createContentDraft($publishedContent->contentInfo);
864
        $contentUpdateStruct = $contentService->newContentUpdateStruct();
865
        $contentUpdateStruct->setField('description', null);
866
        $contentDraft = $contentService->updateContent($contentDraft->versionInfo, $contentUpdateStruct);
867
        $contentService->publishVersion($contentDraft->versionInfo);
868
        $this->refreshSearch($repository);
869
870
        // Removed field value should not be found
871
        $criterion = new Criterion\FullText('descriptionToBeRemoved');
872
        $query = new Query(['filter' => $criterion]);
873
        $results = $searchService->findContent($query);
874
        $this->assertEquals(0, $results->totalCount);
875
876
        // Should be found
877
        $criterion = new Criterion\FullText('testRemovedContentFieldValueIsNotFound');
878
        $query = new Query(['filter' => $criterion]);
879
        $results = $searchService->findContent($query);
880
        $this->assertEquals(1, $results->totalCount);
881
    }
882
883
    /**
884
     * Check if children locations are/are not ivisible.
885
     *
886
     * @param \eZ\Publish\API\Repository\SearchService $searchService
887
     * @param int $parentLocationId parent location Id
888
     * @param bool $expected expected value of {invisible} property in subtree
889
     */
890
    private function assertSubtreeInvisibleProperty(SearchService $searchService, $parentLocationId, $expected)
891
    {
892
        $criterion = new Criterion\ParentLocationId($parentLocationId);
893
        $query = new LocationQuery(array('filter' => $criterion));
894
        $result = $searchService->findLocations($query);
895
        foreach ($result->searchHits as $searchHit) {
896
            $this->assertEquals($expected, $searchHit->valueObject->invisible, sprintf('Location %s is not hidden', $searchHit->valueObject->id));
0 ignored issues
show
Documentation introduced by
The property invisible does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
Documentation introduced by
The property id does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
897
            // Perform recursive check for children locations
898
            $this->assertSubtreeInvisibleProperty($searchService, $searchHit->valueObject->id, $expected);
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
899
        }
900
    }
901
902
    /**
903
     * Test that swapping locations affects properly Search Engine Index.
904
     */
905
    public function testSwapLocation()
906
    {
907
        $repository = $this->getRepository();
908
        $locationService = $repository->getLocationService();
909
        $searchService = $repository->getSearchService();
910
911
        $content01 = $this->createContentWithName('content01', [2]);
912
        $location01 = $locationService->loadLocation($content01->contentInfo->mainLocationId);
913
914
        $content02 = $this->createContentWithName('content02', [2]);
915
        $location02 = $locationService->loadLocation($content02->contentInfo->mainLocationId);
916
917
        $locationService->swapLocation($location01, $location02);
918
        $this->refreshSearch($repository);
919
920
        // content02 should be at location01
921
        $criterion = new Criterion\LocationId($location01->id);
922
        $query = new Query(['filter' => $criterion]);
923
        $results = $searchService->findContent($query);
924
        $this->assertEquals(1, $results->totalCount);
925
        $this->assertEquals($content02->id, $results->searchHits[0]->valueObject->id);
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
926
927
        // content01 should be at location02
928
        $criterion = new Criterion\LocationId($location02->id);
929
        $query = new Query(['filter' => $criterion]);
930
        $results = $searchService->findContent($query);
931
        $this->assertEquals(1, $results->totalCount);
932
        $this->assertEquals($content01->id, $results->searchHits[0]->valueObject->id);
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
933
    }
934
935
    /**
936
     * Test that updating Content metadata affects properly Search Engine Index.
937
     */
938
    public function testUpdateContentMetadata()
939
    {
940
        $repository = $this->getRepository();
941
        $contentService = $repository->getContentService();
942
        $locationService = $repository->getLocationService();
943
        $searchService = $repository->getSearchService();
944
945
        $publishedContent = $this->createContentWithName('updateMetadataTest', [2]);
946
        $originalMainLocationId = $publishedContent->contentInfo->mainLocationId;
947
        $newLocationCreateStruct = $locationService->newLocationCreateStruct(60);
948
        $newLocation = $locationService->createLocation($publishedContent->contentInfo, $newLocationCreateStruct);
949
950
        $newContentMetadataUpdateStruct = $contentService->newContentMetadataUpdateStruct();
951
        $newContentMetadataUpdateStruct->remoteId = md5('Test');
952
        $newContentMetadataUpdateStruct->publishedDate = new \DateTime();
953
        $newContentMetadataUpdateStruct->publishedDate->add(new \DateInterval('P1D'));
954
        $newContentMetadataUpdateStruct->mainLocationId = $newLocation->id;
955
956
        $contentService->updateContentMetadata($publishedContent->contentInfo, $newContentMetadataUpdateStruct);
957
        $this->refreshSearch($repository);
958
959
        // find Content by Id, calling findContentInfo which is using the Search Index
960
        $criterion = new Criterion\ContentId($publishedContent->id);
961
        $query = new Query(['filter' => $criterion]);
962
        $results = $searchService->findContentInfo($query);
963
        $this->assertEquals(1, $results->totalCount);
964
        $this->assertEquals($publishedContent->contentInfo->id, $results->searchHits[0]->valueObject->id);
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
965
966
        // find Content using updated RemoteId
967
        $criterion = new Criterion\RemoteId($newContentMetadataUpdateStruct->remoteId);
968
        $query = new Query(['filter' => $criterion]);
969
        $results = $searchService->findContent($query);
970
        $this->assertEquals(1, $results->totalCount);
971
        $foundContentInfo = $results->searchHits[0]->valueObject->contentInfo;
0 ignored issues
show
Documentation introduced by
The property contentInfo does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __set, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
972
        /** @var \eZ\Publish\Core\Repository\Values\Content\Content $foundContentInfo */
973
        $this->assertEquals($publishedContent->id, $foundContentInfo->id);
974
        $this->assertEquals($newContentMetadataUpdateStruct->publishedDate, $foundContentInfo->publishedDate);
0 ignored issues
show
Documentation introduced by
The property publishedDate does not exist on object<eZ\Publish\Core\R...Values\Content\Content>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
975
        $this->assertEquals($newLocation->id, $foundContentInfo->mainLocationId);
0 ignored issues
show
Documentation introduced by
The property mainLocationId does not exist on object<eZ\Publish\Core\R...Values\Content\Content>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
976
        $this->assertEquals($newContentMetadataUpdateStruct->remoteId, $foundContentInfo->remoteId);
0 ignored issues
show
Documentation introduced by
The property remoteId does not exist on object<eZ\Publish\Core\R...Values\Content\Content>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
977
978
        // find Content using old main location
979
        $criterion = new Criterion\LocationId($originalMainLocationId);
980
        $query = new LocationQuery(['filter' => $criterion]);
981
        $results = $searchService->findLocations($query);
982
        $this->assertEquals(1, $results->totalCount);
983
        $this->assertEquals($newContentMetadataUpdateStruct->remoteId, $results->searchHits[0]->valueObject->contentInfo->remoteId);
0 ignored issues
show
Documentation introduced by
The property contentInfo does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
984
    }
985
986
    /**
987
     * Test that updating Content Draft metadata does not affect Search Engine Index.
988
     */
989
    public function testUpdateContentDraftMetadataIsNotIndexed()
990
    {
991
        $repository = $this->getRepository();
992
        $contentService = $repository->getContentService();
993
        $locationService = $repository->getLocationService();
994
995
        $testableContentType = $this->createTestContentType();
996
        $rootContentStruct = $contentService->newContentCreateStruct($testableContentType, 'eng-GB');
997
        $rootContentStruct->setField('name', 'TestUpdatingContentDraftMetadata');
998
999
        $contentDraft = $contentService->createContent($rootContentStruct, [$locationService->newLocationCreateStruct(2)]);
1000
1001
        $newContentMetadataUpdateStruct = $contentService->newContentMetadataUpdateStruct();
1002
        $newContentMetadataUpdateStruct->ownerId = 10;
1003
        $newContentMetadataUpdateStruct->remoteId = md5('Test');
1004
1005
        $contentService->updateContentMetadata($contentDraft->contentInfo, $newContentMetadataUpdateStruct);
1006
1007
        $this->refreshSearch($repository);
1008
        $this->assertContentIdSearch($contentDraft->contentInfo->id, 0);
1009
    }
1010
1011
    /**
1012
     * Test that assigning section to content object properly affects Search Engine Index.
1013
     */
1014
    public function testAssignSection()
1015
    {
1016
        $repository = $this->getRepository();
1017
        $sectionService = $repository->getSectionService();
1018
        $searchService = $repository->getSearchService();
1019
1020
        $section = $sectionService->loadSection(2);
1021
        $content = $this->createContentWithName('testAssignSection', [2]);
1022
1023
        $sectionService->assignSection($content->contentInfo, $section);
1024
        $this->refreshSearch($repository);
1025
1026
        $criterion = new Criterion\ContentId($content->id);
1027
        $query = new Query(['filter' => $criterion]);
1028
        $results = $searchService->findContentInfo($query);
1029
        $this->assertEquals($section->id, $results->searchHits[0]->valueObject->sectionId);
0 ignored issues
show
Documentation introduced by
The property sectionId does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
1030
    }
1031
1032
    /**
1033
     * Will create if not exists a simple content type for test purposes with just one required field name.
1034
     *
1035
     * @return \eZ\Publish\API\Repository\Values\ContentType\ContentType
1036
     */
1037
    protected function createTestContentType()
1038
    {
1039
        $repository = $this->getRepository();
1040
        $contentTypeService = $repository->getContentTypeService();
1041
        $contentTypeIdentifier = 'test-type';
1042
        try {
1043
            return $contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier);
1044
        } catch (NotFoundException $e) {
1045
            // continue creation process
1046
        }
1047
1048
        $nameField = $contentTypeService->newFieldDefinitionCreateStruct('name', 'ezstring');
1049
        $nameField->fieldGroup = 'main';
1050
        $nameField->position = 1;
1051
        $nameField->isTranslatable = true;
1052
        $nameField->isSearchable = true;
1053
        $nameField->isRequired = true;
1054
1055
        $contentTypeStruct = $contentTypeService->newContentTypeCreateStruct($contentTypeIdentifier);
1056
        $contentTypeStruct->mainLanguageCode = 'eng-GB';
1057
        $contentTypeStruct->creatorId = 14;
1058
        $contentTypeStruct->creationDate = new DateTime();
1059
        $contentTypeStruct->names = ['eng-GB' => 'Test Content Type'];
1060
        $contentTypeStruct->addFieldDefinition($nameField);
1061
1062
        $contentTypeGroup = $contentTypeService->loadContentTypeGroupByIdentifier('Content');
1063
1064
        $contentTypeDraft = $contentTypeService->createContentType($contentTypeStruct, [$contentTypeGroup]);
1065
        $contentTypeService->publishContentTypeDraft($contentTypeDraft);
1066
1067
        return $contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier);
1068
    }
1069
1070
    /**
1071
     * Will create and publish an content with a filed with a given content name in location provided into
1072
     * $parentLocationIdList.
1073
     *
1074
     * @param string $contentName
1075
     * @param array $parentLocationIdList
1076
     *
1077
     * @return \eZ\Publish\API\Repository\Values\Content\Content
1078
     */
1079
    protected function createContentWithName($contentName, array $parentLocationIdList = array())
1080
    {
1081
        $contentService = $this->getRepository()->getContentService();
1082
        $locationService = $this->getRepository()->getLocationService();
1083
1084
        $testableContentType = $this->createTestContentType();
1085
1086
        $rootContentStruct = $contentService->newContentCreateStruct($testableContentType, 'eng-GB');
1087
        $rootContentStruct->setField('name', $contentName);
1088
1089
        $parentLocationList = [];
1090
        foreach ($parentLocationIdList as $locationID) {
1091
            $parentLocationList[] = $locationService->newLocationCreateStruct($locationID);
1092
        }
1093
1094
        $contentDraft = $contentService->createContent($rootContentStruct, $parentLocationList);
1095
        $publishedContent = $contentService->publishVersion($contentDraft->getVersionInfo());
1096
1097
        return $publishedContent;
1098
    }
1099
1100
    /**
1101
     * Create and publish a content with filled name and description fields in location provided into
1102
     * $parentLocationIdList.
1103
     *
1104
     * @param string $contentName
1105
     * @param $contentDescription
1106
     * @param array $parentLocationIdList
1107
     *
1108
     * @return \eZ\Publish\API\Repository\Values\Content\Content
1109
     */
1110
    protected function createContentWithNameAndDescription($contentName, $contentDescription, array $parentLocationIdList = [])
1111
    {
1112
        $repository = $this->getRepository();
1113
        $contentService = $repository->getContentService();
1114
        $contentTypeService = $repository->getContentTypeService();
1115
        $publishedContent = $this->createContentWithName($contentName, $parentLocationIdList);
1116
        $descriptionField = $contentTypeService->newFieldDefinitionCreateStruct('description', 'ezstring');
1117
        $descriptionField->fieldGroup = 'main';
1118
        $descriptionField->position = 2;
1119
        $descriptionField->isTranslatable = true;
1120
        $descriptionField->isSearchable = true;
1121
        $descriptionField->isRequired = false;
1122
        $contentType = $contentTypeService->loadContentType($publishedContent->contentInfo->contentTypeId);
1123
        $contentTypeDraft = $contentTypeService->createContentTypeDraft($contentType);
1124
        $contentTypeService->addFieldDefinition($contentTypeDraft, $descriptionField);
1125
        $contentTypeService->publishContentTypeDraft($contentTypeDraft);
1126
        $contentDraft = $contentService->createContentDraft($publishedContent->contentInfo);
1127
        $contentUpdateStruct = $contentService->newContentUpdateStruct();
1128
        $contentUpdateStruct->setField('description', $contentDescription);
1129
        $contentDraft = $contentService->updateContent($contentDraft->versionInfo, $contentUpdateStruct);
1130
1131
        return $contentService->publishVersion($contentDraft->versionInfo);
1132
    }
1133
1134
    /**
1135
     * Asserts an content id if it exists still in the solr core.
1136
     *
1137
     * @param int $contentId
1138
     * @param int $expectedCount
1139
     */
1140
    protected function assertContentIdSearch($contentId, $expectedCount)
1141
    {
1142
        $searchService = $this->getRepository()->getSearchService();
1143
1144
        $criterion = new Criterion\ContentId($contentId);
1145
        $query = new Query(array('filter' => $criterion));
1146
        $result = $searchService->findContent($query);
1147
1148
        $this->assertEquals($expectedCount, $result->totalCount);
1149
        if ($expectedCount == 0) {
1150
            return;
1151
        }
1152
1153
        $this->assertEquals(
1154
            $contentId,
1155
            $result->searchHits[0]->valueObject->id
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
1156
        );
1157
    }
1158
1159
    /**
1160
     * Create & get new Location for tests.
1161
     *
1162
     * @return \eZ\Publish\API\Repository\Values\Content\Location
1163
     */
1164
    protected function createNewTestLocation()
1165
    {
1166
        $repository = $this->getRepository();
1167
        $locationService = $repository->getLocationService();
1168
        $contentService = $repository->getContentService();
1169
1170
        $rootLocationId = 2;
1171
        $membersContentId = 11;
1172
        $membersContentInfo = $contentService->loadContentInfo($membersContentId);
1173
1174
        $locationCreateStruct = $locationService->newLocationCreateStruct($rootLocationId);
1175
1176
        return $locationService->createLocation($membersContentInfo, $locationCreateStruct);
1177
    }
1178
}
1179