Completed
Push — 7.0 ( 66fc99...d11e6e )
by André
14:26
created

VisibleOnlyTest::testHandle()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 31
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 23
nc 1
nop 0
dl 0
loc 31
rs 8.8571
c 0
b 0
f 0
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\Core\Persistence\Legacy\Tests\URL\Query\CriterionHandler;
8
9
use eZ\Publish\API\Repository\Values\URL\Query\Criterion\VisibleOnly;
10
use eZ\Publish\API\Repository\Values\URL\Query\Criterion;
11
use eZ\Publish\Core\Persistence\Database\Expression;
12
use eZ\Publish\Core\Persistence\Database\SelectQuery;
13
use eZ\Publish\Core\Persistence\Legacy\URL\Query\CriteriaConverter;
14
use eZ\Publish\Core\Persistence\Legacy\URL\Query\CriterionHandler\VisibleOnly as VisibleOnlyHandler;
15
16
class VisibleOnlyTest extends CriterionHandlerTest
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function testAccept()
22
    {
23
        $handler = new VisibleOnlyHandler();
24
25
        $this->assertHandlerAcceptsCriterion($handler, VisibleOnly::class);
26
        $this->assertHandlerRejectsCriterion($handler, Criterion::class);
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function testHandle()
33
    {
34
        $criterion = new VisibleOnly();
35
        $expected = 'ezurl.id IN (SUBQUERY)';
36
37
        $expr = $this->createMock(Expression::class);
38
        $expr
39
            ->expects($this->once())
40
            ->method('in')
41
            ->with('ezurl.id', '(SUBQUERY)')
42
            ->willReturn($expected);
43
44
        $query = $this->createMock(SelectQuery::class);
45
        $query->expr = $expr;
46
47
        $converter = $this->createMock(CriteriaConverter::class);
48
49
        $handler = $this
50
            ->getMockBuilder(VisibleOnlyHandler::class)
51
            ->setMethods(['getVisibleOnlySubQuery'])
52
            ->getMock();
53
        $handler
54
            ->expects($this->once())
55
            ->method('getVisibleOnlySubQuery')
56
            ->with($query)
57
            ->willReturn('(SUBQUERY)');
58
59
        $actual = $handler->handle($converter, $query, $criterion);
60
61
        $this->assertEquals($expected, $actual);
62
    }
63
}
64