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