Completed
Push — change-internal-query-parser ( 00dc88 )
by
unknown
16:55 queued 01:20
created

testMatchAllContentInfoQuery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 5

Duplication

Lines 12
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 2
dl 12
loc 12
rs 9.4285
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\LocationQuery;
11
use eZ\Publish\API\Repository\Values\Content\Query;
12
use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
13
14
/**
15
 * This test will try to execute search queries that might be interpreted as "pure negative"
16
 * by the search backend and hence produce incorrect results.
17
 *
18
 * @group regression
19
 */
20
class PureNegativeQueryTest extends BaseTest
21
{
22
    public function providerForTestMatchAll()
23
    {
24
        $query = new Query(['filter' => new Criterion\MatchAll()]);
25
        $result = $this->getRepository()->getSearchService()->findContent($query);
26
        // Sanity check
27
        $this->assertGreaterThan(0, $result->totalCount);
28
        $totalCount = $result->totalCount;
29
        $contentId = 12;
30
31
        return [
32
            [
33
                new Criterion\LogicalOr(
34
                    [
35
                        new Criterion\ContentId($contentId),
36
                        new Criterion\LogicalNot(
37
                            new Criterion\ContentId($contentId)
38
                        ),
39
                    ]
40
                ),
41
                $totalCount,
42
            ],
43
            [
44
                new Criterion\LogicalOr(
45
                    [
46
47
                        new Criterion\ContentId($contentId),
48
                        new Criterion\LogicalNot(
49
                            new Criterion\LogicalNot(
50
                                new Criterion\ContentId($contentId)
51
                            )
52
                        ),
53
                    ]
54
                ),
55
                1,
56
            ],
57
            [
58
                new Criterion\LogicalOr(
59
                    [
60
                        new Criterion\LogicalNot(
61
                            new Criterion\ContentId($contentId)
62
                        ),
63
                        new Criterion\LogicalNot(
64
                            new Criterion\LogicalNot(
65
                                new Criterion\ContentId($contentId)
66
                            )
67
                        ),
68
                    ]
69
                ),
70
                $totalCount,
71
            ],
72
            [
73
                new Criterion\LogicalOr(
74
                    [
75
                        new Criterion\LogicalNot(
76
                            new Criterion\ContentId($contentId)
77
                        ),
78
                        new Criterion\LogicalNot(
79
                            new Criterion\ContentId($contentId)
80
                        ),
81
                    ]
82
                ),
83
                $totalCount - 1,
84
            ],
85
86
            [
87
                new Criterion\LogicalAnd(
88
                    [
89
                        new Criterion\ContentId($contentId),
90
                        new Criterion\LogicalNot(
91
                            new Criterion\ContentId($contentId)
92
                        ),
93
                    ]
94
                ),
95
                0,
96
            ],
97
            [
98
                new Criterion\LogicalAnd(
99
                    [
100
101
                        new Criterion\ContentId($contentId),
102
                        new Criterion\LogicalNot(
103
                            new Criterion\LogicalNot(
104
                                new Criterion\ContentId($contentId)
105
                            )
106
                        ),
107
                    ]
108
                ),
109
                1,
110
            ],
111
            [
112
                new Criterion\LogicalAnd(
113
                    [
114
                        new Criterion\LogicalNot(
115
                            new Criterion\ContentId($contentId)
116
                        ),
117
                        new Criterion\LogicalNot(
118
                            new Criterion\LogicalNot(
119
                                new Criterion\ContentId($contentId)
120
                            )
121
                        ),
122
                    ]
123
                ),
124
                0,
125
            ],
126
            [
127
                new Criterion\LogicalAnd(
128
                    [
129
                        new Criterion\LogicalNot(
130
                            new Criterion\ContentId($contentId)
131
                        ),
132
                        new Criterion\LogicalNot(
133
                            new Criterion\ContentId($contentId)
134
                        ),
135
                    ]
136
                ),
137
                $totalCount - 1,
138
            ],
139
        ];
140
    }
141
142
    /**
143
     * @dataProvider providerForTestMatchAll
144
     *
145
     * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion
146
     * @param int $totalCount
147
     */
148 View Code Duplication
    public function testMatchAllContentInfoQuery($criterion, $totalCount)
149
    {
150
        $query = new Query(
151
            [
152
                'query' => $criterion,
153
            ]
154
        );
155
156
        $result = $this->getRepository()->getSearchService()->findContentInfo($query);
157
158
        $this->assertEquals($totalCount, $result->totalCount);
159
    }
160
161
    /**
162
     * @dataProvider providerForTestMatchAll
163
     *
164
     * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion
165
     * @param int $totalCount
166
     */
167 View Code Duplication
    public function testMatchAllContentInfoFilter($criterion, $totalCount)
168
    {
169
        $query = new Query(
170
            [
171
                'filter' => $criterion,
172
            ]
173
        );
174
175
        $result = $this->getRepository()->getSearchService()->findContentInfo($query);
176
177
        $this->assertEquals($totalCount, $result->totalCount);
178
    }
179
180
    /**
181
     * @dataProvider providerForTestMatchAll
182
     *
183
     * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion
184
     * @param int $totalCount
185
     */
186 View Code Duplication
    public function testMatchAllLocationQuery($criterion, $totalCount)
187
    {
188
        $query = new LocationQuery(
189
            [
190
                'query' => $criterion,
191
            ]
192
        );
193
194
        $result = $this->getRepository()->getSearchService()->findLocations($query);
195
196
        $this->assertEquals($totalCount, $result->totalCount);
197
    }
198
199
    /**
200
     * @dataProvider providerForTestMatchAll
201
     *
202
     * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion
203
     * @param int $totalCount
204
     */
205 View Code Duplication
    public function testMatchAllLocationFilter($criterion, $totalCount)
206
    {
207
        $query = new LocationQuery(
208
            [
209
                'filter' => $criterion,
210
            ]
211
        );
212
213
        $result = $this->getRepository()->getSearchService()->findLocations($query);
214
215
        $this->assertEquals($totalCount, $result->totalCount);
216
    }
217
}
218