Completed
Push — master ( 8f089d...5e6645 )
by André
74:40 queued 48:55
created

SearchEngineIndexingTest   C

Complexity

Total Complexity 4

Size/Duplication

Total Lines 181
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 22

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 181
rs 5.7894
wmc 4
lcom 1
cbo 22

4 Methods

Rating   Name   Duplication   Size   Complexity  
B testCreateLocation() 0 26 1
A testMoveSubtree() 0 60 1
A testIndexContentWithNullField() 0 52 1
B testUpdateLocation() 0 33 1
1
<?php
2
3
/**
4
 * This file is part of the eZ Publish Kernel package.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 *
9
 * @version //autogentag//
10
 */
11
namespace eZ\Publish\API\Repository\Tests;
12
13
use eZ\Publish\API\Repository\Values\Content\LocationQuery;
14
use eZ\Publish\API\Repository\Values\Content\Query;
15
use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
16
use DateTime;
17
18
/**
19
 * Test case for indexing operations with a search engine.
20
 *
21
 * @group integration
22
 * @group search
23
 * @group indexing
24
 */
25
class SearchEngineIndexingTest extends BaseTest
26
{
27
    public function testCreateLocation()
28
    {
29
        $repository = $this->getRepository();
30
        $locationService = $repository->getLocationService();
31
        $contentService = $repository->getContentService();
32
        $searchService = $repository->getSearchService();
33
34
        $rootLocationId = 2;
35
        $membersContentId = 11;
36
        $membersContentInfo = $contentService->loadContentInfo($membersContentId);
37
38
        $locationCreateStruct = $locationService->newLocationCreateStruct($rootLocationId);
39
        $membersLocation = $locationService->createLocation($membersContentInfo, $locationCreateStruct);
40
41
        $this->refreshSearch($repository);
42
43
        // Found
44
        $criterion = new Criterion\LocationId($membersLocation->id);
45
        $query = new LocationQuery(array('filter' => $criterion));
46
        $result = $searchService->findLocations($query);
47
        $this->assertEquals(1, $result->totalCount);
48
        $this->assertEquals(
49
            $membersLocation->id,
50
            $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...
51
        );
52
    }
53
54
    public function testMoveSubtree()
55
    {
56
        $repository = $this->getRepository();
57
        $locationService = $repository->getLocationService();
58
        $contentService = $repository->getContentService();
59
        $searchService = $repository->getSearchService();
60
61
        $rootLocationId = 2;
62
        $membersContentId = 11;
63
        $adminsContentId = 12;
64
        $editorsContentId = 13;
65
        $membersContentInfo = $contentService->loadContentInfo($membersContentId);
66
        $adminsContentInfo = $contentService->loadContentInfo($adminsContentId);
67
        $editorsContentInfo = $contentService->loadContentInfo($editorsContentId);
68
69
        $locationCreateStruct = $locationService->newLocationCreateStruct($rootLocationId);
70
        $membersLocation = $locationService->createLocation($membersContentInfo, $locationCreateStruct);
71
        $editorsLocation = $locationService->createLocation($editorsContentInfo, $locationCreateStruct);
72
        $adminsLocation = $locationService->createLocation(
73
            $adminsContentInfo,
74
            $locationService->newLocationCreateStruct($membersLocation->id)
75
        );
76
77
        $this->refreshSearch($repository);
78
79
        // Not found under Editors
80
        $criterion = new Criterion\ParentLocationId($editorsLocation->id);
81
        $query = new LocationQuery(array('filter' => $criterion));
82
        $result = $searchService->findLocations($query);
83
        $this->assertEquals(0, $result->totalCount);
84
85
        // Found under Members
86
        $criterion = new Criterion\ParentLocationId($membersLocation->id);
87
        $query = new LocationQuery(array('filter' => $criterion));
88
        $result = $searchService->findLocations($query);
89
        $this->assertEquals(1, $result->totalCount);
90
        $this->assertEquals(
91
            $adminsLocation->id,
92
            $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...
93
        );
94
95
        $locationService->moveSubtree($adminsLocation, $editorsLocation);
96
        $this->refreshSearch($repository);
97
98
        // Found under Editors
99
        $criterion = new Criterion\ParentLocationId($editorsLocation->id);
100
        $query = new LocationQuery(array('filter' => $criterion));
101
        $result = $searchService->findLocations($query);
102
        $this->assertEquals(1, $result->totalCount);
103
        $this->assertEquals(
104
            $adminsLocation->id,
105
            $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...
106
        );
107
108
        // Not found under Members
109
        $criterion = new Criterion\ParentLocationId($membersLocation->id);
110
        $query = new LocationQuery(array('filter' => $criterion));
111
        $result = $searchService->findLocations($query);
112
        $this->assertEquals(0, $result->totalCount);
113
    }
114
115
    /**
116
     * Testing that content is indexed even when containing only fields with values
117
     * considered to be empty by the search engine.
118
     */
119
    public function testIndexContentWithNullField()
120
    {
121
        $repository = $this->getRepository();
122
        $contentService = $repository->getContentService();
123
        $contentTypeService = $repository->getContentTypeService();
124
        $searchService = $repository->getSearchService();
125
126
        $createStruct = $contentTypeService->newContentTypeCreateStruct('test-type');
127
        $createStruct->mainLanguageCode = 'eng-GB';
128
        $createStruct->names = array('eng-GB' => 'Test type');
129
        $createStruct->creatorId = 14;
130
        $createStruct->creationDate = new DateTime();
131
132
        $translatableFieldCreate = $contentTypeService->newFieldDefinitionCreateStruct(
133
            'integer',
134
            'ezinteger'
135
        );
136
        $translatableFieldCreate->names = array('eng-GB' => 'Simple translatable integer field');
137
        $translatableFieldCreate->fieldGroup = 'main';
138
        $translatableFieldCreate->position = 1;
139
        $translatableFieldCreate->isTranslatable = true;
140
        $translatableFieldCreate->isSearchable = true;
141
142
        $createStruct->addFieldDefinition($translatableFieldCreate);
143
144
        $contentGroup = $contentTypeService->loadContentTypeGroupByIdentifier('Content');
145
        $contentTypeDraft = $contentTypeService->createContentType(
146
            $createStruct,
147
            array($contentGroup)
148
        );
149
        $contentTypeService->publishContentTypeDraft($contentTypeDraft);
150
        $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...
151
152
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
153
        $createStruct->alwaysAvailable = false;
154
        $createStruct->mainLanguageCode = 'eng-GB';
155
156
        $draft = $contentService->createContent($createStruct);
157
        $content = $contentService->publishVersion($draft->getVersionInfo());
158
159
        $this->refreshSearch($repository);
160
161
        // Found
162
        $criterion = new Criterion\ContentId($content->id);
163
        $query = new Query(array('filter' => $criterion));
164
        $result = $searchService->findContent($query);
165
        $this->assertEquals(1, $result->totalCount);
166
        $this->assertEquals(
167
            $content->id,
168
            $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...
169
        );
170
    }
171
172
    public function testUpdateLocation()
173
    {
174
        $repository = $this->getRepository();
175
        $locationService = $repository->getLocationService();
176
        $searchService = $repository->getSearchService();
177
178
        $rootLocationId = 2;
179
        $locationToUpdate = $locationService->loadLocation($rootLocationId);
180
181
        $criterion = new Criterion\LogicalAnd([
182
            new Criterion\LocationId($rootLocationId),
183
            new Criterion\Location\Priority(Criterion\Operator::GT, 0),
184
        ]);
185
186
        $query = new LocationQuery(array('filter' => $criterion));
187
        $result = $searchService->findLocations($query);
188
189
        $this->assertEquals(0, $result->totalCount);
190
191
        $locationUpdateStruct = $locationService->newLocationUpdateStruct();
192
        $locationUpdateStruct->priority = 4;
193
        $locationService->updateLocation($locationToUpdate, $locationUpdateStruct);
194
195
        $this->refreshSearch($repository);
196
197
        $result = $searchService->findLocations($query);
198
199
        $this->assertEquals(1, $result->totalCount);
200
        $this->assertEquals(
201
            $locationToUpdate->id,
202
            $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...
203
        );
204
    }
205
}
206