Completed
Push — feature-EZP-25696 ( 5c8491...b810c8 )
by André
11: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\MatchNone(),
37
                    ]
38
                ),
39
                1,
40
            ],
41
            [
42
                new Criterion\LogicalAnd(
43
                    [
44
                        new Criterion\ContentId($contentId),
45
                        new Criterion\MatchNone(),
46
                    ]
47
                ),
48
                0,
49
            ],
50
            [
51
                new Criterion\LogicalOr(
52
                    [
53
                        new Criterion\ContentId($contentId),
54
                        new Criterion\LogicalNot(
55
                            new Criterion\MatchAll()
56
                        ),
57
                    ]
58
                ),
59
                1,
60
            ],
61
            [
62
                new Criterion\LogicalAnd(
63
                    [
64
                        new Criterion\ContentId($contentId),
65
                        new Criterion\LogicalNot(
66
                            new Criterion\MatchAll()
67
                        ),
68
                    ]
69
                ),
70
                0,
71
            ],
72
            [
73
                new Criterion\LogicalOr(
74
                    [
75
                        new Criterion\ContentId($contentId),
76
                        new Criterion\MatchAll(),
77
                    ]
78
                ),
79
                $totalCount,
80
            ],
81
            [
82
                new Criterion\LogicalAnd(
83
                    [
84
                        new Criterion\ContentId($contentId),
85
                        new Criterion\MatchAll(),
86
                    ]
87
                ),
88
                1,
89
            ],
90
            [
91
                new Criterion\LogicalOr(
92
                    [
93
                        new Criterion\MatchAll(),
94
                        new Criterion\MatchNone(),
95
                    ]
96
                ),
97
                $totalCount,
98
            ],
99
            [
100
                new Criterion\LogicalAnd(
101
                    [
102
                        new Criterion\MatchAll(),
103
                        new Criterion\MatchNone(),
104
                    ]
105
                ),
106
                0,
107
            ],
108
            [
109
                new Criterion\LogicalOr(
110
                    [
111
                        new Criterion\ContentId($contentId),
112
                        new Criterion\LogicalNot(
113
                            new Criterion\ContentId($contentId)
114
                        ),
115
                    ]
116
                ),
117
                $totalCount,
118
            ],
119
            [
120
                new Criterion\LogicalOr(
121
                    [
122
                        new Criterion\ContentId($contentId),
123
                        new Criterion\LogicalNot(
124
                            new Criterion\LogicalNot(
125
                                new Criterion\ContentId($contentId)
126
                            )
127
                        ),
128
                    ]
129
                ),
130
                1,
131
            ],
132
            [
133
                new Criterion\LogicalOr(
134
                    [
135
                        new Criterion\LogicalNot(
136
                            new Criterion\ContentId($contentId)
137
                        ),
138
                        new Criterion\LogicalNot(
139
                            new Criterion\LogicalNot(
140
                                new Criterion\ContentId($contentId)
141
                            )
142
                        ),
143
                    ]
144
                ),
145
                $totalCount,
146
            ],
147
            [
148
                new Criterion\LogicalOr(
149
                    [
150
                        new Criterion\LogicalNot(
151
                            new Criterion\ContentId($contentId)
152
                        ),
153
                        new Criterion\LogicalNot(
154
                            new Criterion\ContentId($contentId)
155
                        ),
156
                    ]
157
                ),
158
                $totalCount - 1,
159
            ],
160
            [
161
                new Criterion\LogicalAnd(
162
                    [
163
                        new Criterion\ContentId($contentId),
164
                        new Criterion\LogicalNot(
165
                            new Criterion\ContentId($contentId)
166
                        ),
167
                    ]
168
                ),
169
                0,
170
            ],
171
            [
172
                new Criterion\LogicalAnd(
173
                    [
174
175
                        new Criterion\ContentId($contentId),
176
                        new Criterion\LogicalNot(
177
                            new Criterion\LogicalNot(
178
                                new Criterion\ContentId($contentId)
179
                            )
180
                        ),
181
                    ]
182
                ),
183
                1,
184
            ],
185
            [
186
                new Criterion\LogicalAnd(
187
                    [
188
                        new Criterion\LogicalNot(
189
                            new Criterion\ContentId($contentId)
190
                        ),
191
                        new Criterion\LogicalNot(
192
                            new Criterion\LogicalNot(
193
                                new Criterion\ContentId($contentId)
194
                            )
195
                        ),
196
                    ]
197
                ),
198
                0,
199
            ],
200
            [
201
                new Criterion\LogicalAnd(
202
                    [
203
                        new Criterion\LogicalNot(
204
                            new Criterion\ContentId($contentId)
205
                        ),
206
                        new Criterion\LogicalNot(
207
                            new Criterion\ContentId($contentId)
208
                        ),
209
                    ]
210
                ),
211
                $totalCount - 1,
212
            ],
213
        ];
214
    }
215
216
    /**
217
     * @dataProvider providerForTestMatchAll
218
     *
219
     * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion
220
     * @param int $totalCount
221
     */
222 View Code Duplication
    public function testMatchAllContentInfoQuery($criterion, $totalCount)
223
    {
224
        $query = new Query(
225
            [
226
                'query' => $criterion,
227
            ]
228
        );
229
230
        $result = $this->getRepository()->getSearchService()->findContentInfo($query);
231
232
        $this->assertEquals($totalCount, $result->totalCount);
233
    }
234
235
    /**
236
     * @dataProvider providerForTestMatchAll
237
     *
238
     * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion
239
     * @param int $totalCount
240
     */
241 View Code Duplication
    public function testMatchAllContentInfoFilter($criterion, $totalCount)
242
    {
243
        $query = new Query(
244
            [
245
                'filter' => $criterion,
246
            ]
247
        );
248
249
        $result = $this->getRepository()->getSearchService()->findContentInfo($query);
250
251
        $this->assertEquals($totalCount, $result->totalCount);
252
    }
253
254
    /**
255
     * @dataProvider providerForTestMatchAll
256
     *
257
     * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion
258
     * @param int $totalCount
259
     */
260 View Code Duplication
    public function testMatchAllLocationQuery($criterion, $totalCount)
261
    {
262
        $query = new LocationQuery(
263
            [
264
                'query' => $criterion,
265
            ]
266
        );
267
268
        $result = $this->getRepository()->getSearchService()->findLocations($query);
269
270
        $this->assertEquals($totalCount, $result->totalCount);
271
    }
272
273
    /**
274
     * @dataProvider providerForTestMatchAll
275
     *
276
     * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion
277
     * @param int $totalCount
278
     */
279 View Code Duplication
    public function testMatchAllLocationFilter($criterion, $totalCount)
280
    {
281
        $query = new LocationQuery(
282
            [
283
                'filter' => $criterion,
284
            ]
285
        );
286
287
        $result = $this->getRepository()->getSearchService()->findLocations($query);
288
289
        $this->assertEquals($totalCount, $result->totalCount);
290
    }
291
}
292