|
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; |
|
10
|
|
|
use eZ\Publish\API\Repository\Values\URL\Query\Criterion\LogicalOr; |
|
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\LogicalOr as LogicalOrHandler; |
|
15
|
|
|
|
|
16
|
|
|
class LogicalOrTest extends CriterionHandlerTest |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* {@inheritdoc} |
|
20
|
|
|
*/ |
|
21
|
|
|
public function testAccept() |
|
22
|
|
|
{ |
|
23
|
|
|
$handler = new LogicalOrHandler(); |
|
24
|
|
|
|
|
25
|
|
|
$this->assertHandlerAcceptsCriterion($handler, LogicalOr::class); |
|
26
|
|
|
$this->assertHandlerRejectsCriterion($handler, Criterion::class); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* {@inheritdoc} |
|
31
|
|
|
*/ |
|
32
|
|
View Code Duplication |
public function testHandle() |
|
33
|
|
|
{ |
|
34
|
|
|
$foo = $this->createMock(Criterion::class); |
|
35
|
|
|
$bar = $this->createMock(Criterion::class); |
|
36
|
|
|
|
|
37
|
|
|
$fooExpr = 'FOO'; |
|
38
|
|
|
$barExpr = 'BAR'; |
|
39
|
|
|
|
|
40
|
|
|
$expected = 'FOO OR BAR'; |
|
41
|
|
|
|
|
42
|
|
|
$expr = $this->createMock(Expression::class); |
|
43
|
|
|
$expr |
|
44
|
|
|
->expects($this->once()) |
|
45
|
|
|
->method('lOr') |
|
46
|
|
|
->with([$fooExpr, $barExpr]) |
|
47
|
|
|
->willReturn($expected); |
|
48
|
|
|
|
|
49
|
|
|
$query = $this->createMock(SelectQuery::class); |
|
50
|
|
|
$query->expr = $expr; |
|
51
|
|
|
|
|
52
|
|
|
$converter = $this->createMock(CriteriaConverter::class); |
|
53
|
|
|
$converter |
|
54
|
|
|
->expects($this->at(0)) |
|
55
|
|
|
->method('convertCriteria') |
|
56
|
|
|
->with($query, $foo) |
|
57
|
|
|
->willReturn($fooExpr); |
|
58
|
|
|
$converter |
|
59
|
|
|
->expects($this->at(1)) |
|
60
|
|
|
->method('convertCriteria') |
|
61
|
|
|
->with($query, $bar) |
|
62
|
|
|
->willReturn($barExpr); |
|
63
|
|
|
|
|
64
|
|
|
$handler = new LogicalOrHandler(); |
|
65
|
|
|
$actual = $handler->handle( |
|
66
|
|
|
$converter, $query, new LogicalOr([$foo, $bar]) |
|
67
|
|
|
); |
|
68
|
|
|
|
|
69
|
|
|
$this->assertEquals($expected, $actual); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|