1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
5
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
6
|
|
|
*/ |
7
|
|
|
namespace eZ\Publish\API\Repository\Tests\Regression; |
8
|
|
|
|
9
|
|
|
use eZ\Publish\API\Repository\Tests\BaseTest; |
10
|
|
|
use eZ\Publish\API\Repository\Values\Content\Query; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @link https://jira.ez.no/browse/EZP-28799 |
14
|
|
|
*/ |
15
|
|
|
class EZP28799SubtreeSearchTest extends BaseTest |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Content[] |
19
|
|
|
*/ |
20
|
|
|
public function createTestContent() |
21
|
|
|
{ |
22
|
|
|
$rootLocationId = 2; |
23
|
|
|
$contentService = $this->getRepository()->getContentService(); |
24
|
|
|
$contentTypeService = $this->getRepository()->getContentTypeService(); |
25
|
|
|
$locationService = $this->getRepository()->getLocationService(); |
26
|
|
|
|
27
|
|
|
$contentType = $contentTypeService->loadContentTypeByIdentifier('folder'); |
28
|
|
|
$locationCreateStruct = $locationService->newLocationCreateStruct($rootLocationId); |
29
|
|
|
|
30
|
|
|
$contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
31
|
|
|
$contentCreateStruct->setField('name', 'LEFT'); |
32
|
|
|
|
33
|
|
|
$draft = $contentService->createContent($contentCreateStruct, [$locationCreateStruct]); |
34
|
|
|
$leftFolder = $contentService->publishVersion($draft->versionInfo); |
35
|
|
|
|
36
|
|
|
$contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
37
|
|
|
$contentCreateStruct->setField('name', 'RIGHT'); |
38
|
|
|
|
39
|
|
|
$draft = $contentService->createContent($contentCreateStruct, [$locationCreateStruct]); |
40
|
|
|
$rightFolder = $contentService->publishVersion($draft->versionInfo); |
41
|
|
|
|
42
|
|
|
$contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
43
|
|
|
$contentCreateStruct->setField('name', 'TARGET'); |
44
|
|
|
|
45
|
|
|
$locationCreateStructLeft = $locationService->newLocationCreateStruct( |
46
|
|
|
$leftFolder->contentInfo->mainLocationId |
47
|
|
|
); |
48
|
|
|
$locationCreateStructRight = $locationService->newLocationCreateStruct( |
49
|
|
|
$rightFolder->contentInfo->mainLocationId |
50
|
|
|
); |
51
|
|
|
$draft = $contentService->createContent( |
52
|
|
|
$contentCreateStruct, |
53
|
|
|
[ |
54
|
|
|
$locationCreateStructLeft, |
55
|
|
|
$locationCreateStructRight, |
56
|
|
|
] |
57
|
|
|
); |
58
|
|
|
$targetFolder = $contentService->publishVersion($draft->versionInfo); |
59
|
|
|
|
60
|
|
|
return [$leftFolder, $rightFolder, $targetFolder]; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
View Code Duplication |
public function testConflictingConditions() |
64
|
|
|
{ |
65
|
|
|
list($leftFolder, $rightFolder, $targetFolder) = $this->createTestContent(); |
|
|
|
|
66
|
|
|
$locationService = $this->getRepository()->getLocationService(); |
67
|
|
|
$leftLocation = $locationService->loadLocation($leftFolder->contentInfo->mainLocationId); |
68
|
|
|
|
69
|
|
|
$query = new Query([ |
70
|
|
|
'filter' => new Query\Criterion\LogicalAnd([ |
71
|
|
|
new Query\Criterion\ContentId($targetFolder->contentInfo->id), |
72
|
|
|
new Query\Criterion\Subtree($leftLocation->pathString), |
73
|
|
|
new Query\Criterion\LogicalNot( |
74
|
|
|
new Query\Criterion\Subtree($leftLocation->pathString) |
75
|
|
|
), |
76
|
|
|
]), |
77
|
|
|
]); |
78
|
|
|
|
79
|
|
|
$searchService = $this->getRepository()->getSearchService(); |
80
|
|
|
$result = $searchService->findContent($query); |
81
|
|
|
|
82
|
|
|
$this->assertSame(0, $result->totalCount); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
View Code Duplication |
public function testNegativeSubtree() |
86
|
|
|
{ |
87
|
|
|
list($leftFolder, $rightFolder, $targetFolder) = $this->createTestContent(); |
|
|
|
|
88
|
|
|
$locationService = $this->getRepository()->getLocationService(); |
89
|
|
|
$leftLocation = $locationService->loadLocation($leftFolder->contentInfo->mainLocationId); |
90
|
|
|
|
91
|
|
|
$query = new Query([ |
92
|
|
|
'filter' => new Query\Criterion\LogicalAnd([ |
93
|
|
|
new Query\Criterion\ContentId($targetFolder->contentInfo->id), |
94
|
|
|
new Query\Criterion\LogicalNot( |
95
|
|
|
new Query\Criterion\Subtree($leftLocation->pathString) |
96
|
|
|
), |
97
|
|
|
]), |
98
|
|
|
]); |
99
|
|
|
|
100
|
|
|
$searchService = $this->getRepository()->getSearchService(); |
101
|
|
|
$result = $searchService->findContent($query); |
102
|
|
|
|
103
|
|
|
$this->assertSame(0, $result->totalCount); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
This checks looks for assignemnts to variables using the
list(...)
function, where not all assigned variables are subsequently used.Consider the following code example.
Only the variables
$a
and$c
are used. There was no need to assign$b
.Instead, the list call could have been.