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

ObjectStateGroupTest::testVisit()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 46
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 29
nc 1
nop 0
dl 0
loc 46
rs 8.9411
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File containing a test 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\Server\Tests\Output\ValueObjectVisitor;
12
13
use eZ\Publish\Core\REST\Common\Tests\Output\ValueObjectVisitorBaseTest;
14
use eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor;
15
use eZ\Publish\Core\Repository\Values\ObjectState;
16
use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
17
18
class ObjectStateGroupTest extends ValueObjectVisitorBaseTest
19
{
20
    /**
21
     * Test the ObjectStateGroup visitor.
22
     *
23
     * @return string
24
     */
25
    public function testVisit()
26
    {
27
        $visitor = $this->getVisitor();
28
        $generator = $this->getGenerator();
29
30
        $generator->startDocument(null);
31
32
        $objectStateGroup = new ObjectState\ObjectStateGroup(
33
            array(
34
                'id' => 42,
35
                'identifier' => 'test-group',
36
                'defaultLanguageCode' => 'eng-GB',
37
                'languageCodes' => array('eng-GB', 'eng-US'),
38
                'names' => array(
39
                    'eng-GB' => 'Group name EN',
40
                    'eng-US' => 'Group name EN US',
41
                ),
42
                'descriptions' => array(
43
                    'eng-GB' => 'Group description EN',
44
                    'eng-US' => 'Group description EN US',
45
                ),
46
            )
47
        );
48
49
        $this->addRouteExpectation(
50
            'ezpublish_rest_loadObjectStateGroup',
51
            array('objectStateGroupId' => $objectStateGroup->id),
52
            "/content/objectstategroups/$objectStateGroup->id"
53
        );
54
55
        $this->setVisitValueObjectExpectations([
56
            new ResourceRouteReference('ezpublish_rest_loadObjectStates', ['objectStateGroupId' => $objectStateGroup->id]),
0 ignored issues
show
Documentation introduced by
'ezpublish_rest_loadObjectStates' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
57
        ]);
58
59
        $visitor->visit(
60
            $this->getVisitorMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->getVisitorMock() targeting eZ\Publish\Core\REST\Com...eTest::getVisitorMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\REST\Com...eObjectVisitor::visit() does only seem to accept object<eZ\Publish\Core\R...\Common\Output\Visitor>, maybe add an additional type check?

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.

Loading history...
61
            $generator,
62
            $objectStateGroup
63
        );
64
65
        $result = $generator->endDocument(null);
66
67
        $this->assertNotNull($result);
68
69
        return $result;
70
    }
71
72
    /**
73
     * Test if result contains ObjectStateGroup element.
74
     *
75
     * @param string $result
76
     *
77
     * @depends testVisit
78
     */
79
    public function testResultContainsObjectStateGroupElement($result)
80
    {
81
        $this->assertXMLTag(
82
            array(
83
                'tag' => 'ObjectStateGroup',
84
                'children' => array(
85
                    'count' => 7,
86
                ),
87
            ),
88
            $result,
89
            'Invalid <ObjectStateGroup> element.',
90
            false
91
        );
92
    }
93
94
    /**
95
     * Test if result contains ObjectStateGroup element attributes.
96
     *
97
     * @param string $result
98
     *
99
     * @depends testVisit
100
     */
101
    public function testResultContainsObjectStateGroupAttributes($result)
102
    {
103
        $this->assertXMLTag(
104
            array(
105
                'tag' => 'ObjectStateGroup',
106
                'attributes' => array(
107
                    'media-type' => 'application/vnd.ez.api.ObjectStateGroup+xml',
108
                    'href' => '/content/objectstategroups/42',
109
                ),
110
            ),
111
            $result,
112
            'Invalid <ObjectStateGroup> attributes.',
113
            false
114
        );
115
    }
116
117
    /**
118
     * Test if result contains id value element.
119
     *
120
     * @param string $result
121
     *
122
     * @depends testVisit
123
     */
124
    public function testResultContainsIdValueElement($result)
125
    {
126
        $this->assertXMLTag(
127
            array(
128
                'tag' => 'id',
129
                'content' => '42',
130
            ),
131
            $result,
132
            'Invalid or non-existing <ObjectStateGroup> id value element.',
133
            false
134
        );
135
    }
136
137
    /**
138
     * Test if result contains identifier value element.
139
     *
140
     * @param string $result
141
     *
142
     * @depends testVisit
143
     */
144
    public function testResultContainsIdentifierValueElement($result)
145
    {
146
        $this->assertXMLTag(
147
            array(
148
                'tag' => 'identifier',
149
                'content' => 'test-group',
150
            ),
151
            $result,
152
            'Invalid or non-existing <ObjectStateGroup> identifier value element.',
153
            false
154
        );
155
    }
156
157
    /**
158
     * Test if result contains defaultLanguageCode value element.
159
     *
160
     * @param string $result
161
     *
162
     * @depends testVisit
163
     */
164
    public function testResultContainsDefaultLanguageCodeValueElement($result)
165
    {
166
        $this->assertXMLTag(
167
            array(
168
                'tag' => 'defaultLanguageCode',
169
                'content' => 'eng-GB',
170
            ),
171
            $result,
172
            'Invalid or non-existing <ObjectStateGroup> defaultLanguageCode value element.',
173
            false
174
        );
175
    }
176
177
    /**
178
     * Test if result contains languageCodes value element.
179
     *
180
     * @param string $result
181
     *
182
     * @depends testVisit
183
     */
184
    public function testResultContainsLanguageCodesValueElement($result)
185
    {
186
        $this->assertXMLTag(
187
            array(
188
                'tag' => 'languageCodes',
189
                'content' => 'eng-GB,eng-US',
190
            ),
191
            $result,
192
            'Invalid or non-existing <ObjectStateGroup> languageCodes value element.',
193
            false
194
        );
195
    }
196
197
    /**
198
     * Test if result contains names element.
199
     *
200
     * @param string $result
201
     *
202
     * @depends testVisit
203
     */
204
    public function testResultContainsNamesElement($result)
205
    {
206
        $this->assertXMLTag(
207
            array(
208
                'tag' => 'names',
209
                'children' => array(
210
                    'count' => 2,
211
                ),
212
            ),
213
            $result,
214
            'Invalid <names> element.',
215
            false
216
        );
217
    }
218
219
    /**
220
     * Test if result contains descriptions element.
221
     *
222
     * @param string $result
223
     *
224
     * @depends testVisit
225
     */
226
    public function testResultContainsDescriptionsElement($result)
227
    {
228
        $this->assertXMLTag(
229
            array(
230
                'tag' => 'descriptions',
231
                'children' => array(
232
                    'count' => 2,
233
                ),
234
            ),
235
            $result,
236
            'Invalid <descriptions> element.',
237
            false
238
        );
239
    }
240
241
    /**
242
     * Get the ObjectStateGroup visitor.
243
     *
244
     * @return \eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\ObjectStateGroup
245
     */
246
    protected function internalGetVisitor()
247
    {
248
        return new ValueObjectVisitor\ObjectStateGroup();
249
    }
250
}
251