|
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\Validity; |
|
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\Validity as ValidityHandler; |
|
15
|
|
|
|
|
16
|
|
View Code Duplication |
class ValidityTest extends CriterionHandlerTest |
|
|
|
|
|
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* {@inheritdoc} |
|
20
|
|
|
*/ |
|
21
|
|
|
public function testAccept() |
|
22
|
|
|
{ |
|
23
|
|
|
$handler = new ValidityHandler(); |
|
24
|
|
|
|
|
25
|
|
|
$this->assertHandlerAcceptsCriterion($handler, Validity::class); |
|
26
|
|
|
$this->assertHandlerRejectsCriterion($handler, Criterion::class); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* {@inheritdoc} |
|
31
|
|
|
*/ |
|
32
|
|
|
public function testHandle() |
|
33
|
|
|
{ |
|
34
|
|
|
$criterion = new Validity(true); |
|
35
|
|
|
$expected = 'is_valid = :is_valid'; |
|
36
|
|
|
|
|
37
|
|
|
$expr = $this->createMock(Expression::class); |
|
38
|
|
|
$expr |
|
39
|
|
|
->expects($this->once()) |
|
40
|
|
|
->method('eq') |
|
41
|
|
|
->with('is_valid', ':is_valid') |
|
42
|
|
|
->willReturn($expected); |
|
43
|
|
|
|
|
44
|
|
|
$query = $this->createMock(SelectQuery::class); |
|
45
|
|
|
$query->expr = $expr; |
|
46
|
|
|
$query |
|
47
|
|
|
->expects($this->once()) |
|
48
|
|
|
->method('bindValue') |
|
49
|
|
|
->with($criterion->isValid) |
|
50
|
|
|
->willReturn(':is_valid'); |
|
51
|
|
|
|
|
52
|
|
|
$converter = $this->createMock(CriteriaConverter::class); |
|
53
|
|
|
|
|
54
|
|
|
$handler = new ValidityHandler(); |
|
55
|
|
|
$actual = $handler->handle($converter, $query, $criterion); |
|
56
|
|
|
|
|
57
|
|
|
$this->assertEquals($expected, $actual); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.