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