| @@ 16-59 (lines=44) @@ | ||
| 13 | use eZ\Publish\Core\Persistence\Legacy\URL\Query\CriteriaConverter; |
|
| 14 | use eZ\Publish\Core\Persistence\Legacy\URL\Query\CriterionHandler\MatchNone as MatchNoneHandler; |
|
| 15 | ||
| 16 | class MatchNoneTest extends CriterionHandlerTest |
|
| 17 | { |
|
| 18 | /** |
|
| 19 | * {@inheritdoc} |
|
| 20 | */ |
|
| 21 | public function testAccept() |
|
| 22 | { |
|
| 23 | $handler = new MatchNoneHandler(); |
|
| 24 | ||
| 25 | $this->assertHandlerAcceptsCriterion($handler, MatchNone::class); |
|
| 26 | $this->assertHandlerRejectsCriterion($handler, Criterion::class); |
|
| 27 | } |
|
| 28 | ||
| 29 | /** |
|
| 30 | * {@inheritdoc} |
|
| 31 | */ |
|
| 32 | public function testHandle() |
|
| 33 | { |
|
| 34 | $criterion = new MatchNone(); |
|
| 35 | $expected = 'NOT :value'; |
|
| 36 | ||
| 37 | $expr = $this->createMock(Expression::class); |
|
| 38 | $expr |
|
| 39 | ->expects($this->once()) |
|
| 40 | ->method('not') |
|
| 41 | ->with(':value') |
|
| 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('1') |
|
| 50 | ->willReturn(':value'); |
|
| 51 | ||
| 52 | $converter = $this->createMock(CriteriaConverter::class); |
|
| 53 | ||
| 54 | $handler = new MatchNoneHandler(); |
|
| 55 | $actual = $handler->handle($converter, $query, $criterion); |
|
| 56 | ||
| 57 | $this->assertEquals($expected, $actual); |
|
| 58 | } |
|
| 59 | } |
|
| 60 | ||
| @@ 16-59 (lines=44) @@ | ||
| 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 | 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 | ||