Completed
Push — ezp24624-query_controller_take... ( f346e1...647162 )
by
unknown
23:39
created

HandlerContentTest   F

Complexity

Total Complexity 78

Size/Duplication

Total Lines 1495
Duplicated Lines 36.72 %

Coupling/Cohesion

Components 2
Dependencies 74

Importance

Changes 0
Metric Value
dl 549
loc 1495
rs 0.5217
c 0
b 0
f 0
wmc 78
lcom 2
cbo 74

72 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 10 10 2
A assertSearchResults() 13 13 1
B getContentSearchHandler() 0 141 1
A getContentTypeHandler() 15 15 2
A getConverterRegistry() 19 19 2
B getContentMapperMock() 32 32 3
A getContentFieldHandlerMock() 0 10 1
A testFindWithoutOffsetLimit() 0 17 1
A testFindWithZeroLimit() 0 23 1
A testFindWithNullLimit() 23 23 1
A testFindWithOffsetToNonexistent() 23 23 1
A testFindSingle() 0 8 1
A testFindSingleWithNonSearchableField() 0 11 1
A testFindContentWithNonSearchableField() 16 16 1
A testFindSingleTooMany() 0 5 1
A testFindSingleZero() 0 5 1
A testContentIdFilter() 0 16 1
A testContentIdFilterCount() 0 17 1
A testContentAndCombinatorFilter() 0 23 1
B testContentOrCombinatorFilter() 0 35 2
B testContentNotCombinatorFilter() 0 25 1
A testContentSubtreeFilterIn() 16 16 1
A testContentSubtreeFilterEq() 14 14 1
A testContentTypeIdFilter() 14 14 1
A testContentTypeIdentifierFilter() 0 15 1
A testContentTypeGroupFilter() 14 14 1
A testDateMetadataFilterModifiedGreater() 0 18 1
A testDateMetadataFilterModifiedGreaterOrEqual() 0 18 1
A testDateMetadataFilterModifiedIn() 0 18 1
A testDateMetadataFilterModifiedBetween() 0 18 1
A testDateMetadataFilterCreatedBetween() 0 18 1
A testLocationIdFilter() 0 14 1
A testParentLocationIdFilter() 0 14 1
A testRemoteIdFilter() 0 16 1
A testLocationRemoteIdFilter() 0 16 1
A testSectionFilter() 14 14 1
B testStatusFilter() 0 25 1
A testFieldFilter() 0 18 1
A testFieldFilterIn() 0 18 1
A testFieldFilterContainsPartial() 0 18 1
A testFieldFilterContainsSimple() 0 18 1
A testFieldFilterContainsSimpleNoMatch() 0 18 1
A testFieldFilterBetween() 0 18 1
B testFieldFilterOr() 27 27 1
A testFullTextFilter() 14 14 1
A testFullTextWildcardFilter() 14 14 1
A testFullTextDisabledWildcardFilter() 16 16 1
A testFullTextFilterStopwordRemoval() 20 20 1
B testFullTextFilterNoStopwordRemoval() 31 31 1
A testFullTextFilterInvalidStopwordThreshold() 0 8 1
A testObjectStateIdFilter() 0 15 1
A testObjectStateIdFilterIn() 0 15 1
A testLanguageCodeFilter() 0 15 1
A testLanguageCodeFilterIn() 0 15 1
A testLanguageCodeFilterWithAlwaysAvailable() 15 15 1
A testVisibilityFilter() 0 17 1
A testUserMetadataFilterOwnerWrongUserId() 17 17 1
A testUserMetadataFilterOwnerAdministrator() 19 19 1
A testUserMetadataFilterOwnerEqAMember() 17 17 1
A testUserMetadataFilterOwnerInAMember() 17 17 1
A testUserMetadataFilterCreatorEqAMember() 17 17 1
A testUserMetadataFilterCreatorInAMember() 17 17 1
A testUserMetadataFilterEqGroupMember() 17 17 1
A testUserMetadataFilterInGroupMember() 17 17 1
A testUserMetadataFilterEqGroupMemberNoMatch() 17 17 1
A testUserMetadataFilterInGroupMemberNoMatch() 17 17 1
A testFieldRelationFilterContainsSingle() 0 17 1
A testFieldRelationFilterContainsSingleNoMatch() 17 17 1
A testFieldRelationFilterContainsArray() 0 17 1
A testFieldRelationFilterContainsArrayNotMatch() 0 17 1
A testFieldRelationFilterInArray() 0 17 1
A testFieldRelationFilterInArrayNotMatch() 0 17 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like HandlerContentTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use HandlerContentTest, and based on these observations, apply Extract Interface, too.

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\Core\Search\Legacy\Tests\Content;
12
13
use eZ\Publish\Core\Persistence\Legacy\Tests\Content\LanguageAwareTestCase;
14
use eZ\Publish\Core\Persistence;
15
use eZ\Publish\Core\Search\Legacy\Content;
16
use eZ\Publish\Core\Persistence\Legacy\Content\Type\Handler as ContentTypeHandler;
17
use eZ\Publish\Core\Persistence\Legacy\Content\Type\Mapper as ContentTypeMapper;
18
use eZ\Publish\API\Repository\Values\Content\Query;
19
use eZ\Publish\API\Repository\Values\Content\Query\SortClause;
20
use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
21
use eZ\Publish\SPI\Persistence\Content\ContentInfo;
22
use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter;
23
use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\ConverterRegistry;
24
use eZ\Publish\Core\Persistence\Legacy\Content\Type\Gateway\DoctrineDatabase as ContentTypeGateway;
25
26
/**
27
 * Content Search test case for ContentSearchHandler.
28
 */
29
class HandlerContentTest extends LanguageAwareTestCase
30
{
31
    protected static $setUp = false;
32
33
    /**
34
     * Field registry mock.
35
     *
36
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\ConverterRegistry
37
     */
38
    protected $fieldRegistry;
39
40
    /**
41
     * Only set up once for these read only tests on a large fixture.
42
     *
43
     * Skipping the reset-up, since setting up for these tests takes quite some
44
     * time, which is not required to spent, since we are only reading from the
45
     * database anyways.
46
     */
47 View Code Duplication
    public function setUp()
48
    {
49
        if (!self::$setUp) {
50
            parent::setUp();
51
            $this->insertDatabaseFixture(__DIR__ . '/../_fixtures/full_dump.php');
52
            self::$setUp = $this->handler;
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->handler of type object<eZ\Publish\Core\P...tabase\DatabaseHandler> is incompatible with the declared type boolean of property $setUp.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
53
        } else {
54
            $this->handler = self::$setUp;
0 ignored issues
show
Documentation Bug introduced by
It seems like self::$setUp of type boolean is incompatible with the declared type object<eZ\Publish\Core\P...tabase\DatabaseHandler> of property $handler.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
55
        }
56
    }
57
58
    /**
59
     * Assert that the elements are.
60
     */
61 View Code Duplication
    protected function assertSearchResults($expectedIds, $searchResult)
62
    {
63
        $result = array_map(
64
            function ($hit) {
65
                return $hit->valueObject->id;
66
            },
67
            $searchResult->searchHits
68
        );
69
70
        sort($result);
71
72
        $this->assertEquals($expectedIds, $result);
73
    }
74
75
    /**
76
     * Returns the content search handler to test.
77
     *
78
     * This method returns a fully functional search handler to perform tests
79
     * on.
80
     *
81
     * @param array $fullTextSearchConfiguration
82
     *
83
     * @return \eZ\Publish\Core\Search\Legacy\Content\Handler
84
     */
85
    protected function getContentSearchHandler(array $fullTextSearchConfiguration = array())
86
    {
87
        $transformationProcessor = new Persistence\TransformationProcessor\DefinitionBased(
88
            new Persistence\TransformationProcessor\DefinitionBased\Parser(),
89
            new Persistence\TransformationProcessor\PcreCompiler(
90
                new Persistence\Utf8Converter()
91
            ),
92
            glob(__DIR__ . '/../../../../Persistence/Tests/TransformationProcessor/_fixtures/transformations/*.tr')
93
        );
94
        $commaSeparatedCollectionValueHandler = new Content\Common\Gateway\CriterionHandler\FieldValue\Handler\Collection(
95
            $this->getDatabaseHandler(),
96
            $transformationProcessor,
97
            ','
98
        );
99
        $hyphenSeparatedCollectionValueHandler = new Content\Common\Gateway\CriterionHandler\FieldValue\Handler\Collection(
100
            $this->getDatabaseHandler(),
101
            $transformationProcessor,
102
            '-'
103
        );
104
        $simpleValueHandler = new Content\Common\Gateway\CriterionHandler\FieldValue\Handler\Simple(
105
            $this->getDatabaseHandler(),
106
            $transformationProcessor
107
        );
108
        $compositeValueHandler = new Content\Common\Gateway\CriterionHandler\FieldValue\Handler\Composite(
109
            $this->getDatabaseHandler(),
110
            $transformationProcessor
111
        );
112
113
        return new Content\Handler(
114
            new Content\Gateway\DoctrineDatabase(
115
                $this->getDatabaseHandler(),
116
                new Content\Common\Gateway\CriteriaConverter(
117
                    array(
118
                        new Content\Common\Gateway\CriterionHandler\ContentId(
119
                            $this->getDatabaseHandler()
120
                        ),
121
                        new Content\Common\Gateway\CriterionHandler\LogicalNot(
122
                            $this->getDatabaseHandler()
123
                        ),
124
                        new Content\Common\Gateway\CriterionHandler\LogicalAnd(
125
                            $this->getDatabaseHandler()
126
                        ),
127
                        new Content\Common\Gateway\CriterionHandler\LogicalOr(
128
                            $this->getDatabaseHandler()
129
                        ),
130
                        new Content\Gateway\CriterionHandler\Subtree(
131
                            $this->getDatabaseHandler()
132
                        ),
133
                        new Content\Common\Gateway\CriterionHandler\ContentTypeId(
134
                            $this->getDatabaseHandler()
135
                        ),
136
                        new Content\Common\Gateway\CriterionHandler\ContentTypeIdentifier(
137
                            $this->getDatabaseHandler(),
138
                            $this->getContentTypeHandler()
139
                        ),
140
                        new Content\Common\Gateway\CriterionHandler\ContentTypeGroupId(
141
                            $this->getDatabaseHandler()
142
                        ),
143
                        new Content\Common\Gateway\CriterionHandler\DateMetadata(
144
                            $this->getDatabaseHandler()
145
                        ),
146
                        new Content\Gateway\CriterionHandler\LocationId(
147
                            $this->getDatabaseHandler()
148
                        ),
149
                        new Content\Gateway\CriterionHandler\ParentLocationId(
150
                            $this->getDatabaseHandler()
151
                        ),
152
                        new Content\Common\Gateway\CriterionHandler\RemoteId(
153
                            $this->getDatabaseHandler()
154
                        ),
155
                        new Content\Gateway\CriterionHandler\LocationRemoteId(
156
                            $this->getDatabaseHandler()
157
                        ),
158
                        new Content\Common\Gateway\CriterionHandler\SectionId(
159
                            $this->getDatabaseHandler()
160
                        ),
161
                        new Content\Common\Gateway\CriterionHandler\FullText(
162
                            $this->getDatabaseHandler(),
163
                            $transformationProcessor,
164
                            $fullTextSearchConfiguration
165
                        ),
166
                        new Content\Common\Gateway\CriterionHandler\Field(
167
                            $this->getDatabaseHandler(),
168
                            $this->getContentTypeHandler(),
169
                            $this->getLanguageHandler(),
170
                            $this->getConverterRegistry(),
171
                            new Content\Common\Gateway\CriterionHandler\FieldValue\Converter(
172
                                new Content\Common\Gateway\CriterionHandler\FieldValue\HandlerRegistry(
173
                                    array(
174
                                        'ezboolean' => $simpleValueHandler,
175
                                        'ezcountry' => $commaSeparatedCollectionValueHandler,
176
                                        'ezdate' => $simpleValueHandler,
177
                                        'ezdatetime' => $simpleValueHandler,
178
                                        'ezemail' => $simpleValueHandler,
179
                                        'ezinteger' => $simpleValueHandler,
180
                                        'ezobjectrelation' => $simpleValueHandler,
181
                                        'ezobjectrelationlist' => $commaSeparatedCollectionValueHandler,
182
                                        'ezselection' => $hyphenSeparatedCollectionValueHandler,
183
                                        'eztime' => $simpleValueHandler,
184
                                    )
185
                                ),
186
                                $compositeValueHandler
187
                            ),
188
                            $transformationProcessor
189
                        ),
190
                        new Content\Common\Gateway\CriterionHandler\ObjectStateId(
191
                            $this->getDatabaseHandler()
192
                        ),
193
                        new Content\Common\Gateway\CriterionHandler\LanguageCode(
194
                            $this->getDatabaseHandler(),
195
                            $this->getLanguageMaskGenerator()
196
                        ),
197
                        new Content\Gateway\CriterionHandler\Visibility(
198
                            $this->getDatabaseHandler()
199
                        ),
200
                        new Content\Common\Gateway\CriterionHandler\MatchAll(
201
                            $this->getDatabaseHandler()
202
                        ),
203
                        new Content\Common\Gateway\CriterionHandler\UserMetadata(
204
                            $this->getDatabaseHandler()
205
                        ),
206
                        new Content\Common\Gateway\CriterionHandler\FieldRelation(
207
                            $this->getDatabaseHandler(),
208
                            $this->getContentTypeHandler(),
209
                            $this->getLanguageHandler()
210
                        ),
211
                    )
212
                ),
213
                new Content\Common\Gateway\SortClauseConverter(
214
                    array(
215
                        new Content\Common\Gateway\SortClauseHandler\ContentId($this->getDatabaseHandler()),
216
                    )
217
                ),
218
                $this->getLanguageHandler()
219
            ),
220
            $this->getMock('eZ\\Publish\\Core\\Search\\Legacy\\Content\\Location\\Gateway'),
221
            $this->getContentMapperMock(),
222
            $this->getMock('eZ\\Publish\\Core\\Persistence\\Legacy\\Content\\Location\\Mapper'),
223
            $this->getLanguageHandler()
224
        );
225
    }
226
227
    protected $contentTypeHandler;
228
229 View Code Duplication
    protected function getContentTypeHandler()
230
    {
231
        if (!isset($this->contentTypeHandler)) {
232
            $this->contentTypeHandler = new ContentTypeHandler(
233
                new ContentTypeGateway(
234
                    $this->getDatabaseHandler(),
235
                    $this->getLanguageMaskGenerator()
236
                ),
237
                new ContentTypeMapper($this->getConverterRegistry()),
238
                $this->getMock('eZ\\Publish\\Core\\Persistence\\Legacy\\Content\\Type\\Update\\Handler')
239
            );
240
        }
241
242
        return $this->contentTypeHandler;
243
    }
244
245 View Code Duplication
    protected function getConverterRegistry()
246
    {
247
        if (!isset($this->fieldRegistry)) {
248
            $this->fieldRegistry = new ConverterRegistry(
249
                array(
250
                    'ezdatetime' => new Converter\DateAndTimeConverter(),
251
                    'ezinteger' => new Converter\IntegerConverter(),
252
                    'ezstring' => new Converter\TextLineConverter(),
253
                    'ezprice' => new Converter\IntegerConverter(),
254
                    'ezurl' => new Converter\UrlConverter(),
255
                    'ezrichtext' => new Converter\RichTextConverter(),
256
                    'ezboolean' => new Converter\CheckboxConverter(),
257
                    'ezkeyword' => new Converter\KeywordConverter(),
258
                )
259
            );
260
        }
261
262
        return $this->fieldRegistry;
263
    }
264
265
    /**
266
     * Returns a content mapper mock.
267
     *
268
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Mapper
269
     */
270 View Code Duplication
    protected function getContentMapperMock()
271
    {
272
        $mapperMock = $this->getMock(
273
            'eZ\\Publish\\Core\\Persistence\\Legacy\\Content\\Mapper',
274
            array('extractContentInfoFromRows'),
275
            array(
276
                $this->fieldRegistry,
277
                $this->getLanguageHandler(),
278
            )
279
        );
280
        $mapperMock->expects($this->any())
281
            ->method('extractContentInfoFromRows')
282
            ->with($this->isType('array'))
283
            ->will(
284
                $this->returnCallback(
285
                    function ($rows) {
286
                        $contentInfoObjs = array();
287
                        foreach ($rows as $row) {
288
                            $contentId = (int)$row['id'];
289
                            if (!isset($contentInfoObjs[$contentId])) {
290
                                $contentInfoObjs[$contentId] = new ContentInfo();
291
                                $contentInfoObjs[$contentId]->id = $contentId;
292
                            }
293
                        }
294
295
                        return array_values($contentInfoObjs);
296
                    }
297
                )
298
            );
299
300
        return $mapperMock;
301
    }
302
303
    /**
304
     * Returns a content field handler mock.
305
     *
306
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\FieldHandler
307
     */
308
    protected function getContentFieldHandlerMock()
309
    {
310
        return $this->getMock(
311
            'eZ\\Publish\\Core\\Persistence\\Legacy\\Content\\FieldHandler',
312
            array('loadExternalFieldData'),
313
            array(),
314
            '',
315
            false
316
        );
317
    }
318
319
    /**
320
     * Bug #80.
321
     */
322
    public function testFindWithoutOffsetLimit()
323
    {
324
        $locator = $this->getContentSearchHandler();
325
326
        $result = $locator->findContent(
327
            new Query(
328
                array(
329
                    'filter' => new Criterion\ContentId(10),
330
                )
331
            )
332
        );
333
334
        $this->assertEquals(
335
            1,
336
            $result->totalCount
337
        );
338
    }
339
340
    /**
341
     * Bug #81, bug #82.
342
     */
343
    public function testFindWithZeroLimit()
344
    {
345
        $locator = $this->getContentSearchHandler();
346
347
        $result = $locator->findContent(
348
            new Query(
349
                array(
350
                    'filter' => new Criterion\ContentId(10),
351
                    'offset' => 0,
352
                    'limit' => 0,
353
                )
354
            )
355
        );
356
357
        $this->assertEquals(
358
            1,
359
            $result->totalCount
360
        );
361
        $this->assertEquals(
362
            array(),
363
            $result->searchHits
364
        );
365
    }
366
367
    /**
368
     * Issue with PHP_MAX_INT limit overflow in databases.
369
     */
370 View Code Duplication
    public function testFindWithNullLimit()
371
    {
372
        $locator = $this->getContentSearchHandler();
373
374
        $result = $locator->findContent(
375
            new Query(
376
                array(
377
                    'filter' => new Criterion\ContentId(10),
378
                    'offset' => 0,
379
                    'limit' => null,
380
                )
381
            )
382
        );
383
384
        $this->assertEquals(
385
            1,
386
            $result->totalCount
387
        );
388
        $this->assertEquals(
389
            1,
390
            count($result->searchHits)
391
        );
392
    }
393
394
    /**
395
     * Issue with offsetting to the nonexistent results produces \ezcQueryInvalidParameterException exception.
396
     */
397 View Code Duplication
    public function testFindWithOffsetToNonexistent()
398
    {
399
        $locator = $this->getContentSearchHandler();
400
401
        $result = $locator->findContent(
402
            new Query(
403
                array(
404
                    'filter' => new Criterion\ContentId(10),
405
                    'offset' => 1000,
406
                    'limit' => null,
407
                )
408
            )
409
        );
410
411
        $this->assertEquals(
412
            1,
413
            $result->totalCount
414
        );
415
        $this->assertEquals(
416
            0,
417
            count($result->searchHits)
418
        );
419
    }
420
421
    public function testFindSingle()
422
    {
423
        $locator = $this->getContentSearchHandler();
424
425
        $contentInfo = $locator->findSingle(new Criterion\ContentId(10));
426
427
        $this->assertEquals(10, $contentInfo->id);
428
    }
429
430
    /**
431
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
432
     */
433
    public function testFindSingleWithNonSearchableField()
434
    {
435
        $locator = $this->getContentSearchHandler();
436
        $locator->findSingle(
437
            new Criterion\Field(
438
                'tag_cloud_url',
439
                Criterion\Operator::EQ,
440
                'http://nimbus.com'
441
            )
442
        );
443
    }
444
445
    /**
446
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
447
     */
448 View Code Duplication
    public function testFindContentWithNonSearchableField()
449
    {
450
        $locator = $this->getContentSearchHandler();
451
        $locator->findContent(
452
            new Query(
453
                array(
454
                    'filter' => new Criterion\Field(
455
                        'tag_cloud_url',
456
                        Criterion\Operator::EQ,
457
                        'http://nimbus.com'
458
                    ),
459
                    'sortClauses' => array(new SortClause\ContentId()),
460
                )
461
            )
462
        );
463
    }
464
465
    /**
466
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
467
     */
468
    public function testFindSingleTooMany()
469
    {
470
        $locator = $this->getContentSearchHandler();
471
        $locator->findSingle(new Criterion\ContentId(array(4, 10, 12, 23)));
472
    }
473
474
    /**
475
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
476
     */
477
    public function testFindSingleZero()
478
    {
479
        $locator = $this->getContentSearchHandler();
480
        $locator->findSingle(new Criterion\ContentId(0));
481
    }
482
483
    public function testContentIdFilter()
484
    {
485
        $this->assertSearchResults(
486
            array(4, 10),
487
            $this->getContentSearchHandler()->findContent(
488
                new Query(
489
                    array(
490
                        'filter' => new Criterion\ContentId(
491
                            array(1, 4, 10)
492
                        ),
493
                        'limit' => 10,
494
                    )
495
                )
496
            )
497
        );
498
    }
499
500
    public function testContentIdFilterCount()
501
    {
502
        $locator = $this->getContentSearchHandler();
503
504
        $result = $locator->findContent(
505
            new Query(
506
                array(
507
                    'filter' => new Criterion\ContentId(
508
                        array(1, 4, 10)
509
                    ),
510
                    'limit' => 10,
511
                )
512
            )
513
        );
514
515
        $this->assertSame(2, $result->totalCount);
516
    }
517
518
    public function testContentAndCombinatorFilter()
519
    {
520
        $this->assertSearchResults(
521
            array(4),
522
            $this->getContentSearchHandler()->findContent(
523
                new Query(
524
                    array(
525
                        'filter' => new Criterion\LogicalAnd(
526
                            array(
527
                                new Criterion\ContentId(
528
                                    array(1, 4, 10)
529
                                ),
530
                                new Criterion\ContentId(
531
                                    array(4, 12)
532
                                ),
533
                            )
534
                        ),
535
                        'limit' => 10,
536
                    )
537
                )
538
            )
539
        );
540
    }
541
542
    public function testContentOrCombinatorFilter()
543
    {
544
        $locator = $this->getContentSearchHandler();
545
546
        $result = $locator->findContent(
547
            new Query(
548
                array(
549
                    'filter' => new Criterion\LogicalOr(
550
                        array(
551
                            new Criterion\ContentId(
552
                                array(1, 4, 10)
553
                            ),
554
                            new Criterion\ContentId(
555
                                array(4, 12)
556
                            ),
557
                        )
558
                    ),
559
                    'limit' => 10,
560
                )
561
            )
562
        );
563
564
        $expectedContentIds = array(4, 10, 12);
565
566
        $this->assertEquals(
567
            count($expectedContentIds),
568
            count($result->searchHits)
569
        );
570
        foreach ($result->searchHits as $hit) {
571
            $this->assertContains(
572
                $hit->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...
573
                $expectedContentIds
574
            );
575
        }
576
    }
577
578
    public function testContentNotCombinatorFilter()
579
    {
580
        $this->assertSearchResults(
581
            array(4),
582
            $this->getContentSearchHandler()->findContent(
583
                new Query(
584
                    array(
585
                        'filter' => new Criterion\LogicalAnd(
586
                            array(
587
                                new Criterion\ContentId(
588
                                    array(1, 4, 10)
589
                                ),
590
                                new Criterion\LogicalNot(
591
                                    new Criterion\ContentId(
592
                                        array(10, 12)
593
                                    )
594
                                ),
595
                            )
596
                        ),
597
                        'limit' => 10,
598
                    )
599
                )
600
            )
601
        );
602
    }
603
604 View Code Duplication
    public function testContentSubtreeFilterIn()
605
    {
606
        $this->assertSearchResults(
607
            array(67, 68, 69, 70, 71, 72, 73, 74),
608
            $this->getContentSearchHandler()->findContent(
609
                new Query(
610
                    array(
611
                        'filter' => new Criterion\Subtree(
612
                            array('/1/2/69/')
613
                        ),
614
                        'limit' => 10,
615
                    )
616
                )
617
            )
618
        );
619
    }
620
621 View Code Duplication
    public function testContentSubtreeFilterEq()
622
    {
623
        $this->assertSearchResults(
624
            array(67, 68, 69, 70, 71, 72, 73, 74),
625
            $this->getContentSearchHandler()->findContent(
626
                new Query(
627
                    array(
628
                        'filter' => new Criterion\Subtree('/1/2/69/'),
629
                        'limit' => 10,
630
                    )
631
                )
632
            )
633
        );
634
    }
635
636 View Code Duplication
    public function testContentTypeIdFilter()
637
    {
638
        $this->assertSearchResults(
639
            array(10, 14, 226),
640
            $this->getContentSearchHandler()->findContent(
641
                new Query(
642
                    array(
643
                        'filter' => new Criterion\ContentTypeId(4),
644
                        'limit' => 10,
645
                    )
646
                )
647
            )
648
        );
649
    }
650
651
    public function testContentTypeIdentifierFilter()
652
    {
653
        $this->assertSearchResults(
654
            array(41, 45, 49, 50, 51),
655
            $this->getContentSearchHandler()->findContent(
656
                new Query(
657
                    array(
658
                        'filter' => new Criterion\ContentTypeIdentifier('folder'),
659
                        'limit' => 5,
660
                        'sortClauses' => array(new SortClause\ContentId()),
661
                    )
662
                )
663
            )
664
        );
665
    }
666
667 View Code Duplication
    public function testContentTypeGroupFilter()
668
    {
669
        $this->assertSearchResults(
670
            array(4, 10, 11, 12, 13, 14, 42, 225, 226),
671
            $this->getContentSearchHandler()->findContent(
672
                new Query(
673
                    array(
674
                        'filter' => new Criterion\ContentTypeGroupId(2),
675
                        'limit' => 10,
676
                    )
677
                )
678
            )
679
        );
680
    }
681
682
    public function testDateMetadataFilterModifiedGreater()
683
    {
684
        $this->assertSearchResults(
685
            array(11, 225, 226),
686
            $this->getContentSearchHandler()->findContent(
687
                new Query(
688
                    array(
689
                        'filter' => new Criterion\DateMetadata(
690
                            Criterion\DateMetadata::MODIFIED,
691
                            Criterion\Operator::GT,
692
                            1311154214
693
                        ),
694
                        'limit' => 10,
695
                    )
696
                )
697
            )
698
        );
699
    }
700
701
    public function testDateMetadataFilterModifiedGreaterOrEqual()
702
    {
703
        $this->assertSearchResults(
704
            array(11, 14, 225, 226),
705
            $this->getContentSearchHandler()->findContent(
706
                new Query(
707
                    array(
708
                        'filter' => new Criterion\DateMetadata(
709
                            Criterion\DateMetadata::MODIFIED,
710
                            Criterion\Operator::GTE,
711
                            1311154214
712
                        ),
713
                        'limit' => 10,
714
                    )
715
                )
716
            )
717
        );
718
    }
719
720
    public function testDateMetadataFilterModifiedIn()
721
    {
722
        $this->assertSearchResults(
723
            array(11, 14, 225, 226),
724
            $this->getContentSearchHandler()->findContent(
725
                new Query(
726
                    array(
727
                        'filter' => new Criterion\DateMetadata(
728
                            Criterion\DateMetadata::MODIFIED,
729
                            Criterion\Operator::IN,
730
                            array(1311154214, 1311154215)
731
                        ),
732
                        'limit' => 10,
733
                    )
734
                )
735
            )
736
        );
737
    }
738
739
    public function testDateMetadataFilterModifiedBetween()
740
    {
741
        $this->assertSearchResults(
742
            array(11, 14, 225, 226),
743
            $this->getContentSearchHandler()->findContent(
744
                new Query(
745
                    array(
746
                        'filter' => new Criterion\DateMetadata(
747
                            Criterion\DateMetadata::MODIFIED,
748
                            Criterion\Operator::BETWEEN,
749
                            array(1311154213, 1311154215)
750
                        ),
751
                        'limit' => 10,
752
                    )
753
                )
754
            )
755
        );
756
    }
757
758
    public function testDateMetadataFilterCreatedBetween()
759
    {
760
        $this->assertSearchResults(
761
            array(66, 131, 225),
762
            $this->getContentSearchHandler()->findContent(
763
                new Query(
764
                    array(
765
                        'filter' => new Criterion\DateMetadata(
766
                            Criterion\DateMetadata::CREATED,
767
                            Criterion\Operator::BETWEEN,
768
                            array(1299780749, 1311154215)
769
                        ),
770
                        'limit' => 10,
771
                    )
772
                )
773
            )
774
        );
775
    }
776
777
    public function testLocationIdFilter()
778
    {
779
        $this->assertSearchResults(
780
            array(4, 65),
781
            $this->getContentSearchHandler()->findContent(
782
                new Query(
783
                    array(
784
                        'filter' => new Criterion\LocationId(array(1, 2, 5)),
785
                        'limit' => 10,
786
                    )
787
                )
788
            )
789
        );
790
    }
791
792
    public function testParentLocationIdFilter()
793
    {
794
        $this->assertSearchResults(
795
            array(4, 41, 45, 56, 65),
796
            $this->getContentSearchHandler()->findContent(
797
                new Query(
798
                    array(
799
                        'filter' => new Criterion\ParentLocationId(array(1)),
800
                        'limit' => 10,
801
                    )
802
                )
803
            )
804
        );
805
    }
806
807
    public function testRemoteIdFilter()
808
    {
809
        $this->assertSearchResults(
810
            array(4, 10),
811
            $this->getContentSearchHandler()->findContent(
812
                new Query(
813
                    array(
814
                        'filter' => new Criterion\RemoteId(
815
                            array('f5c88a2209584891056f987fd965b0ba', 'faaeb9be3bd98ed09f606fc16d144eca')
816
                        ),
817
                        'limit' => 10,
818
                    )
819
                )
820
            )
821
        );
822
    }
823
824
    public function testLocationRemoteIdFilter()
825
    {
826
        $this->assertSearchResults(
827
            array(4, 65),
828
            $this->getContentSearchHandler()->findContent(
829
                new Query(
830
                    array(
831
                        'filter' => new Criterion\LocationRemoteId(
832
                            array('3f6d92f8044aed134f32153517850f5a', 'f3e90596361e31d496d4026eb624c983')
833
                        ),
834
                        'limit' => 10,
835
                    )
836
                )
837
            )
838
        );
839
    }
840
841 View Code Duplication
    public function testSectionFilter()
842
    {
843
        $this->assertSearchResults(
844
            array(4, 10, 11, 12, 13, 14, 42, 226),
845
            $this->getContentSearchHandler()->findContent(
846
                new Query(
847
                    array(
848
                        'filter' => new Criterion\SectionId(array(2)),
849
                        'limit' => 10,
850
                    )
851
                )
852
            )
853
        );
854
    }
855
856
    public function testStatusFilter()
857
    {
858
        $this->assertSearchResults(
859
            array(4, 10, 11, 12, 13, 14, 41, 42, 45, 49),
860
            $searchResult = $this->getContentSearchHandler()->findContent(
861
                new Query(
862
                    array(
863
                        // Status criterion is gone, but this will also match all published
864
                        'filter' => new Criterion\LogicalNot(
865
                            new Criterion\ContentId(
866
                                array(0)
867
                            )
868
                        ),
869
                        'limit' => 10,
870
                        'sortClauses' => array(new SortClause\ContentId()),
871
                    )
872
                )
873
            )
874
        );
875
876
        $this->assertEquals(
877
            185,
878
            $searchResult->totalCount
879
        );
880
    }
881
882
    public function testFieldFilter()
883
    {
884
        $this->assertSearchResults(
885
            array(11),
886
            $this->getContentSearchHandler()->findContent(
887
                new Query(
888
                    array(
889
                        'filter' => new Criterion\Field(
890
                            'name',
891
                            Criterion\Operator::EQ,
892
                            'members'
893
                        ),
894
                        'limit' => 10,
895
                    )
896
                )
897
            )
898
        );
899
    }
900
901
    public function testFieldFilterIn()
902
    {
903
        $this->assertSearchResults(
904
            array(11, 42),
905
            $this->getContentSearchHandler()->findContent(
906
                new Query(
907
                    array(
908
                        'filter' => new Criterion\Field(
909
                            'name',
910
                            Criterion\Operator::IN,
911
                            array('members', 'anonymous users')
912
                        ),
913
                        'limit' => 10,
914
                    )
915
                )
916
            )
917
        );
918
    }
919
920
    public function testFieldFilterContainsPartial()
921
    {
922
        $this->assertSearchResults(
923
            array(42),
924
            $this->getContentSearchHandler()->findContent(
925
                new Query(
926
                    array(
927
                        'filter' => new Criterion\Field(
928
                            'name',
929
                            Criterion\Operator::CONTAINS,
930
                            'nonymous use'
931
                        ),
932
                        'limit' => 10,
933
                    )
934
                )
935
            )
936
        );
937
    }
938
939
    public function testFieldFilterContainsSimple()
940
    {
941
        $this->assertSearchResults(
942
            array(77),
943
            $this->getContentSearchHandler()->findContent(
944
                new Query(
945
                    array(
946
                        'filter' => new Criterion\Field(
947
                            'publish_date',
948
                            Criterion\Operator::CONTAINS,
949
                            1174643880
950
                        ),
951
                        'limit' => 10,
952
                    )
953
                )
954
            )
955
        );
956
    }
957
958
    public function testFieldFilterContainsSimpleNoMatch()
959
    {
960
        $this->assertSearchResults(
961
            array(),
962
            $this->getContentSearchHandler()->findContent(
963
                new Query(
964
                    array(
965
                        'filter' => new Criterion\Field(
966
                            'publish_date',
967
                            Criterion\Operator::CONTAINS,
968
                            1174643
969
                        ),
970
                        'limit' => 10,
971
                    )
972
                )
973
            )
974
        );
975
    }
976
977
    public function testFieldFilterBetween()
978
    {
979
        $this->assertSearchResults(
980
            array(69, 71, 72),
981
            $this->getContentSearchHandler()->findContent(
982
                new Query(
983
                    array(
984
                        'filter' => new Criterion\Field(
985
                            'price',
986
                            Criterion\Operator::BETWEEN,
987
                            array(10000, 1000000)
988
                        ),
989
                        'limit' => 10,
990
                    )
991
                )
992
            )
993
        );
994
    }
995
996 View Code Duplication
    public function testFieldFilterOr()
997
    {
998
        $this->assertSearchResults(
999
            array(11, 69, 71, 72),
1000
            $this->getContentSearchHandler()->findContent(
1001
                new Query(
1002
                    array(
1003
                        'filter' => new Criterion\LogicalOr(
1004
                            array(
1005
                                new Criterion\Field(
1006
                                    'name',
1007
                                    Criterion\Operator::EQ,
1008
                                    'members'
1009
                                ),
1010
                                new Criterion\Field(
1011
                                    'price',
1012
                                    Criterion\Operator::BETWEEN,
1013
                                    array(10000, 1000000)
1014
                                ),
1015
                            )
1016
                        ),
1017
                        'limit' => 10,
1018
                    )
1019
                )
1020
            )
1021
        );
1022
    }
1023
1024 View Code Duplication
    public function testFullTextFilter()
1025
    {
1026
        $this->assertSearchResults(
1027
            array(191),
1028
            $this->getContentSearchHandler()->findContent(
1029
                new Query(
1030
                    array(
1031
                        'filter' => new Criterion\FullText('applied webpage'),
1032
                        'limit' => 10,
1033
                    )
1034
                )
1035
            )
1036
        );
1037
    }
1038
1039 View Code Duplication
    public function testFullTextWildcardFilter()
1040
    {
1041
        $this->assertSearchResults(
1042
            array(191),
1043
            $this->getContentSearchHandler()->findContent(
1044
                new Query(
1045
                    array(
1046
                        'filter' => new Criterion\FullText('applie*'),
1047
                        'limit' => 10,
1048
                    )
1049
                )
1050
            )
1051
        );
1052
    }
1053
1054 View Code Duplication
    public function testFullTextDisabledWildcardFilter()
1055
    {
1056
        $this->assertSearchResults(
1057
            array(),
1058
            $this->getContentSearchHandler(
1059
                array('enableWildcards' => false)
1060
            )->findContent(
1061
                new Query(
1062
                    array(
1063
                        'filter' => new Criterion\FullText('applie*'),
1064
                        'limit' => 10,
1065
                    )
1066
                )
1067
            )
1068
        );
1069
    }
1070
1071 View Code Duplication
    public function testFullTextFilterStopwordRemoval()
1072
    {
1073
        $handler = $this->getContentSearchHandler(
1074
            array(
1075
                'stopWordThresholdFactor' => 0.1,
1076
            )
1077
        );
1078
1079
        $this->assertSearchResults(
1080
            array(),
1081
            $handler->findContent(
1082
                new Query(
1083
                    array(
1084
                        'filter' => new Criterion\FullText('the'),
1085
                        'limit' => 10,
1086
                    )
1087
                )
1088
            )
1089
        );
1090
    }
1091
1092 View Code Duplication
    public function testFullTextFilterNoStopwordRemoval()
1093
    {
1094
        $handler = $this->getContentSearchHandler(
1095
            array(
1096
                'stopWordThresholdFactor' => 1,
1097
            )
1098
        );
1099
1100
        $result = $handler->findContent(
1101
            new Query(
1102
                array(
1103
                    'filter' => new Criterion\FullText(
1104
                        'the'
1105
                    ),
1106
                    'limit' => 10,
1107
                )
1108
            )
1109
        );
1110
1111
        $this->assertEquals(
1112
            10,
1113
            count(
1114
                array_map(
1115
                    function ($hit) {
1116
                        return $hit->valueObject->id;
1117
                    },
1118
                    $result->searchHits
1119
                )
1120
            )
1121
        );
1122
    }
1123
1124
    /**
1125
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1126
     */
1127
    public function testFullTextFilterInvalidStopwordThreshold()
1128
    {
1129
        $this->getContentSearchHandler(
1130
            array(
1131
                'stopWordThresholdFactor' => 2,
1132
            )
1133
        );
1134
    }
1135
1136
    public function testObjectStateIdFilter()
1137
    {
1138
        $this->assertSearchResults(
1139
            array(4, 10, 11, 12, 13, 14, 41, 42, 45, 49),
1140
            $this->getContentSearchHandler()->findContent(
1141
                new Query(
1142
                    array(
1143
                        'filter' => new Criterion\ObjectStateId(1),
1144
                        'limit' => 10,
1145
                        'sortClauses' => array(new SortClause\ContentId()),
1146
                    )
1147
                )
1148
            )
1149
        );
1150
    }
1151
1152
    public function testObjectStateIdFilterIn()
1153
    {
1154
        $this->assertSearchResults(
1155
            array(4, 10, 11, 12, 13, 14, 41, 42, 45, 49),
1156
            $this->getContentSearchHandler()->findContent(
1157
                new Query(
1158
                    array(
1159
                        'filter' => new Criterion\ObjectStateId(array(1, 2)),
1160
                        'limit' => 10,
1161
                        'sortClauses' => array(new SortClause\ContentId()),
1162
                    )
1163
                )
1164
            )
1165
        );
1166
    }
1167
1168
    public function testLanguageCodeFilter()
1169
    {
1170
        $this->assertSearchResults(
1171
            array(4, 10, 11, 12, 13, 14, 41, 42, 45, 49),
1172
            $this->getContentSearchHandler()->findContent(
1173
                new Query(
1174
                    array(
1175
                        'filter' => new Criterion\LanguageCode('eng-US'),
1176
                        'limit' => 10,
1177
                        'sortClauses' => array(new SortClause\ContentId()),
1178
                    )
1179
                )
1180
            )
1181
        );
1182
    }
1183
1184
    public function testLanguageCodeFilterIn()
1185
    {
1186
        $this->assertSearchResults(
1187
            array(4, 10, 11, 12, 13, 14, 41, 42, 45, 49),
1188
            $this->getContentSearchHandler()->findContent(
1189
                new Query(
1190
                    array(
1191
                        'filter' => new Criterion\LanguageCode(array('eng-US', 'eng-GB')),
1192
                        'limit' => 10,
1193
                        'sortClauses' => array(new SortClause\ContentId()),
1194
                    )
1195
                )
1196
            )
1197
        );
1198
    }
1199
1200 View Code Duplication
    public function testLanguageCodeFilterWithAlwaysAvailable()
1201
    {
1202
        $this->assertSearchResults(
1203
            array(4, 10, 11, 12, 13, 14, 41, 42, 45, 49, 50, 51, 56, 57, 65, 68, 70, 74, 76, 80),
1204
            $this->getContentSearchHandler()->findContent(
1205
                new Query(
1206
                    array(
1207
                        'filter' => new Criterion\LanguageCode('eng-GB', true),
1208
                        'limit' => 20,
1209
                        'sortClauses' => array(new SortClause\ContentId()),
1210
                    )
1211
                )
1212
            )
1213
        );
1214
    }
1215
1216
    public function testVisibilityFilter()
1217
    {
1218
        $this->assertSearchResults(
1219
            array(4, 10, 11, 12, 13, 14, 41, 42, 45, 49),
1220
            $this->getContentSearchHandler()->findContent(
1221
                new Query(
1222
                    array(
1223
                        'filter' => new Criterion\Visibility(
1224
                            Criterion\Visibility::VISIBLE
1225
                        ),
1226
                        'limit' => 10,
1227
                        'sortClauses' => array(new SortClause\ContentId()),
1228
                    )
1229
                )
1230
            )
1231
        );
1232
    }
1233
1234 View Code Duplication
    public function testUserMetadataFilterOwnerWrongUserId()
1235
    {
1236
        $this->assertSearchResults(
1237
            array(),
1238
            $this->getContentSearchHandler()->findContent(
1239
                new Query(
1240
                    array(
1241
                        'filter' => new Criterion\UserMetadata(
1242
                            Criterion\UserMetadata::OWNER,
1243
                            Criterion\Operator::EQ,
1244
                            2
1245
                        ),
1246
                    )
1247
                )
1248
            )
1249
        );
1250
    }
1251
1252 View Code Duplication
    public function testUserMetadataFilterOwnerAdministrator()
1253
    {
1254
        $this->assertSearchResults(
1255
            array(4, 10, 11, 12, 13, 14, 41, 42, 45, 49),
1256
            $this->getContentSearchHandler()->findContent(
1257
                new Query(
1258
                    array(
1259
                        'filter' => new Criterion\UserMetadata(
1260
                            Criterion\UserMetadata::OWNER,
1261
                            Criterion\Operator::EQ,
1262
                            14
1263
                        ),
1264
                        'limit' => 10,
1265
                        'sortClauses' => array(new SortClause\ContentId()),
1266
                    )
1267
                )
1268
            )
1269
        );
1270
    }
1271
1272 View Code Duplication
    public function testUserMetadataFilterOwnerEqAMember()
1273
    {
1274
        $this->assertSearchResults(
1275
            array(223),
1276
            $this->getContentSearchHandler()->findContent(
1277
                new Query(
1278
                    array(
1279
                        'filter' => new Criterion\UserMetadata(
1280
                            Criterion\UserMetadata::OWNER,
1281
                            Criterion\Operator::EQ,
1282
                            226
1283
                        ),
1284
                    )
1285
                )
1286
            )
1287
        );
1288
    }
1289
1290 View Code Duplication
    public function testUserMetadataFilterOwnerInAMember()
1291
    {
1292
        $this->assertSearchResults(
1293
            array(223),
1294
            $this->getContentSearchHandler()->findContent(
1295
                new Query(
1296
                    array(
1297
                        'filter' => new Criterion\UserMetadata(
1298
                            Criterion\UserMetadata::OWNER,
1299
                            Criterion\Operator::IN,
1300
                            array(226)
1301
                        ),
1302
                    )
1303
                )
1304
            )
1305
        );
1306
    }
1307
1308 View Code Duplication
    public function testUserMetadataFilterCreatorEqAMember()
1309
    {
1310
        $this->assertSearchResults(
1311
            array(223),
1312
            $this->getContentSearchHandler()->findContent(
1313
                new Query(
1314
                    array(
1315
                        'filter' => new Criterion\UserMetadata(
1316
                            Criterion\UserMetadata::MODIFIER,
1317
                            Criterion\Operator::EQ,
1318
                            226
1319
                        ),
1320
                    )
1321
                )
1322
            )
1323
        );
1324
    }
1325
1326 View Code Duplication
    public function testUserMetadataFilterCreatorInAMember()
1327
    {
1328
        $this->assertSearchResults(
1329
            array(223),
1330
            $this->getContentSearchHandler()->findContent(
1331
                new Query(
1332
                    array(
1333
                        'filter' => new Criterion\UserMetadata(
1334
                            Criterion\UserMetadata::MODIFIER,
1335
                            Criterion\Operator::IN,
1336
                            array(226)
1337
                        ),
1338
                    )
1339
                )
1340
            )
1341
        );
1342
    }
1343
1344 View Code Duplication
    public function testUserMetadataFilterEqGroupMember()
1345
    {
1346
        $this->assertSearchResults(
1347
            array(223),
1348
            $this->getContentSearchHandler()->findContent(
1349
                new Query(
1350
                    array(
1351
                        'filter' => new Criterion\UserMetadata(
1352
                            Criterion\UserMetadata::GROUP,
1353
                            Criterion\Operator::EQ,
1354
                            11
1355
                        ),
1356
                    )
1357
                )
1358
            )
1359
        );
1360
    }
1361
1362 View Code Duplication
    public function testUserMetadataFilterInGroupMember()
1363
    {
1364
        $this->assertSearchResults(
1365
            array(223),
1366
            $this->getContentSearchHandler()->findContent(
1367
                new Query(
1368
                    array(
1369
                        'filter' => new Criterion\UserMetadata(
1370
                            Criterion\UserMetadata::GROUP,
1371
                            Criterion\Operator::IN,
1372
                            array(11)
1373
                        ),
1374
                    )
1375
                )
1376
            )
1377
        );
1378
    }
1379
1380 View Code Duplication
    public function testUserMetadataFilterEqGroupMemberNoMatch()
1381
    {
1382
        $this->assertSearchResults(
1383
            array(),
1384
            $this->getContentSearchHandler()->findContent(
1385
                new Query(
1386
                    array(
1387
                        'filter' => new Criterion\UserMetadata(
1388
                            Criterion\UserMetadata::GROUP,
1389
                            Criterion\Operator::EQ,
1390
                            13
1391
                        ),
1392
                    )
1393
                )
1394
            )
1395
        );
1396
    }
1397
1398 View Code Duplication
    public function testUserMetadataFilterInGroupMemberNoMatch()
1399
    {
1400
        $this->assertSearchResults(
1401
            array(),
1402
            $this->getContentSearchHandler()->findContent(
1403
                new Query(
1404
                    array(
1405
                        'filter' => new Criterion\UserMetadata(
1406
                            Criterion\UserMetadata::GROUP,
1407
                            Criterion\Operator::IN,
1408
                            array(13)
1409
                        ),
1410
                    )
1411
                )
1412
            )
1413
        );
1414
    }
1415
1416
    public function testFieldRelationFilterContainsSingle()
1417
    {
1418
        $this->assertSearchResults(
1419
            array(67),
1420
            $this->getContentSearchHandler()->findContent(
1421
                new Query(
1422
                    array(
1423
                        'filter' => new Criterion\FieldRelation(
1424
                            'billboard',
1425
                            Criterion\Operator::CONTAINS,
1426
                            array(60)
1427
                        ),
1428
                    )
1429
                )
1430
            )
1431
        );
1432
    }
1433
1434 View Code Duplication
    public function testFieldRelationFilterContainsSingleNoMatch()
1435
    {
1436
        $this->assertSearchResults(
1437
            array(),
1438
            $this->getContentSearchHandler()->findContent(
1439
                new Query(
1440
                    array(
1441
                        'filter' => new Criterion\FieldRelation(
1442
                            'billboard',
1443
                            Criterion\Operator::CONTAINS,
1444
                            array(4)
1445
                        ),
1446
                    )
1447
                )
1448
            )
1449
        );
1450
    }
1451
1452
    public function testFieldRelationFilterContainsArray()
1453
    {
1454
        $this->assertSearchResults(
1455
            array(67),
1456
            $this->getContentSearchHandler()->findContent(
1457
                new Query(
1458
                    array(
1459
                        'filter' => new Criterion\FieldRelation(
1460
                            'billboard',
1461
                            Criterion\Operator::CONTAINS,
1462
                            array(60, 75)
1463
                        ),
1464
                    )
1465
                )
1466
            )
1467
        );
1468
    }
1469
1470
    public function testFieldRelationFilterContainsArrayNotMatch()
1471
    {
1472
        $this->assertSearchResults(
1473
            array(),
1474
            $this->getContentSearchHandler()->findContent(
1475
                new Query(
1476
                    array(
1477
                        'filter' => new Criterion\FieldRelation(
1478
                            'billboard',
1479
                            Criterion\Operator::CONTAINS,
1480
                            array(60, 64)
1481
                        ),
1482
                    )
1483
                )
1484
            )
1485
        );
1486
    }
1487
1488
    public function testFieldRelationFilterInArray()
1489
    {
1490
        $this->assertSearchResults(
1491
            array(67, 75),
1492
            $this->getContentSearchHandler()->findContent(
1493
                new Query(
1494
                    array(
1495
                        'filter' => new Criterion\FieldRelation(
1496
                            'billboard',
1497
                            Criterion\Operator::IN,
1498
                            array(60, 64)
1499
                        ),
1500
                    )
1501
                )
1502
            )
1503
        );
1504
    }
1505
1506
    public function testFieldRelationFilterInArrayNotMatch()
1507
    {
1508
        $this->assertSearchResults(
1509
            array(),
1510
            $this->getContentSearchHandler()->findContent(
1511
                new Query(
1512
                    array(
1513
                        'filter' => new Criterion\FieldRelation(
1514
                            'billboard',
1515
                            Criterion\Operator::IN,
1516
                            array(4, 10)
1517
                        ),
1518
                    )
1519
                )
1520
            )
1521
        );
1522
    }
1523
}
1524