|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
4
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
5
|
|
|
*/ |
|
6
|
|
|
namespace eZ\Publish\Core\REST\Server\Tests\Output\PathExpansion; |
|
7
|
|
|
|
|
8
|
|
|
use eZ\Publish\Core\REST\Server\Output\PathExpansion\ExpansionGenerator; |
|
9
|
|
|
use PHPUnit_Framework_TestCase; |
|
10
|
|
|
|
|
11
|
|
|
class ExpansionGeneratorTest extends PHPUnit_Framework_TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject|\eZ\Publish\Core\REST\Common\Output\Generator |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $innerGeneratorMock; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @expectedException \eZ\Publish\Core\Base\Exceptions\BadStateException |
|
20
|
|
|
*/ |
|
21
|
|
|
public function testStartDocument() |
|
22
|
|
|
{ |
|
23
|
|
|
$this->buildGenerator()->startDocument('tenant'); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @expectedException \eZ\Publish\Core\Base\Exceptions\BadStateException |
|
28
|
|
|
*/ |
|
29
|
|
|
public function testEndDocument() |
|
30
|
|
|
{ |
|
31
|
|
|
$this->buildGenerator()->endDocument('tenant'); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function testIsEmpty() |
|
35
|
|
|
{ |
|
36
|
|
|
$this->getInnerGeneratorMock() |
|
37
|
|
|
->expects($this->once()) |
|
38
|
|
|
->method('isEmpty'); |
|
39
|
|
|
|
|
40
|
|
|
$this->buildGenerator()->isEmpty(); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
View Code Duplication |
public function testStartEndObjectElement() |
|
44
|
|
|
{ |
|
45
|
|
|
$this->getInnerGeneratorMock() |
|
46
|
|
|
->expects($this->once()) |
|
47
|
|
|
->method('startObjectElement') |
|
48
|
|
|
->with('pertwee', 'doctor'); |
|
49
|
|
|
|
|
50
|
|
|
$this->getInnerGeneratorMock() |
|
51
|
|
|
->expects($this->once()) |
|
52
|
|
|
->method('endObjectElement') |
|
53
|
|
|
->with('pertwee'); |
|
54
|
|
|
|
|
55
|
|
|
$generator = $this->buildGenerator(); |
|
56
|
|
|
$generator->startObjectElement('jon', 'doctor'); |
|
57
|
|
|
$generator->startObjectElement('pertwee', 'doctor'); |
|
58
|
|
|
$generator->endObjectElement('pertwee'); |
|
59
|
|
|
$generator->endObjectElement('jon'); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function testStartHashElement() |
|
63
|
|
|
{ |
|
64
|
|
|
$this->getInnerGeneratorMock() |
|
65
|
|
|
->expects($this->once()) |
|
66
|
|
|
->method('startHashElement') |
|
67
|
|
|
->with('baker'); |
|
68
|
|
|
|
|
69
|
|
|
$this->buildGenerator()->startHashElement('baker'); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function testEndHashElement() |
|
73
|
|
|
{ |
|
74
|
|
|
$this->getInnerGeneratorMock() |
|
75
|
|
|
->expects($this->once()) |
|
76
|
|
|
->method('endHashElement') |
|
77
|
|
|
->with('baker'); |
|
78
|
|
|
|
|
79
|
|
|
$this->buildGenerator()->endHashElement('baker'); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function testStartValueElement() |
|
83
|
|
|
{ |
|
84
|
|
|
$this->getInnerGeneratorMock() |
|
85
|
|
|
->expects($this->once()) |
|
86
|
|
|
->method('startValueElement') |
|
87
|
|
|
->with('baker', 'paul'); |
|
88
|
|
|
|
|
89
|
|
|
$this->buildGenerator()->startValueElement('baker', 'paul'); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function testEndValueElement() |
|
93
|
|
|
{ |
|
94
|
|
|
$this->getInnerGeneratorMock() |
|
95
|
|
|
->expects($this->once()) |
|
96
|
|
|
->method('endValueElement') |
|
97
|
|
|
->with('baker'); |
|
98
|
|
|
|
|
99
|
|
|
$this->buildGenerator()->endValueElement('baker'); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function testStartList() |
|
103
|
|
|
{ |
|
104
|
|
|
$this->getInnerGeneratorMock() |
|
105
|
|
|
->expects($this->once()) |
|
106
|
|
|
->method('startList') |
|
107
|
|
|
->with('hartnell'); |
|
108
|
|
|
|
|
109
|
|
|
$this->buildGenerator()->startList('hartnell'); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
public function testEndList() |
|
113
|
|
|
{ |
|
114
|
|
|
$this->getInnerGeneratorMock() |
|
115
|
|
|
->expects($this->once()) |
|
116
|
|
|
->method('endList') |
|
117
|
|
|
->with('hartnell'); |
|
118
|
|
|
|
|
119
|
|
|
$this->buildGenerator()->endList('hartnell'); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
View Code Duplication |
public function testStartEndAttribute() |
|
123
|
|
|
{ |
|
124
|
|
|
$this->getInnerGeneratorMock() |
|
125
|
|
|
->expects($this->once()) |
|
126
|
|
|
->method('startObjectElement') |
|
127
|
|
|
->with('eccleston', 'doctor'); |
|
128
|
|
|
|
|
129
|
|
|
$this->getInnerGeneratorMock() |
|
130
|
|
|
->expects($this->once()) |
|
131
|
|
|
->method('startAttribute') |
|
132
|
|
|
->with('jacket', 'leather'); |
|
133
|
|
|
|
|
134
|
|
|
$generator = $this->buildGenerator(); |
|
135
|
|
|
|
|
136
|
|
|
$generator->startObjectElement('smith'); |
|
137
|
|
|
$generator->startObjectElement('eccleston', 'doctor'); |
|
138
|
|
|
$generator->startAttribute('jacket', 'leather'); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
public function testStartEndAttributeAtRoot() |
|
142
|
|
|
{ |
|
143
|
|
|
$this->getInnerGeneratorMock() |
|
144
|
|
|
->expects($this->never()) |
|
145
|
|
|
->method('startObjectElement'); |
|
146
|
|
|
|
|
147
|
|
|
$this->getInnerGeneratorMock() |
|
148
|
|
|
->expects($this->once()) |
|
149
|
|
|
->method('startAttribute') |
|
150
|
|
|
->with('jacket'); |
|
151
|
|
|
|
|
152
|
|
|
$this->getInnerGeneratorMock() |
|
153
|
|
|
->expects($this->once()) |
|
154
|
|
|
->method('endAttribute') |
|
155
|
|
|
->with('jacket'); |
|
156
|
|
|
|
|
157
|
|
|
$this->buildGenerator()->startObjectElement('eccleston'); |
|
158
|
|
|
$this->buildGenerator()->startAttribute('href', 'http://ez.no'); |
|
159
|
|
|
$this->buildGenerator()->endAttribute('href'); |
|
160
|
|
|
$this->buildGenerator()->startAttribute('media-type', 'application/planet.gallifrey.doctor'); |
|
161
|
|
|
$this->buildGenerator()->endAttribute('media-type'); |
|
162
|
|
|
$this->buildGenerator()->startAttribute('jacket', 'leather'); |
|
163
|
|
|
$this->buildGenerator()->endAttribute('jacket'); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
public function testGetMediaType() |
|
167
|
|
|
{ |
|
168
|
|
|
$this->getInnerGeneratorMock() |
|
169
|
|
|
->expects($this->once()) |
|
170
|
|
|
->method('getMediaType') |
|
171
|
|
|
->with('foo') |
|
172
|
|
|
->willReturn('application/vnd.ez.api.foo'); |
|
173
|
|
|
|
|
174
|
|
|
self::assertEquals('application/vnd.ez.api.foo', $this->buildGenerator()->getMediaType('foo')); |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
public function testGenerateFieldTypeHash() |
|
178
|
|
|
{ |
|
179
|
|
|
$this->getInnerGeneratorMock() |
|
180
|
|
|
->expects($this->once()) |
|
181
|
|
|
->method('generateFieldTypeHash') |
|
182
|
|
|
->with('smith', []); |
|
183
|
|
|
|
|
184
|
|
|
$this->buildGenerator()->generateFieldTypeHash('smith', []); |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
public function testSerializeBool() |
|
188
|
|
|
{ |
|
189
|
|
|
$this->getInnerGeneratorMock() |
|
190
|
|
|
->expects($this->once()) |
|
191
|
|
|
->method('serializeBool') |
|
192
|
|
|
->with(true) |
|
193
|
|
|
->willReturn('true'); |
|
194
|
|
|
|
|
195
|
|
|
self::assertEquals('true', $this->buildGenerator()->serializeBool(true)); |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* @return ExpansionGenerator |
|
200
|
|
|
*/ |
|
201
|
|
|
protected function buildGenerator() |
|
202
|
|
|
{ |
|
203
|
|
|
return new ExpansionGenerator($this->getInnerGeneratorMock()); |
|
|
|
|
|
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
/** |
|
207
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|\eZ\Publish\Core\REST\Common\Output\Generator |
|
208
|
|
|
*/ |
|
209
|
|
|
protected function getInnerGeneratorMock() |
|
210
|
|
|
{ |
|
211
|
|
|
if (!isset($this->innerGeneratorMock)) { |
|
212
|
|
|
$this->innerGeneratorMock = $this->getMockBuilder('eZ\Publish\Core\REST\Common\Output\Generator')->getMock(); |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
return $this->innerGeneratorMock; |
|
216
|
|
|
} |
|
217
|
|
|
} |
|
218
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.