Completed
Push — test-EZP-26707-issearchable-fu... ( 51e186 )
by
unknown
27:09 queued 12:08
created

testFindContentInfoFullTextIsSearchable()   B

Complexity

Conditions 3
Paths 2

Size

Total Lines 29
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 16
nc 2
nop 0
dl 0
loc 29
rs 8.8571
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 EzSystems\EzPlatformSolrSearchEngine\Tests\SetupFactory\LegacySetupFactory as LegacySolrSetupFactory;
14
use eZ\Publish\API\Repository\Tests\SetupFactory\LegacyElasticsearch as LegacyElasticsearchSetupFactory;
15
use eZ\Publish\API\Repository\Exceptions\NotFoundException;
16
use eZ\Publish\API\Repository\SearchService;
17
use eZ\Publish\API\Repository\Tests\SetupFactory\LegacyElasticsearch;
18
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
19
use eZ\Publish\API\Repository\Values\Content\LocationQuery;
20
use eZ\Publish\API\Repository\Values\Content\Query;
21
use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
22
use DateTime;
23
24
/**
25
 * Test case for indexing operations with a search engine.
26
 *
27
 * @group integration
28
 * @group search
29
 * @group indexing
30
 */
31
class SearchEngineIndexingTest extends BaseTest
32
{
33
    /**
34
     * EZP-26186: Make sure index is NOT deleted on removal of version draft (affected Solr & content index on Elastic).
35
     */
36
    public function testDeleteVersion()
37
    {
38
        $repository = $this->getRepository();
39
        $contentService = $repository->getContentService();
40
        $searchService = $repository->getSearchService();
41
42
        $membersContentId = $this->generateId('content', 11);
43
        $contentInfo = $contentService->loadContentInfo($membersContentId);
44
45
        $draft = $contentService->createContentDraft($contentInfo);
46
        $contentService->deleteVersion($draft->getVersionInfo());
47
48
        $this->refreshSearch($repository);
49
50
        // Found
51
        $criterion = new Criterion\LocationId($contentInfo->mainLocationId);
52
        $query = new Query(array('filter' => $criterion));
53
        $result = $searchService->findContentInfo($query);
54
        $this->assertEquals(1, $result->totalCount);
55
        $this->assertEquals(
56
            $contentInfo->id,
57
            $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...
58
        );
59
    }
60
61
    /**
62
     * EZP-26186: Make sure affected child locations are deleted on content deletion (affected Solr & Elastic).
63
     */
64
    public function testDeleteContent()
65
    {
66
        $repository = $this->getRepository();
67
        $contentService = $repository->getContentService();
68
        $searchService = $repository->getSearchService();
69
70
        $anonymousUsersContentId = $this->generateId('content', 42);
71
        $contentInfo = $contentService->loadContentInfo($anonymousUsersContentId);
72
73
        $contentService->deleteContent($contentInfo);
74
75
        $this->refreshSearch($repository);
76
77
        // Should not be found
78
        $criterion = new Criterion\ParentLocationId($contentInfo->mainLocationId);
79
        $query = new LocationQuery(array('filter' => $criterion));
80
        $result = $searchService->findLocations($query);
81
        $this->assertEquals(0, $result->totalCount);
82
    }
83
84
    /**
85
     * Test that a newly created user is available for search.
86
     */
87
    public function testCreateUser()
88
    {
89
        $repository = $this->getRepository();
90
        $userService = $repository->getUserService();
91
        $searchService = $repository->getSearchService();
92
93
        // ID of the "Editors" user group
94
        $editorsGroupId = 13;
95
        $userCreate = $userService->newUserCreateStruct(
96
            'user',
97
            '[email protected]',
98
            'secret',
99
            'eng-US'
100
        );
101
        $userCreate->enabled = true;
102
        $userCreate->setField('first_name', 'Example');
103
        $userCreate->setField('last_name', 'User');
104
105
        // Load parent group for the user
106
        $group = $userService->loadUserGroup($editorsGroupId);
107
108
        // Create a new user instance.
109
        $user = $userService->createUser($userCreate, array($group));
110
111
        $this->refreshSearch($repository);
112
113
        // Should be found
114
        $criterion = new Criterion\ContentId($user->id);
115
        $query = new Query(array('filter' => $criterion));
116
        $result = $searchService->findContentInfo($query);
117
        $this->assertEquals(1, $result->totalCount);
118
    }
119
120
    /**
121
     * Test that a newly created user group is available for search.
122
     */
123
    public function testCreateUserGroup()
124
    {
125
        $repository = $this->getRepository();
126
        $userService = $repository->getUserService();
127
        $searchService = $repository->getSearchService();
128
        $mainGroupId = $this->generateId('group', 4);
129
130
        $parentUserGroup = $userService->loadUserGroup($mainGroupId);
131
        $userGroupCreateStruct = $userService->newUserGroupCreateStruct('eng-GB');
132
        $userGroupCreateStruct->setField('name', 'Example Group');
133
134
        // Create a new user group
135
        $userGroup = $userService->createUserGroup(
136
            $userGroupCreateStruct,
137
            $parentUserGroup
138
        );
139
140
        $this->refreshSearch($repository);
141
142
        // Should be found
143
        $criterion = new Criterion\ContentId($userGroup->id);
144
        $query = new Query(array('filter' => $criterion));
145
        $result = $searchService->findContentInfo($query);
146
        $this->assertEquals(1, $result->totalCount);
147
    }
148
149
    /**
150
     * Test that a newly created Location is available for search.
151
     */
152
    public function testCreateLocation()
153
    {
154
        $repository = $this->getRepository();
155
        $searchService = $repository->getSearchService();
156
        $membersLocation = $this->createNewTestLocation();
157
158
        $this->refreshSearch($repository);
159
160
        // Found
161
        $criterion = new Criterion\LocationId($membersLocation->id);
162
        $query = new LocationQuery(array('filter' => $criterion));
163
        $result = $searchService->findLocations($query);
164
        $this->assertEquals(1, $result->totalCount);
165
        $this->assertEquals(
166
            $membersLocation->id,
167
            $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...
168
        );
169
    }
170
171
    /**
172
     * Test that hiding a Location makes it unavailable for search.
173
     */
174
    public function testHideSubtree()
175
    {
176
        $repository = $this->getRepository();
177
        $searchService = $repository->getSearchService();
178
179
        // 5 is the ID of an existing location
180
        $locationId = $this->generateId('location', 5);
181
        $locationService = $repository->getLocationService();
182
        $location = $locationService->loadLocation($locationId);
183
        $locationService->hideLocation($location);
184
        $this->refreshSearch($repository);
185
186
        // Check if parent location is hidden
187
        $criterion = new Criterion\LocationId($locationId);
188
        $query = new LocationQuery(array('filter' => $criterion));
189
        $result = $searchService->findLocations($query);
190
        $this->assertEquals(1, $result->totalCount);
191
        $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...
192
193
        // Check if children locations are invisible
194
        $this->assertSubtreeInvisibleProperty($searchService, $locationId, true);
195
    }
196
197
    /**
198
     * Test that hiding and revealing a Location makes it available for search.
199
     */
200
    public function testRevealSubtree()
201
    {
202
        $repository = $this->getRepository();
203
        $searchService = $repository->getSearchService();
204
205
        // 5 is the ID of an existing location
206
        $locationId = $this->generateId('location', 5);
207
        $locationService = $repository->getLocationService();
208
        $location = $locationService->loadLocation($locationId);
209
        $locationService->hideLocation($location);
210
        $this->refreshSearch($repository);
211
        $locationService->unhideLocation($location);
212
        $this->refreshSearch($repository);
213
214
        // Check if parent location is not hidden
215
        $criterion = new Criterion\LocationId($locationId);
216
        $query = new LocationQuery(array('filter' => $criterion));
217
        $result = $searchService->findLocations($query);
218
        $this->assertEquals(1, $result->totalCount);
219
        $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...
220
221
        // Check if children locations are not invisible
222
        $this->assertSubtreeInvisibleProperty($searchService, $locationId, false);
223
    }
224
225
    /**
226
     * Test that a copied subtree is available for search.
227
     */
228
    public function testCopySubtree()
229
    {
230
        $repository = $this->getRepository();
231
        $locationService = $repository->getLocationService();
232
        $contentService = $repository->getContentService();
233
        $searchService = $repository->getSearchService();
234
235
        $rootLocationId = 2;
236
        $membersContentId = 11;
237
        $adminsContentId = 12;
238
        $editorsContentId = 13;
239
        $membersContentInfo = $contentService->loadContentInfo($membersContentId);
240
        $adminsContentInfo = $contentService->loadContentInfo($adminsContentId);
241
        $editorsContentInfo = $contentService->loadContentInfo($editorsContentId);
242
243
        $locationCreateStruct = $locationService->newLocationCreateStruct($rootLocationId);
244
        $membersLocation = $locationService->createLocation($membersContentInfo, $locationCreateStruct);
245
        $editorsLocation = $locationService->createLocation($editorsContentInfo, $locationCreateStruct);
246
        $adminsLocation = $locationService->createLocation(
247
            $adminsContentInfo,
248
            $locationService->newLocationCreateStruct($membersLocation->id)
249
        );
250
251
        $copiedLocation = $locationService->copySubtree($adminsLocation, $editorsLocation);
252
        $this->refreshSearch($repository);
253
254
        // Found under Members
255
        $criterion = new Criterion\ParentLocationId($membersLocation->id);
256
        $query = new LocationQuery(array('filter' => $criterion));
257
        $result = $searchService->findLocations($query);
258
        $this->assertEquals(1, $result->totalCount);
259
        $this->assertEquals(
260
            $adminsLocation->id,
261
            $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...
262
        );
263
264
        // Found under Editors
265
        $criterion = new Criterion\ParentLocationId($editorsLocation->id);
266
        $query = new LocationQuery(array('filter' => $criterion));
267
        $result = $searchService->findLocations($query);
268
        $this->assertEquals(1, $result->totalCount);
269
        $this->assertEquals(
270
            $copiedLocation->id,
271
            $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...
272
        );
273
    }
274
275
    /**
276
     * Test that moved subtree is available for search and found only under a specific parent Location.
277
     */
278
    public function testMoveSubtree()
279
    {
280
        $repository = $this->getRepository();
281
        $locationService = $repository->getLocationService();
282
        $contentService = $repository->getContentService();
283
        $searchService = $repository->getSearchService();
284
285
        $rootLocationId = 2;
286
        $membersContentId = 11;
287
        $adminsContentId = 12;
288
        $editorsContentId = 13;
289
        $membersContentInfo = $contentService->loadContentInfo($membersContentId);
290
        $adminsContentInfo = $contentService->loadContentInfo($adminsContentId);
291
        $editorsContentInfo = $contentService->loadContentInfo($editorsContentId);
292
293
        $locationCreateStruct = $locationService->newLocationCreateStruct($rootLocationId);
294
        $membersLocation = $locationService->createLocation($membersContentInfo, $locationCreateStruct);
295
        $editorsLocation = $locationService->createLocation($editorsContentInfo, $locationCreateStruct);
296
        $adminsLocation = $locationService->createLocation(
297
            $adminsContentInfo,
298
            $locationService->newLocationCreateStruct($membersLocation->id)
299
        );
300
301
        $this->refreshSearch($repository);
302
303
        // Not found under Editors
304
        $criterion = new Criterion\ParentLocationId($editorsLocation->id);
305
        $query = new LocationQuery(array('filter' => $criterion));
306
        $result = $searchService->findLocations($query);
307
        $this->assertEquals(0, $result->totalCount);
308
309
        // Found under Members
310
        $criterion = new Criterion\ParentLocationId($membersLocation->id);
311
        $query = new LocationQuery(array('filter' => $criterion));
312
        $result = $searchService->findLocations($query);
313
        $this->assertEquals(1, $result->totalCount);
314
        $this->assertEquals(
315
            $adminsLocation->id,
316
            $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...
317
        );
318
319
        $locationService->moveSubtree($adminsLocation, $editorsLocation);
320
        $this->refreshSearch($repository);
321
322
        // Found under Editors
323
        $criterion = new Criterion\ParentLocationId($editorsLocation->id);
324
        $query = new LocationQuery(array('filter' => $criterion));
325
        $result = $searchService->findLocations($query);
326
        $this->assertEquals(1, $result->totalCount);
327
        $this->assertEquals(
328
            $adminsLocation->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
        // Not found under Members
333
        $criterion = new Criterion\ParentLocationId($membersLocation->id);
334
        $query = new LocationQuery(array('filter' => $criterion));
335
        $result = $searchService->findLocations($query);
336
        $this->assertEquals(0, $result->totalCount);
337
    }
338
339
    /**
340
     * Testing that content is indexed even when containing only fields with values
341
     * considered to be empty by the search engine.
342
     */
343
    public function testIndexContentWithNullField()
344
    {
345
        $repository = $this->getRepository();
346
        $contentService = $repository->getContentService();
347
        $contentTypeService = $repository->getContentTypeService();
348
        $searchService = $repository->getSearchService();
349
350
        $createStruct = $contentTypeService->newContentTypeCreateStruct('test-type');
351
        $createStruct->mainLanguageCode = 'eng-GB';
352
        $createStruct->names = array('eng-GB' => 'Test type');
353
        $createStruct->creatorId = 14;
354
        $createStruct->creationDate = new DateTime();
355
356
        $translatableFieldCreate = $contentTypeService->newFieldDefinitionCreateStruct(
357
            'integer',
358
            'ezinteger'
359
        );
360
        $translatableFieldCreate->names = array('eng-GB' => 'Simple translatable integer field');
361
        $translatableFieldCreate->fieldGroup = 'main';
362
        $translatableFieldCreate->position = 1;
363
        $translatableFieldCreate->isTranslatable = true;
364
        $translatableFieldCreate->isSearchable = true;
365
366
        $createStruct->addFieldDefinition($translatableFieldCreate);
367
368
        $contentGroup = $contentTypeService->loadContentTypeGroupByIdentifier('Content');
369
        $contentTypeDraft = $contentTypeService->createContentType(
370
            $createStruct,
371
            array($contentGroup)
372
        );
373
        $contentTypeService->publishContentTypeDraft($contentTypeDraft);
374
        $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...
375
376
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
377
        $createStruct->alwaysAvailable = false;
378
        $createStruct->mainLanguageCode = 'eng-GB';
379
380
        $draft = $contentService->createContent($createStruct);
381
        $content = $contentService->publishVersion($draft->getVersionInfo());
382
383
        $this->refreshSearch($repository);
384
385
        // Found
386
        $criterion = new Criterion\ContentId($content->id);
387
        $query = new Query(array('filter' => $criterion));
388
        $result = $searchService->findContent($query);
389
        $this->assertEquals(1, $result->totalCount);
390
        $this->assertEquals(
391
            $content->id,
392
            $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...
393
        );
394
    }
395
396
    /**
397
     * Test that updated Location is available for search.
398
     */
399
    public function testUpdateLocation()
400
    {
401
        $repository = $this->getRepository();
402
        $locationService = $repository->getLocationService();
403
        $searchService = $repository->getSearchService();
404
405
        $rootLocationId = 2;
406
        $locationToUpdate = $locationService->loadLocation($rootLocationId);
407
408
        $criterion = new Criterion\LogicalAnd([
409
            new Criterion\LocationId($rootLocationId),
410
            new Criterion\Location\Priority(Criterion\Operator::GT, 0),
411
        ]);
412
413
        $query = new LocationQuery(array('filter' => $criterion));
414
        $result = $searchService->findLocations($query);
415
416
        $this->assertEquals(0, $result->totalCount);
417
418
        $locationUpdateStruct = $locationService->newLocationUpdateStruct();
419
        $locationUpdateStruct->priority = 4;
420
        $locationService->updateLocation($locationToUpdate, $locationUpdateStruct);
421
422
        $this->refreshSearch($repository);
423
424
        $result = $searchService->findLocations($query);
425
426
        $this->assertEquals(1, $result->totalCount);
427
        $this->assertEquals(
428
            $locationToUpdate->id,
429
            $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...
430
        );
431
    }
432
433
    /**
434
     * Testing that content will be deleted with all of its subitems but subitems with additional location will stay as
435
     * they are.
436
     */
437
    public function testDeleteLocation()
438
    {
439
        $repository = $this->getRepository();
440
        $locationService = $repository->getLocationService();
441
442
        $treeContainerContent = $this->createContentWithName('Tree Container', [2]);
443
        $supposeBeDeletedSubItem = $this->createContentWithName(
444
            'Suppose to be deleted sub-item',
445
            [$treeContainerContent->contentInfo->mainLocationId]
446
        );
447
        $supposeSurviveSubItem = $this->createContentWithName(
448
            'Suppose to Survive Item',
449
            [2, $treeContainerContent->contentInfo->mainLocationId]
450
        );
451
452
        $treeContainerLocation = $locationService->loadLocation($treeContainerContent->contentInfo->mainLocationId);
453
454
        $this->refreshSearch($repository);
455
456
        $this->assertContentIdSearch($treeContainerContent->id, 1);
457
        $this->assertContentIdSearch($supposeSurviveSubItem->id, 1);
458
        $this->assertContentIdSearch($supposeBeDeletedSubItem->id, 1);
459
460
        $locationService->deleteLocation($treeContainerLocation);
461
462
        $this->refreshSearch($repository);
463
464
        $this->assertContentIdSearch($supposeSurviveSubItem->id, 1);
465
        $this->assertContentIdSearch($treeContainerContent->id, 0);
466
        $this->assertContentIdSearch($supposeBeDeletedSubItem->id, 0);
467
    }
468
469
    /**
470
     * Test content is available for search after being published.
471
     */
472
    public function testPublishVersion()
473
    {
474
        $repository = $this->getRepository();
475
        $searchService = $repository->getSearchService();
476
477
        $publishedContent = $this->createContentWithName('publishedContent', [2]);
478
        $this->refreshSearch($repository);
479
480
        $criterion = new Criterion\FullText('publishedContent');
481
        $query = new Query(['filter' => $criterion]);
482
        $result = $searchService->findContent($query);
483
484
        $this->assertCount(1, $result->searchHits);
485
        $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...
486
487
        // Searching for children of locationId=2 should also hit this content
488
        $criterion = new Criterion\ParentLocationId(2);
489
        $query = new LocationQuery(array('filter' => $criterion));
490
        $result = $searchService->findLocations($query);
491
492
        foreach ($result->searchHits as $searchHit) {
493
            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...
494
                return;
495
            }
496
        }
497
        $this->fail('Parent location sub-items do not contain published content');
498
    }
499
500
    /**
501
     * Test recovered content is available for search.
502
     */
503
    public function testRecoverLocation()
504
    {
505
        $repository = $this->getRepository();
506
        $locationService = $repository->getLocationService();
507
        $trashService = $repository->getTrashService();
508
        $searchService = $repository->getSearchService();
509
510
        $publishedContent = $this->createContentWithName('recovery-test', [2]);
511
        $location = $locationService->loadLocation($publishedContent->contentInfo->mainLocationId);
512
513
        $trashService->trash($location);
514
        $this->refreshSearch($repository);
515
516
        $criterion = new Criterion\LocationId($location->id);
517
        $query = new LocationQuery(['filter' => $criterion]);
518
        $locations = $searchService->findLocations($query);
519
        $this->assertEquals(0, $locations->totalCount);
520
521
        $trashItem = $trashService->loadTrashItem($location->id);
522
        $trashService->recover($trashItem);
523
        $this->refreshSearch($repository);
524
525
        $locations = $searchService->findLocations($query);
526
        $this->assertEquals(0, $locations->totalCount);
527
        $this->assertContentIdSearch($publishedContent->contentInfo->id, 1);
528
    }
529
530
    /**
531
     * Test copied content is available for search.
532
     */
533
    public function testCopyContent()
534
    {
535
        $repository = $this->getRepository();
536
        $searchService = $repository->getSearchService();
537
        $contentService = $repository->getContentService();
538
        $locationService = $repository->getLocationService();
539
540
        $publishedContent = $this->createContentWithName('copyTest', [2]);
541
        $this->refreshSearch($repository);
542
        $criterion = new Criterion\FullText('copyTest');
543
        $query = new Query(['filter' => $criterion]);
544
        $result = $searchService->findContent($query);
545
        $this->assertCount(1, $result->searchHits);
546
547
        $copiedContent = $contentService->copyContent($publishedContent->contentInfo, $locationService->newLocationCreateStruct(2));
548
        $this->refreshSearch($repository);
549
        $result = $searchService->findContent($query);
550
        $this->assertCount(2, $result->searchHits);
551
552
        $this->assertContentIdSearch($publishedContent->contentInfo->id, 1);
553
        $this->assertContentIdSearch($copiedContent->contentInfo->id, 1);
554
    }
555
556
    /**
557
     * Test that setting object content state to locked and then unlocked does not affect search index.
558
     */
559
    public function testSetContentState()
560
    {
561
        $repository = $this->getRepository();
562
        $objectStateService = $repository->getObjectStateService();
563
564
        // get Object States
565
        $stateNotLocked = $objectStateService->loadObjectState(1);
566
        $stateLocked = $objectStateService->loadObjectState(2);
567
568
        $publishedContent = $this->createContentWithName('setContentStateTest', [2]);
569
        $objectStateService->setContentState($publishedContent->contentInfo, $stateLocked->getObjectStateGroup(), $stateLocked);
570
        $this->refreshSearch($repository);
571
572
        // Setting Content State to "locked" should not affect search index
573
        $this->assertContentIdSearch($publishedContent->contentInfo->id, 1);
574
575
        $objectStateService->setContentState($publishedContent->contentInfo, $stateNotLocked->getObjectStateGroup(), $stateNotLocked);
576
        $this->refreshSearch($repository);
577
578
        // Setting Content State back to "not locked" should not affect search index
579
        $this->assertContentIdSearch($publishedContent->contentInfo->id, 1);
580
    }
581
582
    /**
583
     * Check if FullText indexing works for special cases of text.
584
     *
585
     * @param string $text Content Item field value text (to be indexed)
586
     * @param string $searchForText text based on which Content Item should be found
587
     * @param array $ignoreForSetupFactories list of SetupFactories to be ignored
588
     * @dataProvider getSpecialFullTextCases
589
     */
590
    public function testIndexingSpecialFullTextCases($text, $searchForText, array $ignoreForSetupFactories = [])
591
    {
592
        // check if provided data should be ignored for the current Search Engine (via SetupFactory)
593
        if (!empty($ignoreForSetupFactories) && in_array(get_class($this->getSetupFactory()), $ignoreForSetupFactories)) {
594
            $this->markTestIncomplete(sprintf(
595
                'Handling FullText Searching for the phrase {%s} is incomplete for %s',
596
                $searchForText,
597
                get_class($this->getSetupFactory())
598
            ));
599
        }
600
601
        $repository = $this->getRepository();
602
        $searchService = $repository->getSearchService();
603
604
        $content = $this->createContentWithName($text, [2]);
605
        $this->refreshSearch($repository);
606
607
        $criterion = new Criterion\FullText($searchForText);
608
        $query = new Query(['filter' => $criterion]);
609
        $result = $searchService->findContent($query);
610
611
        // for some cases there might be more than one hit, so check if proper one was found
612
        foreach ($result->searchHits as $searchHit) {
613
            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...
614
                return;
615
            }
616
        }
617
        $this->fail('Failed to find required Content in search results');
618
    }
619
620
    /**
621
     * Data Provider for {@see testIndexingSpecialFullTextCases()} method.
622
     *
623
     * @return array
624
     */
625
    public function getSpecialFullTextCases()
626
    {
627
        return [
628
            ['UPPERCASE TEXT', 'uppercase text'],
629
            ['lowercase text', 'LOWERCASE TEXT'],
630
            ['text-with-hyphens', 'text-with-hyphens'],
631
            ['text containing spaces', 'text containing spaces'],
632
            ['"quoted text"', 'quoted text'],
633
            ['ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝ', 'àáâãäåçèéêëìíîïðñòóôõöøùúûüý'],
634
            ['with boundary.', 'with boundary'],
635
            ['Folder1.', 'Folder1.'],
636
            ['whitespaces', "     whitespaces  \n \t "],
637
            // @todo: Remove as soon as elastic is updated to later version not affected
638
            ["it's", "it's", [LegacyElasticsearch::class]],
639
            ['with_underscore', 'with_underscore'],
640
        ];
641
    }
642
643
    /**
644
     * Test updating Content field value with empty value removes it from search index.
645
     */
646
    public function testRemovedContentFieldValueIsNotFound()
647
    {
648
        $repository = $this->getRepository();
649
        $contentService = $repository->getContentService();
650
        $searchService = $repository->getSearchService();
651
        $publishedContent = $this->createContentWithNameAndDescription('testRemovedContentFieldValueIsNotFound', 'descriptionToBeRemoved', [2]);
652
        $this->refreshSearch($repository);
653
654
        $contentDraft = $contentService->createContentDraft($publishedContent->contentInfo);
655
        $contentUpdateStruct = $contentService->newContentUpdateStruct();
656
        $contentUpdateStruct->setField('description', null);
657
        $contentDraft = $contentService->updateContent($contentDraft->versionInfo, $contentUpdateStruct);
658
        $contentService->publishVersion($contentDraft->versionInfo);
659
        $this->refreshSearch($repository);
660
661
        // Removed field value should not be found
662
        $criterion = new Criterion\FullText('descriptionToBeRemoved');
663
        $query = new Query(['filter' => $criterion]);
664
        $results = $searchService->findContent($query);
665
        $this->assertEquals(0, $results->totalCount);
666
667
        // Should be found
668
        $criterion = new Criterion\FullText('testRemovedContentFieldValueIsNotFound');
669
        $query = new Query(['filter' => $criterion]);
670
        $results = $searchService->findContent($query);
671
        $this->assertEquals(1, $results->totalCount);
672
    }
673
674
    /**
675
     * Check if children locations are/are not ivisible.
676
     *
677
     * @param \eZ\Publish\API\Repository\SearchService $searchService
678
     * @param int $parentLocationId parent location Id
679
     * @param bool $expected expected value of {invisible} property in subtree
680
     */
681
    private function assertSubtreeInvisibleProperty(SearchService $searchService, $parentLocationId, $expected)
682
    {
683
        $criterion = new Criterion\ParentLocationId($parentLocationId);
684
        $query = new LocationQuery(array('filter' => $criterion));
685
        $result = $searchService->findLocations($query);
686
        foreach ($result->searchHits as $searchHit) {
687
            $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...
688
            // Perform recursive check for children locations
689
            $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...
690
        }
691
    }
692
693
    /**
694
     * Test that swapping locations affects properly Search Engine Index.
695
     */
696
    public function testSwapLocation()
697
    {
698
        $repository = $this->getRepository();
699
        $locationService = $repository->getLocationService();
700
        $searchService = $repository->getSearchService();
701
702
        $content01 = $this->createContentWithName('content01', [2]);
703
        $location01 = $locationService->loadLocation($content01->contentInfo->mainLocationId);
704
705
        $content02 = $this->createContentWithName('content02', [2]);
706
        $location02 = $locationService->loadLocation($content02->contentInfo->mainLocationId);
707
708
        $locationService->swapLocation($location01, $location02);
709
        $this->refreshSearch($repository);
710
711
        // content02 should be at location01
712
        $criterion = new Criterion\LocationId($location01->id);
713
        $query = new Query(['filter' => $criterion]);
714
        $results = $searchService->findContent($query);
715
        $this->assertEquals(1, $results->totalCount);
716
        $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...
717
718
        // content01 should be at location02
719
        $criterion = new Criterion\LocationId($location02->id);
720
        $query = new Query(['filter' => $criterion]);
721
        $results = $searchService->findContent($query);
722
        $this->assertEquals(1, $results->totalCount);
723
        $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...
724
    }
725
726
    /**
727
     * Test that updating Content metadata affects properly Search Engine Index.
728
     */
729
    public function testUpdateContentMetadata()
730
    {
731
        $repository = $this->getRepository();
732
        $contentService = $repository->getContentService();
733
        $locationService = $repository->getLocationService();
734
        $searchService = $repository->getSearchService();
735
736
        $publishedContent = $this->createContentWithName('updateMetadataTest', [2]);
737
        $originalMainLocationId = $publishedContent->contentInfo->mainLocationId;
738
        $newLocationCreateStruct = $locationService->newLocationCreateStruct(60);
739
        $newLocation = $locationService->createLocation($publishedContent->contentInfo, $newLocationCreateStruct);
740
741
        $newContentMetadataUpdateStruct = $contentService->newContentMetadataUpdateStruct();
742
        $newContentMetadataUpdateStruct->remoteId = md5('Test');
743
        $newContentMetadataUpdateStruct->publishedDate = new \DateTime();
744
        $newContentMetadataUpdateStruct->publishedDate->add(new \DateInterval('P1D'));
745
        $newContentMetadataUpdateStruct->mainLocationId = $newLocation->id;
746
747
        $contentService->updateContentMetadata($publishedContent->contentInfo, $newContentMetadataUpdateStruct);
748
        $this->refreshSearch($repository);
749
750
        // find Content by Id, calling findContentInfo which is using the Search Index
751
        $criterion = new Criterion\ContentId($publishedContent->id);
752
        $query = new Query(['filter' => $criterion]);
753
        $results = $searchService->findContentInfo($query);
754
        $this->assertEquals(1, $results->totalCount);
755
        $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...
756
757
        // find Content using updated RemoteId
758
        $criterion = new Criterion\RemoteId($newContentMetadataUpdateStruct->remoteId);
759
        $query = new Query(['filter' => $criterion]);
760
        $results = $searchService->findContent($query);
761
        $this->assertEquals(1, $results->totalCount);
762
        $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...
763
        /** @var \eZ\Publish\Core\Repository\Values\Content\Content $foundContentInfo */
764
        $this->assertEquals($publishedContent->id, $foundContentInfo->id);
765
        $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...
766
        $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...
767
        $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...
768
769
        // find Content using old main location
770
        $criterion = new Criterion\LocationId($originalMainLocationId);
771
        $query = new LocationQuery(['filter' => $criterion]);
772
        $results = $searchService->findLocations($query);
773
        $this->assertEquals(1, $results->totalCount);
774
        $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...
775
    }
776
777
    /**
778
     * Test that updating Content Draft metadata does not affect Search Engine Index.
779
     */
780
    public function testUpdateContentDraftMetadataIsNotIndexed()
781
    {
782
        $repository = $this->getRepository();
783
        $contentService = $repository->getContentService();
784
        $locationService = $repository->getLocationService();
785
786
        $testableContentType = $this->createTestContentType();
787
        $rootContentStruct = $contentService->newContentCreateStruct($testableContentType, 'eng-GB');
788
        $rootContentStruct->setField('name', 'TestUpdatingContentDraftMetadata');
789
790
        $contentDraft = $contentService->createContent($rootContentStruct, [$locationService->newLocationCreateStruct(2)]);
791
792
        $newContentMetadataUpdateStruct = $contentService->newContentMetadataUpdateStruct();
793
        $newContentMetadataUpdateStruct->ownerId = 10;
794
        $newContentMetadataUpdateStruct->remoteId = md5('Test');
795
796
        $contentService->updateContentMetadata($contentDraft->contentInfo, $newContentMetadataUpdateStruct);
797
798
        $this->refreshSearch($repository);
799
        $this->assertContentIdSearch($contentDraft->contentInfo->id, 0);
800
    }
801
802
    /**
803
     * Test that assigning section to content object properly affects Search Engine Index.
804
     */
805
    public function testAssignSection()
806
    {
807
        $repository = $this->getRepository();
808
        $sectionService = $repository->getSectionService();
809
        $searchService = $repository->getSearchService();
810
811
        $section = $sectionService->loadSection(2);
812
        $content = $this->createContentWithName('testAssignSection', [2]);
813
814
        $sectionService->assignSection($content->contentInfo, $section);
815
        $this->refreshSearch($repository);
816
817
        $criterion = new Criterion\ContentId($content->id);
818
        $query = new Query(['filter' => $criterion]);
819
        $results = $searchService->findContentInfo($query);
820
        $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...
821
    }
822
823
    /**
824
     * Will create if not exists a simple content type for test purposes with just one required field name.
825
     *
826
     * @return \eZ\Publish\API\Repository\Values\ContentType\ContentType
827
     */
828
    protected function createTestContentType()
829
    {
830
        $repository = $this->getRepository();
831
        $contentTypeService = $repository->getContentTypeService();
832
        $contentTypeIdentifier = 'test-type';
833
        try {
834
            return $contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier);
835
        } catch (NotFoundException $e) {
836
            // continue creation process
837
        }
838
839
        $nameField = $contentTypeService->newFieldDefinitionCreateStruct('name', 'ezstring');
840
        $nameField->fieldGroup = 'main';
841
        $nameField->position = 1;
842
        $nameField->isTranslatable = true;
843
        $nameField->isSearchable = true;
844
        $nameField->isRequired = true;
845
846
        $contentTypeStruct = $contentTypeService->newContentTypeCreateStruct($contentTypeIdentifier);
847
        $contentTypeStruct->mainLanguageCode = 'eng-GB';
848
        $contentTypeStruct->creatorId = 14;
849
        $contentTypeStruct->creationDate = new DateTime();
850
        $contentTypeStruct->names = ['eng-GB' => 'Test Content Type'];
851
        $contentTypeStruct->addFieldDefinition($nameField);
852
853
        $contentTypeGroup = $contentTypeService->loadContentTypeGroupByIdentifier('Content');
854
855
        $contentTypeDraft = $contentTypeService->createContentType($contentTypeStruct, [$contentTypeGroup]);
856
        $contentTypeService->publishContentTypeDraft($contentTypeDraft);
857
858
        return $contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier);
859
    }
860
861
    /**
862
     * Will create and publish an content with a filed with a given content name in location provided into
863
     * $parentLocationIdList.
864
     *
865
     * @param string $contentName
866
     * @param array $parentLocationIdList
867
     *
868
     * @return \eZ\Publish\API\Repository\Values\Content\Content
869
     */
870
    protected function createContentWithName($contentName, array $parentLocationIdList = array())
871
    {
872
        $contentService = $this->getRepository()->getContentService();
873
        $locationService = $this->getRepository()->getLocationService();
874
875
        $testableContentType = $this->createTestContentType();
876
877
        $rootContentStruct = $contentService->newContentCreateStruct($testableContentType, 'eng-GB');
878
        $rootContentStruct->setField('name', $contentName);
879
880
        $parentLocationList = [];
881
        foreach ($parentLocationIdList as $locationID) {
882
            $parentLocationList[] = $locationService->newLocationCreateStruct($locationID);
883
        }
884
885
        $contentDraft = $contentService->createContent($rootContentStruct, $parentLocationList);
886
        $publishedContent = $contentService->publishVersion($contentDraft->getVersionInfo());
887
888
        return $publishedContent;
889
    }
890
891
    /**
892
     * Create and publish a content with filled name and description fields in location provided into
893
     * $parentLocationIdList.
894
     *
895
     * @param string $contentName
896
     * @param $contentDescription
897
     * @param array $parentLocationIdList
898
     *
899
     * @return \eZ\Publish\API\Repository\Values\Content\Content
900
     */
901
    protected function createContentWithNameAndDescription($contentName, $contentDescription, array $parentLocationIdList = [])
902
    {
903
        $repository = $this->getRepository();
904
        $contentService = $repository->getContentService();
905
        $contentTypeService = $repository->getContentTypeService();
906
        $publishedContent = $this->createContentWithName($contentName, $parentLocationIdList);
907
        $descriptionField = $contentTypeService->newFieldDefinitionCreateStruct('description', 'ezstring');
908
        $descriptionField->fieldGroup = 'main';
909
        $descriptionField->position = 2;
910
        $descriptionField->isTranslatable = true;
911
        $descriptionField->isSearchable = true;
912
        $descriptionField->isRequired = false;
913
        $contentType = $contentTypeService->loadContentType($publishedContent->contentInfo->contentTypeId);
914
        $contentTypeDraft = $contentTypeService->createContentTypeDraft($contentType);
915
        $contentTypeService->addFieldDefinition($contentTypeDraft, $descriptionField);
916
        $contentTypeService->publishContentTypeDraft($contentTypeDraft);
917
        $contentDraft = $contentService->createContentDraft($publishedContent->contentInfo);
918
        $contentUpdateStruct = $contentService->newContentUpdateStruct();
919
        $contentUpdateStruct->setField('description', $contentDescription);
920
        $contentDraft = $contentService->updateContent($contentDraft->versionInfo, $contentUpdateStruct);
921
922
        return $contentService->publishVersion($contentDraft->versionInfo);
923
    }
924
925
    /**
926
     * Asserts an content id if it exists still in the solr core.
927
     *
928
     * @param int $contentId
929
     * @param int $expectedCount
930
     */
931
    protected function assertContentIdSearch($contentId, $expectedCount)
932
    {
933
        $searchService = $this->getRepository()->getSearchService();
934
935
        $criterion = new Criterion\ContentId($contentId);
936
        $query = new Query(array('filter' => $criterion));
937
        $result = $searchService->findContent($query);
938
939
        $this->assertEquals($expectedCount, $result->totalCount);
940
        if ($expectedCount == 0) {
941
            return;
942
        }
943
944
        $this->assertEquals(
945
            $contentId,
946
            $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...
947
        );
948
    }
949
950
    /**
951
     * Create & get new Location for tests.
952
     *
953
     * @return \eZ\Publish\API\Repository\Values\Content\Location
954
     */
955
    protected function createNewTestLocation()
956
    {
957
        $repository = $this->getRepository();
958
        $locationService = $repository->getLocationService();
959
        $contentService = $repository->getContentService();
960
961
        $rootLocationId = 2;
962
        $membersContentId = 11;
963
        $membersContentInfo = $contentService->loadContentInfo($membersContentId);
964
965
        $locationCreateStruct = $locationService->newLocationCreateStruct($rootLocationId);
966
967
        return $locationService->createLocation($membersContentInfo, $locationCreateStruct);
968
    }
969
970
    /**
971
     * Test that indexing full text data depends on the isSearchable flag on the field definition.
972
     */
973
    public function testFindContentInfoFullTextIsSearchable()
974
    {
975
        $setupFactory = $this->getSetupFactory();
976
        if (!$setupFactory instanceof LegacySolrSetupFactory && !$setupFactory instanceof LegacyElasticsearch) {
0 ignored issues
show
Bug introduced by
The class EzSystems\EzPlatformSolr...tory\LegacySetupFactory does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
977
            $this->markTestSkipped(
978
                'Legacy Search Engine is missing full text indexing implementation'
979
            );
980
        }
981
982
        $searchTerm = 'pamplemousse';
983
        $content = $this->createFullTextIsSearchableContent($searchTerm, true);
984
985
        $repository = $this->getRepository();
986
        $searchService = $repository->getSearchService();
987
988
        $query = new Query(
989
            [
990
                'query' => new Criterion\FullText($searchTerm),
991
            ]
992
        );
993
994
        $searchResult = $searchService->findContentInfo($query);
995
996
        $this->assertEquals(1, $searchResult->totalCount);
997
        $contentInfo = $searchResult->searchHits[0]->valueObject;
998
        $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...
999
1000
        return $contentInfo;
1001
    }
1002
1003
    /**
1004
     * Test that indexing full text data depends on the isSearchable flag on the field definition.
1005
     *
1006
     * @depends testFindContentInfoFullTextIsSearchable
1007
     *
1008
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
1009
     */
1010
    public function testFindLocationsFullTextIsSearchable(ContentInfo $contentInfo)
1011
    {
1012
        $setupFactory = $this->getSetupFactory();
1013
        if ($setupFactory instanceof LegacyElasticsearchSetupFactory) {
1014
            $this->markTestSkipped(
1015
                'Elasticsearch Search Engine is missing full text Location search implementation'
1016
            );
1017
        }
1018
1019
        $searchTerm = 'pamplemousse';
1020
1021
        $repository = $this->getRepository(false);
1022
        $searchService = $repository->getSearchService();
1023
1024
        $query = new LocationQuery(
1025
            [
1026
                'query' => new Criterion\FullText($searchTerm),
1027
            ]
1028
        );
1029
1030
        $searchResult = $searchService->findLocations($query);
1031
1032
        $this->assertEquals(1, $searchResult->totalCount);
1033
        $this->assertEquals(
1034
            $contentInfo->mainLocationId,
1035
            $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...
1036
        );
1037
    }
1038
1039
    /**
1040
     * Test that indexing full text data depends on the isSearchable flag on the field definition.
1041
     *
1042
     * @depends testFindContentInfoFullTextIsSearchable
1043
     */
1044 View Code Duplication
    public function testFindContentInfoFullTextIsNotSearchable()
1045
    {
1046
        $searchTerm = 'pamplemousse';
1047
        $this->createFullTextIsSearchableContent($searchTerm, false);
1048
1049
        $repository = $this->getRepository();
1050
        $searchService = $repository->getSearchService();
1051
1052
        $query = new Query(
1053
            [
1054
                'query' => new Criterion\FullText($searchTerm),
1055
            ]
1056
        );
1057
1058
        $searchResult = $searchService->findContentInfo($query);
1059
1060
        $this->assertEquals(0, $searchResult->totalCount);
1061
    }
1062
1063
    /**
1064
     * Test that indexing full text data depends on the isSearchable flag on the field definition.
1065
     *
1066
     * @depends testFindLocationsFullTextIsSearchable
1067
     */
1068 View Code Duplication
    public function testFindLocationsFullTextIsNotSearchable()
1069
    {
1070
        $searchTerm = 'pamplemousse';
1071
1072
        $repository = $this->getRepository(false);
1073
        $searchService = $repository->getSearchService();
1074
1075
        $query = new LocationQuery(
1076
            [
1077
                'query' => new Criterion\FullText($searchTerm),
1078
            ]
1079
        );
1080
1081
        $searchResult = $searchService->findLocations($query);
1082
1083
        $this->assertEquals(0, $searchResult->totalCount);
1084
    }
1085
1086
    /**
1087
     * Creates Content for testing full text search depending on the isSearchable flag.
1088
     *
1089
     * @see testFindContentInfoFullTextIsearchable
1090
     * @see testFindLocationsFullTextIsSearchable
1091
     * @see testFindContentInfoFullTextIsNotSearchable
1092
     * @see testFindLocationsFullTextIsNotSearchable
1093
     *
1094
     * @param string $searchText
1095
     * @param bool $isSearchable
1096
     *
1097
     * @return \eZ\Publish\API\Repository\Values\Content\Content
1098
     */
1099
    protected function createFullTextIsSearchableContent($searchText, $isSearchable)
1100
    {
1101
        $repository = $this->getRepository();
1102
        $contentService = $repository->getContentService();
1103
        $contentTypeService = $repository->getContentTypeService();
1104
        $locationService = $repository->getLocationService();
1105
        $contentType = $contentTypeService->loadContentTypeByIdentifier('folder');
1106
1107
        if (!$isSearchable) {
1108
            $contentTypeDraft = $contentTypeService->createContentTypeDraft($contentType);
1109
            $fieldDefinitionUpdateStruct = $contentTypeService->newFieldDefinitionUpdateStruct();
1110
            $fieldDefinitionUpdateStruct->isSearchable = false;
1111
1112
            $fieldDefinition = $contentType->getFieldDefinition('name');
1113
1114
            $contentTypeService->updateFieldDefinition(
1115
                $contentTypeDraft,
1116
                $fieldDefinition,
1117
                $fieldDefinitionUpdateStruct
1118
            );
1119
1120
            $contentTypeService->publishContentTypeDraft($contentTypeDraft);
1121
            $contentType = $contentTypeService->loadContentTypeByIdentifier('folder');
1122
        }
1123
1124
        $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
1125
1126
        $contentCreateStruct->setField('name', $searchText);
1127
        $contentCreateStruct->setField('short_name', 'hello world');
1128
        $content = $contentService->publishVersion(
1129
            $contentService->createContent(
1130
                $contentCreateStruct,
1131
                [$locationService->newLocationCreateStruct(2)]
1132
            )->versionInfo
1133
        );
1134
1135
        $this->refreshSearch($repository);
1136
1137
        return $content;
1138
    }
1139
}
1140