Completed
Push — travis_trusty ( e78e49...6f0d6f )
by André
54:54 queued 34:46
created

RootTest::testVisit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 20
rs 9.4285
cc 1
eloc 12
nc 1
nop 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\REST\Server\Service\ExpressionRouterRootResourceBuilder;
16
17
class RootTest extends ValueObjectVisitorBaseTest
18
{
19
    protected function getRootResourceBuilder()
20
    {
21
        $resourceConfig = array(
22
            'Router' => array(
23
                'mediaType' => '',
24
                'href' => 'router.generate("ezpublish_rest_createContent")',
25
            ),
26
            'RouterWithAttributes' => array(
27
                'mediaType' => 'UserRefList',
28
                'href' => 'router.generate("ezpublish_rest_loadUsers")',
29
            ),
30
            'TemplateRouter' => array(
31
                'mediaType' => '',
32
                'href' => 'templateRouter.generate("ezpublish_rest_redirectContent", {remoteId: "{remoteId}"})',
33
            ),
34
            'TemplateRouterWithAttributes' => array(
35
                'mediaType' => 'UserRefList',
36
                'href' => 'templateRouter.generate("ezpublish_rest_loadUsers", {roleId: "{roleId}"})',
37
            ),
38
        );
39
40
        $this->addRouteExpectation('ezpublish_rest_createContent', array(), '/content/objects');
41
        $this->addTemplatedRouteExpectation('ezpublish_rest_redirectContent', array('remoteId' => '{remoteId}'), '/content/objects');
42
        $this->addRouteExpectation('ezpublish_rest_loadUsers', array(), '/user/users');
43
        $this->addTemplatedRouteExpectation('ezpublish_rest_loadUsers', array('roleId' => '{roleId}'), '/user/users{?roleId}');
44
45
        return new ExpressionRouterRootResourceBuilder($this->getRouterMock(), $this->getTemplatedRouterMock(), $resourceConfig);
0 ignored issues
show
Bug introduced by
It seems like $this->getRouterMock() targeting eZ\Publish\Core\REST\Com...seTest::getRouterMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\REST\Ser...eBuilder::__construct() does only seem to accept object<Symfony\Component\Routing\RouterInterface>, 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...
Bug introduced by
It seems like $this->getTemplatedRouterMock() targeting eZ\Publish\Core\REST\Com...etTemplatedRouterMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\REST\Ser...eBuilder::__construct() does only seem to accept object<Symfony\Component\Routing\RouterInterface>, 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...
46
    }
47
48
    /**
49
     * Test the Role visitor.
50
     *
51
     * @return string
52
     */
53
    public function testVisit()
54
    {
55
        $visitor = $this->getVisitor();
56
        $generator = $this->getGenerator();
57
        $rootResourceBuilder = $this->getRootResourceBuilder();
58
59
        $generator->startDocument(null);
60
61
        $visitor->visit(
62
            $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...
63
            $generator,
64
            $rootResourceBuilder->buildRootResource()
65
        );
66
67
        $result = $generator->endDocument(null);
68
69
        $this->assertNotNull($result);
70
71
        return $result;
72
    }
73
74
    /**
75
     * @depends testVisit
76
     */
77
    public function testResultContainsRootElement($result)
78
    {
79
        $this->assertXMLTag(
80
            array('tag' => 'Root'),
81
            $result,
82
            'Invalid <Root> element.',
83
            false
84
        );
85
    }
86
87
    /**
88
     * Test if result contains Role element attributes.
89
     *
90
     * @param string $result
91
     *
92
     * @depends testVisit
93
     */
94
    public function testResultContainsRootAttributes($result)
95
    {
96
        $this->assertXMLTag(
97
            array(
98
                'tag' => 'Root',
99
                'attributes' => array(
100
                    'media-type' => 'application/vnd.ez.api.Root+xml',
101
                ),
102
            ),
103
            $result,
104
            'Invalid <Root> attributes.',
105
            false
106
        );
107
    }
108
109
    /**
110
     * @depends testVisit
111
     */
112
    public function testResultContainsRouterTag($result)
113
    {
114
        $this->assertXMLTag(
115
            array(
116
                'tag' => 'Router',
117
            ),
118
            $result,
119
            'Invalid <Router> element.',
120
            false
121
        );
122
    }
123
124
    /**
125
     * @depends testVisit
126
     */
127
    public function testResultContainsRouterWithAttributes($result)
128
    {
129
        $this->assertXMLTag(
130
            array(
131
                'tag' => 'RouterWithAttributes',
132
                'attributes' => array(
133
                    'media-type' => 'application/vnd.ez.api.UserRefList+xml',
134
                ),
135
            ),
136
            $result,
137
            'Invalid <RouterWithAttributes> element.',
138
            false
139
        );
140
    }
141
142
    /**
143
     * @depends testVisit
144
     */
145
    public function testResultContainsTemplateRouterTag($result)
146
    {
147
        $this->assertXMLTag(
148
            array(
149
                'tag' => 'TemplateRouter',
150
            ),
151
            $result,
152
            'Invalid <TemplateRouter> element.',
153
            false
154
        );
155
    }
156
157
    /**
158
     * @depends testVisit
159
     */
160
    public function testResultContainsTemplateRouterWithAttributes($result)
161
    {
162
        $this->assertXMLTag(
163
            array(
164
                'tag' => 'TemplateRouterWithAttributes',
165
                'attributes' => array(
166
                    'media-type' => 'application/vnd.ez.api.UserRefList+xml',
167
                ),
168
            ),
169
            $result,
170
            'Invalid <TemplateRouterWithAttributes> element.',
171
            false
172
        );
173
    }
174
175
    /**
176
     * Get the Role visitor.
177
     *
178
     * @return \eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\Root
179
     */
180
    protected function internalGetVisitor()
181
    {
182
        return new ValueObjectVisitor\Root();
183
    }
184
}
185