|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* File containing the ParentLocationTest class. |
|
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\MVC\Symfony\Matcher\Tests\ContentBased\Matcher\Id; |
|
12
|
|
|
|
|
13
|
|
|
use eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\Id\ParentLocation as ParentLocationIdMatcher; |
|
14
|
|
|
use eZ\Publish\API\Repository\Values\Content\Location; |
|
15
|
|
|
use eZ\Publish\Core\MVC\Symfony\Matcher\Tests\ContentBased\BaseTest; |
|
16
|
|
|
use eZ\Publish\API\Repository\Repository; |
|
17
|
|
|
|
|
18
|
|
|
class ParentLocationTest extends BaseTest |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\Id\ParentLocation |
|
22
|
|
|
*/ |
|
23
|
|
|
private $matcher; |
|
24
|
|
|
|
|
25
|
|
|
protected function setUp() |
|
26
|
|
|
{ |
|
27
|
|
|
parent::setUp(); |
|
28
|
|
|
$this->matcher = new ParentLocationIdMatcher(); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @dataProvider matchLocationProvider |
|
33
|
|
|
* @covers eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\Id\ParentLocation::matchLocation |
|
34
|
|
|
* @covers eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\MultipleValued::setMatchingConfig |
|
35
|
|
|
* |
|
36
|
|
|
* @param int|int[] $matchingConfig |
|
37
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Location $location |
|
38
|
|
|
* @param bool $expectedResult |
|
39
|
|
|
*/ |
|
40
|
|
|
public function testMatchLocation($matchingConfig, Location $location, $expectedResult) |
|
41
|
|
|
{ |
|
42
|
|
|
$this->matcher->setMatchingConfig($matchingConfig); |
|
43
|
|
|
$this->assertSame($expectedResult, $this->matcher->matchLocation($location)); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function matchLocationProvider() |
|
47
|
|
|
{ |
|
48
|
|
|
return array( |
|
49
|
|
|
array( |
|
50
|
|
|
123, |
|
51
|
|
|
$this->getLocationMock(array('parentLocationId' => 123)), |
|
52
|
|
|
true, |
|
53
|
|
|
), |
|
54
|
|
|
array( |
|
55
|
|
|
123, |
|
56
|
|
|
$this->getLocationMock(array('parentLocationId' => 456)), |
|
57
|
|
|
false, |
|
58
|
|
|
), |
|
59
|
|
|
array( |
|
60
|
|
|
array(123, 789), |
|
61
|
|
|
$this->getLocationMock(array('parentLocationId' => 456)), |
|
62
|
|
|
false, |
|
63
|
|
|
), |
|
64
|
|
|
array( |
|
65
|
|
|
array(123, 789), |
|
66
|
|
|
$this->getLocationMock(array('parentLocationId' => 789)), |
|
67
|
|
|
true, |
|
68
|
|
|
), |
|
69
|
|
|
); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @dataProvider matchContentInfoProvider |
|
74
|
|
|
* @covers eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\Id\ParentLocation::matchContentInfo |
|
75
|
|
|
* @covers eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\MultipleValued::setMatchingConfig |
|
76
|
|
|
* @covers \eZ\Publish\Core\MVC\RepositoryAware::setRepository |
|
77
|
|
|
* |
|
78
|
|
|
* @param int|int[] $matchingConfig |
|
79
|
|
|
* @param \eZ\Publish\API\Repository\Repository $repository |
|
80
|
|
|
* @param bool $expectedResult |
|
81
|
|
|
*/ |
|
82
|
|
View Code Duplication |
public function testMatchContentInfo($matchingConfig, Repository $repository, $expectedResult) |
|
83
|
|
|
{ |
|
84
|
|
|
$this->matcher->setRepository($repository); |
|
85
|
|
|
$this->matcher->setMatchingConfig($matchingConfig); |
|
86
|
|
|
$this->assertSame( |
|
87
|
|
|
$expectedResult, |
|
88
|
|
|
$this->matcher->matchContentInfo($this->getContentInfoMock(array('mainLocationId' => 42))) |
|
89
|
|
|
); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function matchContentInfoProvider() |
|
93
|
|
|
{ |
|
94
|
|
|
return array( |
|
95
|
|
|
array( |
|
96
|
|
|
123, |
|
97
|
|
|
$this->generateRepositoryMockForParentLocationId(123), |
|
98
|
|
|
true, |
|
99
|
|
|
), |
|
100
|
|
|
array( |
|
101
|
|
|
123, |
|
102
|
|
|
$this->generateRepositoryMockForParentLocationId(456), |
|
103
|
|
|
false, |
|
104
|
|
|
), |
|
105
|
|
|
array( |
|
106
|
|
|
array(123, 789), |
|
107
|
|
|
$this->generateRepositoryMockForParentLocationId(456), |
|
108
|
|
|
false, |
|
109
|
|
|
), |
|
110
|
|
|
array( |
|
111
|
|
|
array(123, 789), |
|
112
|
|
|
$this->generateRepositoryMockForParentLocationId(789), |
|
113
|
|
|
true, |
|
114
|
|
|
), |
|
115
|
|
|
); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Returns a Repository mock configured to return the appropriate Location object with given parent location Id. |
|
120
|
|
|
* |
|
121
|
|
|
* @param int $parentLocationId |
|
122
|
|
|
* |
|
123
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject |
|
124
|
|
|
*/ |
|
125
|
|
|
private function generateRepositoryMockForParentLocationId($parentLocationId) |
|
126
|
|
|
{ |
|
127
|
|
|
$locationServiceMock = $this |
|
128
|
|
|
->getMockBuilder('eZ\\Publish\\API\\Repository\\LocationService') |
|
129
|
|
|
->disableOriginalConstructor() |
|
130
|
|
|
->getMock(); |
|
131
|
|
|
$locationServiceMock->expects($this->once()) |
|
132
|
|
|
->method('loadLocation') |
|
133
|
|
|
->with(42) |
|
134
|
|
|
->will( |
|
135
|
|
|
$this->returnValue( |
|
136
|
|
|
$this->getLocationMock(array('parentLocationId' => $parentLocationId)) |
|
137
|
|
|
) |
|
138
|
|
|
); |
|
139
|
|
|
|
|
140
|
|
|
$repository = $this->getRepositoryMock(); |
|
141
|
|
|
$repository |
|
142
|
|
|
->expects($this->once()) |
|
143
|
|
|
->method('getLocationService') |
|
144
|
|
|
->will($this->returnValue($locationServiceMock)); |
|
145
|
|
|
|
|
146
|
|
|
return $repository; |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|