Completed
Push — 6.13 ( 055733...f64074 )
by André
23:24 queued 09:44
created

VersionTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 165
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 13

Importance

Changes 0
Metric Value
dl 0
loc 165
rs 10
c 0
b 0
f 0
wmc 6
lcom 2
cbo 13

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
B testVisit() 0 77 1
A testResultContainsVersionChildren() 0 15 1
A testResultVersionAttributes() 0 15 1
A testResultContainsFieldsChildren() 0 15 1
A internalGetVisitor() 0 4 1
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
namespace eZ\Publish\Core\REST\Server\Tests\Output\ValueObjectVisitor;
10
11
use eZ\Publish\API\Repository\Values\ContentType\ContentType;
12
use eZ\Publish\Core\REST\Common\Output\Generator;
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;
16
use eZ\Publish\Core\REST\Server\Values\Version;
17
use eZ\Publish\API\Repository\Values\Content\Field;
18
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
19
use eZ\Publish\Core\REST\Common\Output\FieldTypeSerializer;
20
21
class VersionTest extends ValueObjectVisitorBaseTest
22
{
23
    protected $fieldTypeSerializerMock;
24
25
    public function setUp()
26
    {
27
        $this->fieldTypeSerializerMock = $this->createMock(FieldTypeSerializer::class);
28
    }
29
30
    /**
31
     * Test the Version visitor.
32
     *
33
     * @return string
34
     */
35
    public function testVisit()
36
    {
37
        $visitor = $this->getVisitor();
38
        $generator = $this->getGenerator();
39
40
        $generator->startDocument(null);
41
42
        $version = new Version(
43
            new Values\Content\Content(
44
                array(
45
                    'versionInfo' => new Values\Content\VersionInfo(
46
                        array(
47
                            'versionNo' => 5,
48
                            'contentInfo' => new ContentInfo(
49
                                array(
50
                                    'id' => 23,
51
                                    'contentTypeId' => 42,
52
                                )
53
                            ),
54
                        )
55
                    ),
56
                    'internalFields' => array(
57
                        new Field(
58
                            array(
59
                                'id' => 1,
60
                                'languageCode' => 'eng-US',
61
                                'fieldDefIdentifier' => 'ezauthor',
62
                                'typeIdentifier' => 'ezauthor',
63
                            )
64
                        ),
65
                        new Field(
66
                            array(
67
                                'id' => 2,
68
                                'languageCode' => 'eng-US',
69
                                'fieldDefIdentifier' => 'ezimage',
70
                                'typeIdentifier' => 'ezauthor',
71
                            )
72
                        ),
73
                    ),
74
                )
75
            ),
76
            $this->getMockForAbstractClass(ContentType::class),
77
            array()
78
        );
79
80
        $this->fieldTypeSerializerMock->expects($this->exactly(2))
81
            ->method('serializeFieldValue')
82
            ->with(
83
                $this->isInstanceOf(Generator::class),
84
                $this->isInstanceOf(ContentType::class),
85
                $this->isInstanceOf(Field::class)
86
            );
87
88
        $this->getVisitorMock()->expects($this->exactly(2))
89
            ->method('visitValueObject');
90
91
        $this->addRouteExpectation(
92
            'ezpublish_rest_loadContentInVersion',
93
            array(
94
                'contentId' => $version->content->id,
95
                'versionNumber' => $version->content->versionInfo->versionNo,
96
            ),
97
            "/content/objects/{$version->content->id}/versions/{$version->content->versionInfo->versionNo}"
98
        );
99
100
        $visitor->visit(
101
            $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...
102
            $generator,
103
            $version
104
        );
105
106
        $result = $generator->endDocument(null);
107
108
        $this->assertNotNull($result);
109
110
        return $result;
111
    }
112
113
    /**
114
     * @param string $result
115
     *
116
     * @depends testVisit
117
     */
118
    public function testResultContainsVersionChildren($result)
119
    {
120
        $this->assertXMLTag(
121
            array(
122
                'tag' => 'Version',
123
                'children' => array(
124
                    'less_than' => 2,
125
                    'greater_than' => 0,
126
                ),
127
            ),
128
            $result,
129
            'Invalid <Version> element.',
130
            false
131
        );
132
    }
133
134
    /**
135
     * @param string $result
136
     *
137
     * @depends testVisit
138
     */
139
    public function testResultVersionAttributes($result)
140
    {
141
        $this->assertXMLTag(
142
            array(
143
                'tag' => 'Version',
144
                'attributes' => array(
145
                    'media-type' => 'application/vnd.ez.api.Version+xml',
146
                    'href' => '/content/objects/23/versions/5',
147
                ),
148
            ),
149
            $result,
150
            'Invalid <Version> attributes.',
151
            false
152
        );
153
    }
154
155
    /**
156
     * @param string $result
157
     *
158
     * @depends testVisit
159
     */
160
    public function testResultContainsFieldsChildren($result)
161
    {
162
        $this->assertXMLTag(
163
            array(
164
                'tag' => 'Fields',
165
                'children' => array(
166
                    'less_than' => 3,
167
                    'greater_than' => 1,
168
                ),
169
            ),
170
            $result,
171
            'Invalid <Fields> element.',
172
            false
173
        );
174
    }
175
176
    /**
177
     * Get the Version visitor.
178
     *
179
     * @return \eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\Version
180
     */
181
    protected function internalGetVisitor()
182
    {
183
        return new ValueObjectVisitor\Version($this->fieldTypeSerializerMock);
184
    }
185
}
186