Completed
Push — ezp26352-skip_csrf_check_on_re... ( 19f37a )
by
unknown
36:29
created

GeneratorTest::testGetListChildrenStackPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 13
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File containing the GeneratorTest 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\REST\Common\Tests\Output;
12
13
use PHPUnit_Framework_TestCase;
14
15
/**
16
 * Output generator test class.
17
 */
18
abstract class GeneratorTest extends PHPUnit_Framework_TestCase
19
{
20
    /**
21
     * @var \eZ\Publish\Core\REST\Common\Output\Generator
22
     */
23
    protected $generator;
24
25
    /**
26
     * @return \eZ\Publish\Core\REST\Common\Output\Generator
27
     */
28
    abstract protected function getGenerator();
29
30
    /**
31
     * @expectedException \eZ\Publish\Core\REST\Common\Output\Exceptions\OutputGeneratorException
32
     */
33
    public function testInvalidDocumentStart()
34
    {
35
        $generator = $this->getGenerator();
36
37
        $generator->startDocument('test');
38
        $generator->startDocument('test');
39
    }
40
41
    public function testValidDocumentStartAfterReset()
42
    {
43
        $generator = $this->getGenerator();
44
45
        $generator->startDocument('test');
46
        $generator->reset();
47
        $generator->startDocument('test');
48
49
        $this->assertNotNull($generator->endDocument('test'));
50
    }
51
52
    /**
53
     * @expectedException \eZ\Publish\Core\REST\Common\Output\Exceptions\OutputGeneratorException
54
     */
55
    public function testInvalidDocumentNameEnd()
56
    {
57
        $generator = $this->getGenerator();
58
59
        $generator->startDocument('test');
60
        $generator->endDocument('invalid');
61
    }
62
63
    /**
64
     * @expectedException \eZ\Publish\Core\REST\Common\Output\Exceptions\OutputGeneratorException
65
     */
66
    public function testInvalidOuterElementStart()
67
    {
68
        $generator = $this->getGenerator();
69
70
        $generator->startObjectElement('element');
71
    }
72
73
    /**
74
     * @expectedException \eZ\Publish\Core\REST\Common\Output\Exceptions\OutputGeneratorException
75
     */
76
    public function testInvalidElementEnd()
77
    {
78
        $generator = $this->getGenerator();
79
80
        $generator->startDocument('test');
81
        $generator->startObjectElement('element');
82
        $generator->endObjectElement('invalid');
83
    }
84
85
    /**
86
     * @expectedException \eZ\Publish\Core\REST\Common\Output\Exceptions\OutputGeneratorException
87
     */
88
    public function testInvalidDocumentEnd()
89
    {
90
        $generator = $this->getGenerator();
91
92
        $generator->startDocument('test');
93
        $generator->startObjectElement('element');
94
        $generator->endDocument('test');
95
    }
96
97
    /**
98
     * @expectedException \eZ\Publish\Core\REST\Common\Output\Exceptions\OutputGeneratorException
99
     */
100
    public function testInvalidAttributeOuterStart()
101
    {
102
        $generator = $this->getGenerator();
103
104
        $generator->startAttribute('attribute', 'value');
105
    }
106
107
    /**
108
     * @expectedException \eZ\Publish\Core\REST\Common\Output\Exceptions\OutputGeneratorException
109
     */
110
    public function testInvalidAttributeDocumentStart()
111
    {
112
        $generator = $this->getGenerator();
113
114
        $generator->startDocument('test');
115
        $generator->startAttribute('attribute', 'value');
116
    }
117
118
    /**
119
     * @expectedException \eZ\Publish\Core\REST\Common\Output\Exceptions\OutputGeneratorException
120
     */
121
    public function testInvalidAttributeListStart()
122
    {
123
        $generator = $this->getGenerator();
124
125
        $generator->startDocument('test');
126
        $generator->startObjectElement('element');
127
        $generator->startList('list');
128
        $generator->startAttribute('attribute', 'value');
129
    }
130
131
    /**
132
     * @expectedException \eZ\Publish\Core\REST\Common\Output\Exceptions\OutputGeneratorException
133
     */
134
    public function testInvalidValueElementOuterStart()
135
    {
136
        $generator = $this->getGenerator();
137
138
        $generator->startValueElement('element', 'value');
139
    }
140
141
    /**
142
     * @expectedException \eZ\Publish\Core\REST\Common\Output\Exceptions\OutputGeneratorException
143
     */
144
    public function testInvalidValueElementDocumentStart()
145
    {
146
        $generator = $this->getGenerator();
147
148
        $generator->startDocument('test');
149
        $generator->startValueElement('element', 'value');
150
    }
151
152
    /**
153
     * @expectedException \eZ\Publish\Core\REST\Common\Output\Exceptions\OutputGeneratorException
154
     */
155
    public function testInvalidListOuterStart()
156
    {
157
        $generator = $this->getGenerator();
158
159
        $generator->startList('list');
160
    }
161
162
    /**
163
     * @expectedException \eZ\Publish\Core\REST\Common\Output\Exceptions\OutputGeneratorException
164
     */
165
    public function testInvalidListDocumentStart()
166
    {
167
        $generator = $this->getGenerator();
168
169
        $generator->startDocument('test');
170
        $generator->startList('list');
171
    }
172
173
    /**
174
     * @expectedException \eZ\Publish\Core\REST\Common\Output\Exceptions\OutputGeneratorException
175
     */
176
    public function testInvalidListListStart()
177
    {
178
        $generator = $this->getGenerator();
179
180
        $generator->startDocument('test');
181
        $generator->startObjectElement('element');
182
        $generator->startList('list');
183
        $generator->startList('attribute', 'value');
184
    }
185
186
    public function testEmptyDocument()
187
    {
188
        $generator = $this->getGenerator();
189
190
        $generator->startDocument('test');
191
192
        $this->assertTrue($generator->isEmpty());
193
    }
194
195
    public function testNonEmptyDocument()
196
    {
197
        $generator = $this->getGenerator();
198
199
        $generator->startDocument('test');
200
        $generator->startObjectElement('element');
201
202
        $this->assertFalse($generator->isEmpty());
203
    }
204
205
    public function testGetDocumentStackPath()
206
    {
207
        $generator = $this->getGenerator();
208
209
        $generator->startDocument('test');
210
211
        self::assertEquals('', $generator->getStackPath());
212
    }
213
214
    public function testGetRootStackPath()
215
    {
216
        $generator = $this->getGenerator();
217
218
        $generator->startDocument('test');
219
        $generator->startObjectElement('element');
220
221
        self::assertEquals('element', $generator->getStackPath());
222
    }
223
224
    public function testGetElementStackPath()
225
    {
226
        $generator = $this->getGenerator();
227
228
        $generator->startDocument('test');
229
        $generator->startObjectElement('element');
230
        $generator->startObjectElement('subElement');
231
232
        self::assertEquals('element.subElement', $generator->getStackPath());
233
    }
234
235 View Code Duplication
    public function testGetListChildrenStackPath()
236
    {
237
        $generator = $this->getGenerator();
238
239
        $generator->startDocument('test');
240
        $generator->startObjectElement('listOfElements');
241
        $generator->startList('listOfElements');
242
        $generator->startObjectElement('child');
243
        $generator->startAttribute('href', 'http://google.com');
244
        $generator->endAttribute('href');
245
246
        self::assertEquals('listOfElements.child', $generator->getStackPath());
247
    }
248
}
249