Completed
Push — search_feature_flags ( f33631...aaf89e )
by André
90:30 queued 69:00
created

PureNegativeQueryTest::providerForTestMatchAll()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 192
Code Lines 89

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 89
nc 1
nop 0
dl 0
loc 192
rs 8.2857
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
                        new Criterion\ContentId($contentId),
175
                        new Criterion\LogicalNot(
176
                            new Criterion\LogicalNot(
177
                                new Criterion\ContentId($contentId)
178
                            )
179
                        ),
180
                    ]
181
                ),
182
                1,
183
            ],
184
            [
185
                new Criterion\LogicalAnd(
186
                    [
187
                        new Criterion\LogicalNot(
188
                            new Criterion\ContentId($contentId)
189
                        ),
190
                        new Criterion\LogicalNot(
191
                            new Criterion\LogicalNot(
192
                                new Criterion\ContentId($contentId)
193
                            )
194
                        ),
195
                    ]
196
                ),
197
                0,
198
            ],
199
            [
200
                new Criterion\LogicalAnd(
201
                    [
202
                        new Criterion\LogicalNot(
203
                            new Criterion\ContentId($contentId)
204
                        ),
205
                        new Criterion\LogicalNot(
206
                            new Criterion\ContentId($contentId)
207
                        ),
208
                    ]
209
                ),
210
                $totalCount - 1,
211
            ],
212
        ];
213
    }
214
215
    /**
216
     * @dataProvider providerForTestMatchAll
217
     *
218
     * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion
219
     * @param int $totalCount
220
     */
221 View Code Duplication
    public function testMatchAllContentInfoQuery($criterion, $totalCount)
222
    {
223
        $query = new Query(
224
            [
225
                'query' => $criterion,
226
            ]
227
        );
228
229
        $result = $this->getRepository()->getSearchService()->findContentInfo($query);
230
231
        $this->assertEquals($totalCount, $result->totalCount);
232
    }
233
234
    /**
235
     * @dataProvider providerForTestMatchAll
236
     *
237
     * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion
238
     * @param int $totalCount
239
     */
240 View Code Duplication
    public function testMatchAllContentInfoFilter($criterion, $totalCount)
241
    {
242
        $query = new Query(
243
            [
244
                'filter' => $criterion,
245
            ]
246
        );
247
248
        $result = $this->getRepository()->getSearchService()->findContentInfo($query);
249
250
        $this->assertEquals($totalCount, $result->totalCount);
251
    }
252
253
    /**
254
     * @dataProvider providerForTestMatchAll
255
     *
256
     * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion
257
     * @param int $totalCount
258
     */
259 View Code Duplication
    public function testMatchAllLocationQuery($criterion, $totalCount)
260
    {
261
        $query = new LocationQuery(
262
            [
263
                'query' => $criterion,
264
            ]
265
        );
266
267
        $result = $this->getRepository()->getSearchService()->findLocations($query);
268
269
        $this->assertEquals($totalCount, $result->totalCount);
270
    }
271
272
    /**
273
     * @dataProvider providerForTestMatchAll
274
     *
275
     * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion
276
     * @param int $totalCount
277
     */
278 View Code Duplication
    public function testMatchAllLocationFilter($criterion, $totalCount)
279
    {
280
        $query = new LocationQuery(
281
            [
282
                'filter' => $criterion,
283
            ]
284
        );
285
286
        $result = $this->getRepository()->getSearchService()->findLocations($query);
287
288
        $this->assertEquals($totalCount, $result->totalCount);
289
    }
290
}
291