Completed
Push — test-EZP-26707-issearchable-fu... ( 51e186...7579e0 )
by
unknown
16:56
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
    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
     * Test that a newly created user is available for search.
248
     */
249
    public function testCreateUser()
250
    {
251
        $repository = $this->getRepository();
252
        $userService = $repository->getUserService();
253
        $searchService = $repository->getSearchService();
254
255
        // ID of the "Editors" user group
256
        $editorsGroupId = 13;
257
        $userCreate = $userService->newUserCreateStruct(
258
            'user',
259
            '[email protected]',
260
            'secret',
261
            'eng-US'
262
        );
263
        $userCreate->enabled = true;
264
        $userCreate->setField('first_name', 'Example');
265
        $userCreate->setField('last_name', 'User');
266
267
        // Load parent group for the user
268
        $group = $userService->loadUserGroup($editorsGroupId);
269
270
        // Create a new user instance.
271
        $user = $userService->createUser($userCreate, array($group));
272
273
        $this->refreshSearch($repository);
274
275
        // Should be found
276
        $criterion = new Criterion\ContentId($user->id);
277
        $query = new Query(array('filter' => $criterion));
278
        $result = $searchService->findContentInfo($query);
279
        $this->assertEquals(1, $result->totalCount);
280
    }
281
282
    /**
283
     * Test that a newly created user group is available for search.
284
     */
285
    public function testCreateUserGroup()
286
    {
287
        $repository = $this->getRepository();
288
        $userService = $repository->getUserService();
289
        $searchService = $repository->getSearchService();
290
        $mainGroupId = $this->generateId('group', 4);
291
292
        $parentUserGroup = $userService->loadUserGroup($mainGroupId);
293
        $userGroupCreateStruct = $userService->newUserGroupCreateStruct('eng-GB');
294
        $userGroupCreateStruct->setField('name', 'Example Group');
295
296
        // Create a new user group
297
        $userGroup = $userService->createUserGroup(
298
            $userGroupCreateStruct,
299
            $parentUserGroup
300
        );
301
302
        $this->refreshSearch($repository);
303
304
        // Should be found
305
        $criterion = new Criterion\ContentId($userGroup->id);
306
        $query = new Query(array('filter' => $criterion));
307
        $result = $searchService->findContentInfo($query);
308
        $this->assertEquals(1, $result->totalCount);
309
    }
310
311
    /**
312
     * Test that a newly created Location is available for search.
313
     */
314
    public function testCreateLocation()
315
    {
316
        $repository = $this->getRepository();
317
        $searchService = $repository->getSearchService();
318
        $membersLocation = $this->createNewTestLocation();
319
320
        $this->refreshSearch($repository);
321
322
        // Found
323
        $criterion = new Criterion\LocationId($membersLocation->id);
324
        $query = new LocationQuery(array('filter' => $criterion));
325
        $result = $searchService->findLocations($query);
326
        $this->assertEquals(1, $result->totalCount);
327
        $this->assertEquals(
328
            $membersLocation->id,
329
            $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...
330
        );
331
    }
332
333
    /**
334
     * Test that hiding a Location makes it unavailable for search.
335
     */
336
    public function testHideSubtree()
337
    {
338
        $repository = $this->getRepository();
339
        $searchService = $repository->getSearchService();
340
341
        // 5 is the ID of an existing location
342
        $locationId = $this->generateId('location', 5);
343
        $locationService = $repository->getLocationService();
344
        $location = $locationService->loadLocation($locationId);
345
        $locationService->hideLocation($location);
346
        $this->refreshSearch($repository);
347
348
        // Check if parent location is hidden
349
        $criterion = new Criterion\LocationId($locationId);
350
        $query = new LocationQuery(array('filter' => $criterion));
351
        $result = $searchService->findLocations($query);
352
        $this->assertEquals(1, $result->totalCount);
353
        $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...
354
355
        // Check if children locations are invisible
356
        $this->assertSubtreeInvisibleProperty($searchService, $locationId, true);
357
    }
358
359
    /**
360
     * Test that hiding and revealing a Location makes it available for search.
361
     */
362
    public function testRevealSubtree()
363
    {
364
        $repository = $this->getRepository();
365
        $searchService = $repository->getSearchService();
366
367
        // 5 is the ID of an existing location
368
        $locationId = $this->generateId('location', 5);
369
        $locationService = $repository->getLocationService();
370
        $location = $locationService->loadLocation($locationId);
371
        $locationService->hideLocation($location);
372
        $this->refreshSearch($repository);
373
        $locationService->unhideLocation($location);
374
        $this->refreshSearch($repository);
375
376
        // Check if parent location is not hidden
377
        $criterion = new Criterion\LocationId($locationId);
378
        $query = new LocationQuery(array('filter' => $criterion));
379
        $result = $searchService->findLocations($query);
380
        $this->assertEquals(1, $result->totalCount);
381
        $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...
382
383
        // Check if children locations are not invisible
384
        $this->assertSubtreeInvisibleProperty($searchService, $locationId, false);
385
    }
386
387
    /**
388
     * Test that a copied subtree is available for search.
389
     */
390
    public function testCopySubtree()
391
    {
392
        $repository = $this->getRepository();
393
        $locationService = $repository->getLocationService();
394
        $contentService = $repository->getContentService();
395
        $searchService = $repository->getSearchService();
396
397
        $rootLocationId = 2;
398
        $membersContentId = 11;
399
        $adminsContentId = 12;
400
        $editorsContentId = 13;
401
        $membersContentInfo = $contentService->loadContentInfo($membersContentId);
402
        $adminsContentInfo = $contentService->loadContentInfo($adminsContentId);
403
        $editorsContentInfo = $contentService->loadContentInfo($editorsContentId);
404
405
        $locationCreateStruct = $locationService->newLocationCreateStruct($rootLocationId);
406
        $membersLocation = $locationService->createLocation($membersContentInfo, $locationCreateStruct);
407
        $editorsLocation = $locationService->createLocation($editorsContentInfo, $locationCreateStruct);
408
        $adminsLocation = $locationService->createLocation(
409
            $adminsContentInfo,
410
            $locationService->newLocationCreateStruct($membersLocation->id)
411
        );
412
413
        $copiedLocation = $locationService->copySubtree($adminsLocation, $editorsLocation);
414
        $this->refreshSearch($repository);
415
416
        // Found under Members
417
        $criterion = new Criterion\ParentLocationId($membersLocation->id);
418
        $query = new LocationQuery(array('filter' => $criterion));
419
        $result = $searchService->findLocations($query);
420
        $this->assertEquals(1, $result->totalCount);
421
        $this->assertEquals(
422
            $adminsLocation->id,
423
            $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...
424
        );
425
426
        // Found under Editors
427
        $criterion = new Criterion\ParentLocationId($editorsLocation->id);
428
        $query = new LocationQuery(array('filter' => $criterion));
429
        $result = $searchService->findLocations($query);
430
        $this->assertEquals(1, $result->totalCount);
431
        $this->assertEquals(
432
            $copiedLocation->id,
433
            $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...
434
        );
435
    }
436
437
    /**
438
     * Test that moved subtree is available for search and found only under a specific parent Location.
439
     */
440
    public function testMoveSubtree()
441
    {
442
        $repository = $this->getRepository();
443
        $locationService = $repository->getLocationService();
444
        $contentService = $repository->getContentService();
445
        $searchService = $repository->getSearchService();
446
447
        $rootLocationId = 2;
448
        $membersContentId = 11;
449
        $adminsContentId = 12;
450
        $editorsContentId = 13;
451
        $membersContentInfo = $contentService->loadContentInfo($membersContentId);
452
        $adminsContentInfo = $contentService->loadContentInfo($adminsContentId);
453
        $editorsContentInfo = $contentService->loadContentInfo($editorsContentId);
454
455
        $locationCreateStruct = $locationService->newLocationCreateStruct($rootLocationId);
456
        $membersLocation = $locationService->createLocation($membersContentInfo, $locationCreateStruct);
457
        $editorsLocation = $locationService->createLocation($editorsContentInfo, $locationCreateStruct);
458
        $adminsLocation = $locationService->createLocation(
459
            $adminsContentInfo,
460
            $locationService->newLocationCreateStruct($membersLocation->id)
461
        );
462
463
        $this->refreshSearch($repository);
464
465
        // Not found under Editors
466
        $criterion = new Criterion\ParentLocationId($editorsLocation->id);
467
        $query = new LocationQuery(array('filter' => $criterion));
468
        $result = $searchService->findLocations($query);
469
        $this->assertEquals(0, $result->totalCount);
470
471
        // Found under Members
472
        $criterion = new Criterion\ParentLocationId($membersLocation->id);
473
        $query = new LocationQuery(array('filter' => $criterion));
474
        $result = $searchService->findLocations($query);
475
        $this->assertEquals(1, $result->totalCount);
476
        $this->assertEquals(
477
            $adminsLocation->id,
478
            $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...
479
        );
480
481
        $locationService->moveSubtree($adminsLocation, $editorsLocation);
482
        $this->refreshSearch($repository);
483
484
        // Found under Editors
485
        $criterion = new Criterion\ParentLocationId($editorsLocation->id);
486
        $query = new LocationQuery(array('filter' => $criterion));
487
        $result = $searchService->findLocations($query);
488
        $this->assertEquals(1, $result->totalCount);
489
        $this->assertEquals(
490
            $adminsLocation->id,
491
            $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...
492
        );
493
494
        // Not found under Members
495
        $criterion = new Criterion\ParentLocationId($membersLocation->id);
496
        $query = new LocationQuery(array('filter' => $criterion));
497
        $result = $searchService->findLocations($query);
498
        $this->assertEquals(0, $result->totalCount);
499
    }
500
501
    /**
502
     * Testing that content is indexed even when containing only fields with values
503
     * considered to be empty by the search engine.
504
     */
505
    public function testIndexContentWithNullField()
506
    {
507
        $repository = $this->getRepository();
508
        $contentService = $repository->getContentService();
509
        $contentTypeService = $repository->getContentTypeService();
510
        $searchService = $repository->getSearchService();
511
512
        $createStruct = $contentTypeService->newContentTypeCreateStruct('test-type');
513
        $createStruct->mainLanguageCode = 'eng-GB';
514
        $createStruct->names = array('eng-GB' => 'Test type');
515
        $createStruct->creatorId = 14;
516
        $createStruct->creationDate = new DateTime();
517
518
        $translatableFieldCreate = $contentTypeService->newFieldDefinitionCreateStruct(
519
            'integer',
520
            'ezinteger'
521
        );
522
        $translatableFieldCreate->names = array('eng-GB' => 'Simple translatable integer field');
523
        $translatableFieldCreate->fieldGroup = 'main';
524
        $translatableFieldCreate->position = 1;
525
        $translatableFieldCreate->isTranslatable = true;
526
        $translatableFieldCreate->isSearchable = true;
527
528
        $createStruct->addFieldDefinition($translatableFieldCreate);
529
530
        $contentGroup = $contentTypeService->loadContentTypeGroupByIdentifier('Content');
531
        $contentTypeDraft = $contentTypeService->createContentType(
532
            $createStruct,
533
            array($contentGroup)
534
        );
535
        $contentTypeService->publishContentTypeDraft($contentTypeDraft);
536
        $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...
537
538
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
539
        $createStruct->alwaysAvailable = false;
540
        $createStruct->mainLanguageCode = 'eng-GB';
541
542
        $draft = $contentService->createContent($createStruct);
543
        $content = $contentService->publishVersion($draft->getVersionInfo());
544
545
        $this->refreshSearch($repository);
546
547
        // Found
548
        $criterion = new Criterion\ContentId($content->id);
549
        $query = new Query(array('filter' => $criterion));
550
        $result = $searchService->findContent($query);
551
        $this->assertEquals(1, $result->totalCount);
552
        $this->assertEquals(
553
            $content->id,
554
            $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...
555
        );
556
    }
557
558
    /**
559
     * Test that updated Location is available for search.
560
     */
561
    public function testUpdateLocation()
562
    {
563
        $repository = $this->getRepository();
564
        $locationService = $repository->getLocationService();
565
        $searchService = $repository->getSearchService();
566
567
        $rootLocationId = 2;
568
        $locationToUpdate = $locationService->loadLocation($rootLocationId);
569
570
        $criterion = new Criterion\LogicalAnd([
571
            new Criterion\LocationId($rootLocationId),
572
            new Criterion\Location\Priority(Criterion\Operator::GT, 0),
573
        ]);
574
575
        $query = new LocationQuery(array('filter' => $criterion));
576
        $result = $searchService->findLocations($query);
577
578
        $this->assertEquals(0, $result->totalCount);
579
580
        $locationUpdateStruct = $locationService->newLocationUpdateStruct();
581
        $locationUpdateStruct->priority = 4;
582
        $locationService->updateLocation($locationToUpdate, $locationUpdateStruct);
583
584
        $this->refreshSearch($repository);
585
586
        $result = $searchService->findLocations($query);
587
588
        $this->assertEquals(1, $result->totalCount);
589
        $this->assertEquals(
590
            $locationToUpdate->id,
591
            $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...
592
        );
593
    }
594
595
    /**
596
     * Testing that content will be deleted with all of its subitems but subitems with additional location will stay as
597
     * they are.
598
     */
599
    public function testDeleteLocation()
600
    {
601
        $repository = $this->getRepository();
602
        $locationService = $repository->getLocationService();
603
604
        $treeContainerContent = $this->createContentWithName('Tree Container', [2]);
605
        $supposeBeDeletedSubItem = $this->createContentWithName(
606
            'Suppose to be deleted sub-item',
607
            [$treeContainerContent->contentInfo->mainLocationId]
608
        );
609
        $supposeSurviveSubItem = $this->createContentWithName(
610
            'Suppose to Survive Item',
611
            [2, $treeContainerContent->contentInfo->mainLocationId]
612
        );
613
614
        $treeContainerLocation = $locationService->loadLocation($treeContainerContent->contentInfo->mainLocationId);
615
616
        $this->refreshSearch($repository);
617
618
        $this->assertContentIdSearch($treeContainerContent->id, 1);
619
        $this->assertContentIdSearch($supposeSurviveSubItem->id, 1);
620
        $this->assertContentIdSearch($supposeBeDeletedSubItem->id, 1);
621
622
        $locationService->deleteLocation($treeContainerLocation);
623
624
        $this->refreshSearch($repository);
625
626
        $this->assertContentIdSearch($supposeSurviveSubItem->id, 1);
627
        $this->assertContentIdSearch($treeContainerContent->id, 0);
628
        $this->assertContentIdSearch($supposeBeDeletedSubItem->id, 0);
629
    }
630
631
    /**
632
     * Test content is available for search after being published.
633
     */
634
    public function testPublishVersion()
635
    {
636
        $repository = $this->getRepository();
637
        $searchService = $repository->getSearchService();
638
639
        $publishedContent = $this->createContentWithName('publishedContent', [2]);
640
        $this->refreshSearch($repository);
641
642
        $criterion = new Criterion\FullText('publishedContent');
643
        $query = new Query(['filter' => $criterion]);
644
        $result = $searchService->findContent($query);
645
646
        $this->assertCount(1, $result->searchHits);
647
        $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...
648
649
        // Searching for children of locationId=2 should also hit this content
650
        $criterion = new Criterion\ParentLocationId(2);
651
        $query = new LocationQuery(array('filter' => $criterion));
652
        $result = $searchService->findLocations($query);
653
654
        foreach ($result->searchHits as $searchHit) {
655
            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...
656
                return;
657
            }
658
        }
659
        $this->fail('Parent location sub-items do not contain published content');
660
    }
661
662
    /**
663
     * Test recovered content is available for search.
664
     */
665
    public function testRecoverLocation()
666
    {
667
        $repository = $this->getRepository();
668
        $locationService = $repository->getLocationService();
669
        $trashService = $repository->getTrashService();
670
        $searchService = $repository->getSearchService();
671
672
        $publishedContent = $this->createContentWithName('recovery-test', [2]);
673
        $location = $locationService->loadLocation($publishedContent->contentInfo->mainLocationId);
674
675
        $trashService->trash($location);
676
        $this->refreshSearch($repository);
677
678
        $criterion = new Criterion\LocationId($location->id);
679
        $query = new LocationQuery(['filter' => $criterion]);
680
        $locations = $searchService->findLocations($query);
681
        $this->assertEquals(0, $locations->totalCount);
682
683
        $trashItem = $trashService->loadTrashItem($location->id);
684
        $trashService->recover($trashItem);
685
        $this->refreshSearch($repository);
686
687
        $locations = $searchService->findLocations($query);
688
        $this->assertEquals(0, $locations->totalCount);
689
        $this->assertContentIdSearch($publishedContent->contentInfo->id, 1);
690
    }
691
692
    /**
693
     * Test copied content is available for search.
694
     */
695
    public function testCopyContent()
696
    {
697
        $repository = $this->getRepository();
698
        $searchService = $repository->getSearchService();
699
        $contentService = $repository->getContentService();
700
        $locationService = $repository->getLocationService();
701
702
        $publishedContent = $this->createContentWithName('copyTest', [2]);
703
        $this->refreshSearch($repository);
704
        $criterion = new Criterion\FullText('copyTest');
705
        $query = new Query(['filter' => $criterion]);
706
        $result = $searchService->findContent($query);
707
        $this->assertCount(1, $result->searchHits);
708
709
        $copiedContent = $contentService->copyContent($publishedContent->contentInfo, $locationService->newLocationCreateStruct(2));
710
        $this->refreshSearch($repository);
711
        $result = $searchService->findContent($query);
712
        $this->assertCount(2, $result->searchHits);
713
714
        $this->assertContentIdSearch($publishedContent->contentInfo->id, 1);
715
        $this->assertContentIdSearch($copiedContent->contentInfo->id, 1);
716
    }
717
718
    /**
719
     * Test that setting object content state to locked and then unlocked does not affect search index.
720
     */
721
    public function testSetContentState()
722
    {
723
        $repository = $this->getRepository();
724
        $objectStateService = $repository->getObjectStateService();
725
726
        // get Object States
727
        $stateNotLocked = $objectStateService->loadObjectState(1);
728
        $stateLocked = $objectStateService->loadObjectState(2);
729
730
        $publishedContent = $this->createContentWithName('setContentStateTest', [2]);
731
        $objectStateService->setContentState($publishedContent->contentInfo, $stateLocked->getObjectStateGroup(), $stateLocked);
732
        $this->refreshSearch($repository);
733
734
        // Setting Content State to "locked" should not affect search index
735
        $this->assertContentIdSearch($publishedContent->contentInfo->id, 1);
736
737
        $objectStateService->setContentState($publishedContent->contentInfo, $stateNotLocked->getObjectStateGroup(), $stateNotLocked);
738
        $this->refreshSearch($repository);
739
740
        // Setting Content State back to "not locked" should not affect search index
741
        $this->assertContentIdSearch($publishedContent->contentInfo->id, 1);
742
    }
743
744
    /**
745
     * Check if FullText indexing works for special cases of text.
746
     *
747
     * @param string $text Content Item field value text (to be indexed)
748
     * @param string $searchForText text based on which Content Item should be found
749
     * @param array $ignoreForSetupFactories list of SetupFactories to be ignored
750
     * @dataProvider getSpecialFullTextCases
751
     */
752
    public function testIndexingSpecialFullTextCases($text, $searchForText, array $ignoreForSetupFactories = [])
753
    {
754
        // check if provided data should be ignored for the current Search Engine (via SetupFactory)
755
        if (!empty($ignoreForSetupFactories) && in_array(get_class($this->getSetupFactory()), $ignoreForSetupFactories)) {
756
            $this->markTestIncomplete(sprintf(
757
                'Handling FullText Searching for the phrase {%s} is incomplete for %s',
758
                $searchForText,
759
                get_class($this->getSetupFactory())
760
            ));
761
        }
762
763
        $repository = $this->getRepository();
764
        $searchService = $repository->getSearchService();
765
766
        $content = $this->createContentWithName($text, [2]);
767
        $this->refreshSearch($repository);
768
769
        $criterion = new Criterion\FullText($searchForText);
770
        $query = new Query(['filter' => $criterion]);
771
        $result = $searchService->findContent($query);
772
773
        // for some cases there might be more than one hit, so check if proper one was found
774
        foreach ($result->searchHits as $searchHit) {
775
            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...
776
                return;
777
            }
778
        }
779
        $this->fail('Failed to find required Content in search results');
780
    }
781
782
    /**
783
     * Data Provider for {@see testIndexingSpecialFullTextCases()} method.
784
     *
785
     * @return array
786
     */
787
    public function getSpecialFullTextCases()
788
    {
789
        return [
790
            ['UPPERCASE TEXT', 'uppercase text'],
791
            ['lowercase text', 'LOWERCASE TEXT'],
792
            ['text-with-hyphens', 'text-with-hyphens'],
793
            ['text containing spaces', 'text containing spaces'],
794
            ['"quoted text"', 'quoted text'],
795
            ['ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝ', 'àáâãäåçèéêëìíîïðñòóôõöøùúûüý'],
796
            ['with boundary.', 'with boundary'],
797
            ['Folder1.', 'Folder1.'],
798
            ['whitespaces', "     whitespaces  \n \t "],
799
            // @todo: Remove as soon as elastic is updated to later version not affected
800
            ["it's", "it's", [LegacyElasticsearch::class]],
801
            ['with_underscore', 'with_underscore'],
802
        ];
803
    }
804
805
    /**
806
     * Test updating Content field value with empty value removes it from search index.
807
     */
808
    public function testRemovedContentFieldValueIsNotFound()
809
    {
810
        $repository = $this->getRepository();
811
        $contentService = $repository->getContentService();
812
        $searchService = $repository->getSearchService();
813
        $publishedContent = $this->createContentWithNameAndDescription('testRemovedContentFieldValueIsNotFound', 'descriptionToBeRemoved', [2]);
814
        $this->refreshSearch($repository);
815
816
        $contentDraft = $contentService->createContentDraft($publishedContent->contentInfo);
817
        $contentUpdateStruct = $contentService->newContentUpdateStruct();
818
        $contentUpdateStruct->setField('description', null);
819
        $contentDraft = $contentService->updateContent($contentDraft->versionInfo, $contentUpdateStruct);
820
        $contentService->publishVersion($contentDraft->versionInfo);
821
        $this->refreshSearch($repository);
822
823
        // Removed field value should not be found
824
        $criterion = new Criterion\FullText('descriptionToBeRemoved');
825
        $query = new Query(['filter' => $criterion]);
826
        $results = $searchService->findContent($query);
827
        $this->assertEquals(0, $results->totalCount);
828
829
        // Should be found
830
        $criterion = new Criterion\FullText('testRemovedContentFieldValueIsNotFound');
831
        $query = new Query(['filter' => $criterion]);
832
        $results = $searchService->findContent($query);
833
        $this->assertEquals(1, $results->totalCount);
834
    }
835
836
    /**
837
     * Check if children locations are/are not ivisible.
838
     *
839
     * @param \eZ\Publish\API\Repository\SearchService $searchService
840
     * @param int $parentLocationId parent location Id
841
     * @param bool $expected expected value of {invisible} property in subtree
842
     */
843
    private function assertSubtreeInvisibleProperty(SearchService $searchService, $parentLocationId, $expected)
844
    {
845
        $criterion = new Criterion\ParentLocationId($parentLocationId);
846
        $query = new LocationQuery(array('filter' => $criterion));
847
        $result = $searchService->findLocations($query);
848
        foreach ($result->searchHits as $searchHit) {
849
            $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...
850
            // Perform recursive check for children locations
851
            $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...
852
        }
853
    }
854
855
    /**
856
     * Test that swapping locations affects properly Search Engine Index.
857
     */
858
    public function testSwapLocation()
859
    {
860
        $repository = $this->getRepository();
861
        $locationService = $repository->getLocationService();
862
        $searchService = $repository->getSearchService();
863
864
        $content01 = $this->createContentWithName('content01', [2]);
865
        $location01 = $locationService->loadLocation($content01->contentInfo->mainLocationId);
866
867
        $content02 = $this->createContentWithName('content02', [2]);
868
        $location02 = $locationService->loadLocation($content02->contentInfo->mainLocationId);
869
870
        $locationService->swapLocation($location01, $location02);
871
        $this->refreshSearch($repository);
872
873
        // content02 should be at location01
874
        $criterion = new Criterion\LocationId($location01->id);
875
        $query = new Query(['filter' => $criterion]);
876
        $results = $searchService->findContent($query);
877
        $this->assertEquals(1, $results->totalCount);
878
        $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...
879
880
        // content01 should be at location02
881
        $criterion = new Criterion\LocationId($location02->id);
882
        $query = new Query(['filter' => $criterion]);
883
        $results = $searchService->findContent($query);
884
        $this->assertEquals(1, $results->totalCount);
885
        $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...
886
    }
887
888
    /**
889
     * Test that updating Content metadata affects properly Search Engine Index.
890
     */
891
    public function testUpdateContentMetadata()
892
    {
893
        $repository = $this->getRepository();
894
        $contentService = $repository->getContentService();
895
        $locationService = $repository->getLocationService();
896
        $searchService = $repository->getSearchService();
897
898
        $publishedContent = $this->createContentWithName('updateMetadataTest', [2]);
899
        $originalMainLocationId = $publishedContent->contentInfo->mainLocationId;
900
        $newLocationCreateStruct = $locationService->newLocationCreateStruct(60);
901
        $newLocation = $locationService->createLocation($publishedContent->contentInfo, $newLocationCreateStruct);
902
903
        $newContentMetadataUpdateStruct = $contentService->newContentMetadataUpdateStruct();
904
        $newContentMetadataUpdateStruct->remoteId = md5('Test');
905
        $newContentMetadataUpdateStruct->publishedDate = new \DateTime();
906
        $newContentMetadataUpdateStruct->publishedDate->add(new \DateInterval('P1D'));
907
        $newContentMetadataUpdateStruct->mainLocationId = $newLocation->id;
908
909
        $contentService->updateContentMetadata($publishedContent->contentInfo, $newContentMetadataUpdateStruct);
910
        $this->refreshSearch($repository);
911
912
        // find Content by Id, calling findContentInfo which is using the Search Index
913
        $criterion = new Criterion\ContentId($publishedContent->id);
914
        $query = new Query(['filter' => $criterion]);
915
        $results = $searchService->findContentInfo($query);
916
        $this->assertEquals(1, $results->totalCount);
917
        $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...
918
919
        // find Content using updated RemoteId
920
        $criterion = new Criterion\RemoteId($newContentMetadataUpdateStruct->remoteId);
921
        $query = new Query(['filter' => $criterion]);
922
        $results = $searchService->findContent($query);
923
        $this->assertEquals(1, $results->totalCount);
924
        $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...
925
        /** @var \eZ\Publish\Core\Repository\Values\Content\Content $foundContentInfo */
926
        $this->assertEquals($publishedContent->id, $foundContentInfo->id);
927
        $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...
928
        $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...
929
        $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...
930
931
        // find Content using old main location
932
        $criterion = new Criterion\LocationId($originalMainLocationId);
933
        $query = new LocationQuery(['filter' => $criterion]);
934
        $results = $searchService->findLocations($query);
935
        $this->assertEquals(1, $results->totalCount);
936
        $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...
937
    }
938
939
    /**
940
     * Test that updating Content Draft metadata does not affect Search Engine Index.
941
     */
942
    public function testUpdateContentDraftMetadataIsNotIndexed()
943
    {
944
        $repository = $this->getRepository();
945
        $contentService = $repository->getContentService();
946
        $locationService = $repository->getLocationService();
947
948
        $testableContentType = $this->createTestContentType();
949
        $rootContentStruct = $contentService->newContentCreateStruct($testableContentType, 'eng-GB');
950
        $rootContentStruct->setField('name', 'TestUpdatingContentDraftMetadata');
951
952
        $contentDraft = $contentService->createContent($rootContentStruct, [$locationService->newLocationCreateStruct(2)]);
953
954
        $newContentMetadataUpdateStruct = $contentService->newContentMetadataUpdateStruct();
955
        $newContentMetadataUpdateStruct->ownerId = 10;
956
        $newContentMetadataUpdateStruct->remoteId = md5('Test');
957
958
        $contentService->updateContentMetadata($contentDraft->contentInfo, $newContentMetadataUpdateStruct);
959
960
        $this->refreshSearch($repository);
961
        $this->assertContentIdSearch($contentDraft->contentInfo->id, 0);
962
    }
963
964
    /**
965
     * Test that assigning section to content object properly affects Search Engine Index.
966
     */
967
    public function testAssignSection()
968
    {
969
        $repository = $this->getRepository();
970
        $sectionService = $repository->getSectionService();
971
        $searchService = $repository->getSearchService();
972
973
        $section = $sectionService->loadSection(2);
974
        $content = $this->createContentWithName('testAssignSection', [2]);
975
976
        $sectionService->assignSection($content->contentInfo, $section);
977
        $this->refreshSearch($repository);
978
979
        $criterion = new Criterion\ContentId($content->id);
980
        $query = new Query(['filter' => $criterion]);
981
        $results = $searchService->findContentInfo($query);
982
        $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...
983
    }
984
985
    /**
986
     * Will create if not exists a simple content type for test purposes with just one required field name.
987
     *
988
     * @return \eZ\Publish\API\Repository\Values\ContentType\ContentType
989
     */
990
    protected function createTestContentType()
991
    {
992
        $repository = $this->getRepository();
993
        $contentTypeService = $repository->getContentTypeService();
994
        $contentTypeIdentifier = 'test-type';
995
        try {
996
            return $contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier);
997
        } catch (NotFoundException $e) {
998
            // continue creation process
999
        }
1000
1001
        $nameField = $contentTypeService->newFieldDefinitionCreateStruct('name', 'ezstring');
1002
        $nameField->fieldGroup = 'main';
1003
        $nameField->position = 1;
1004
        $nameField->isTranslatable = true;
1005
        $nameField->isSearchable = true;
1006
        $nameField->isRequired = true;
1007
1008
        $contentTypeStruct = $contentTypeService->newContentTypeCreateStruct($contentTypeIdentifier);
1009
        $contentTypeStruct->mainLanguageCode = 'eng-GB';
1010
        $contentTypeStruct->creatorId = 14;
1011
        $contentTypeStruct->creationDate = new DateTime();
1012
        $contentTypeStruct->names = ['eng-GB' => 'Test Content Type'];
1013
        $contentTypeStruct->addFieldDefinition($nameField);
1014
1015
        $contentTypeGroup = $contentTypeService->loadContentTypeGroupByIdentifier('Content');
1016
1017
        $contentTypeDraft = $contentTypeService->createContentType($contentTypeStruct, [$contentTypeGroup]);
1018
        $contentTypeService->publishContentTypeDraft($contentTypeDraft);
1019
1020
        return $contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier);
1021
    }
1022
1023
    /**
1024
     * Will create and publish an content with a filed with a given content name in location provided into
1025
     * $parentLocationIdList.
1026
     *
1027
     * @param string $contentName
1028
     * @param array $parentLocationIdList
1029
     *
1030
     * @return \eZ\Publish\API\Repository\Values\Content\Content
1031
     */
1032
    protected function createContentWithName($contentName, array $parentLocationIdList = array())
1033
    {
1034
        $contentService = $this->getRepository()->getContentService();
1035
        $locationService = $this->getRepository()->getLocationService();
1036
1037
        $testableContentType = $this->createTestContentType();
1038
1039
        $rootContentStruct = $contentService->newContentCreateStruct($testableContentType, 'eng-GB');
1040
        $rootContentStruct->setField('name', $contentName);
1041
1042
        $parentLocationList = [];
1043
        foreach ($parentLocationIdList as $locationID) {
1044
            $parentLocationList[] = $locationService->newLocationCreateStruct($locationID);
1045
        }
1046
1047
        $contentDraft = $contentService->createContent($rootContentStruct, $parentLocationList);
1048
        $publishedContent = $contentService->publishVersion($contentDraft->getVersionInfo());
1049
1050
        return $publishedContent;
1051
    }
1052
1053
    /**
1054
     * Create and publish a content with filled name and description fields in location provided into
1055
     * $parentLocationIdList.
1056
     *
1057
     * @param string $contentName
1058
     * @param $contentDescription
1059
     * @param array $parentLocationIdList
1060
     *
1061
     * @return \eZ\Publish\API\Repository\Values\Content\Content
1062
     */
1063
    protected function createContentWithNameAndDescription($contentName, $contentDescription, array $parentLocationIdList = [])
1064
    {
1065
        $repository = $this->getRepository();
1066
        $contentService = $repository->getContentService();
1067
        $contentTypeService = $repository->getContentTypeService();
1068
        $publishedContent = $this->createContentWithName($contentName, $parentLocationIdList);
1069
        $descriptionField = $contentTypeService->newFieldDefinitionCreateStruct('description', 'ezstring');
1070
        $descriptionField->fieldGroup = 'main';
1071
        $descriptionField->position = 2;
1072
        $descriptionField->isTranslatable = true;
1073
        $descriptionField->isSearchable = true;
1074
        $descriptionField->isRequired = false;
1075
        $contentType = $contentTypeService->loadContentType($publishedContent->contentInfo->contentTypeId);
1076
        $contentTypeDraft = $contentTypeService->createContentTypeDraft($contentType);
1077
        $contentTypeService->addFieldDefinition($contentTypeDraft, $descriptionField);
1078
        $contentTypeService->publishContentTypeDraft($contentTypeDraft);
1079
        $contentDraft = $contentService->createContentDraft($publishedContent->contentInfo);
1080
        $contentUpdateStruct = $contentService->newContentUpdateStruct();
1081
        $contentUpdateStruct->setField('description', $contentDescription);
1082
        $contentDraft = $contentService->updateContent($contentDraft->versionInfo, $contentUpdateStruct);
1083
1084
        return $contentService->publishVersion($contentDraft->versionInfo);
1085
    }
1086
1087
    /**
1088
     * Asserts an content id if it exists still in the solr core.
1089
     *
1090
     * @param int $contentId
1091
     * @param int $expectedCount
1092
     */
1093
    protected function assertContentIdSearch($contentId, $expectedCount)
1094
    {
1095
        $searchService = $this->getRepository()->getSearchService();
1096
1097
        $criterion = new Criterion\ContentId($contentId);
1098
        $query = new Query(array('filter' => $criterion));
1099
        $result = $searchService->findContent($query);
1100
1101
        $this->assertEquals($expectedCount, $result->totalCount);
1102
        if ($expectedCount == 0) {
1103
            return;
1104
        }
1105
1106
        $this->assertEquals(
1107
            $contentId,
1108
            $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...
1109
        );
1110
    }
1111
1112
    /**
1113
     * Create & get new Location for tests.
1114
     *
1115
     * @return \eZ\Publish\API\Repository\Values\Content\Location
1116
     */
1117
    protected function createNewTestLocation()
1118
    {
1119
        $repository = $this->getRepository();
1120
        $locationService = $repository->getLocationService();
1121
        $contentService = $repository->getContentService();
1122
1123
        $rootLocationId = 2;
1124
        $membersContentId = 11;
1125
        $membersContentInfo = $contentService->loadContentInfo($membersContentId);
1126
1127
        $locationCreateStruct = $locationService->newLocationCreateStruct($rootLocationId);
1128
1129
        return $locationService->createLocation($membersContentInfo, $locationCreateStruct);
1130
    }
1131
}
1132