Completed
Push — EZP-31776 ( f8b5ee...e4a561 )
by
unknown
22:20
created

RestExecutedViewTest::getLocationServiceMock()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
namespace eZ\Publish\Core\REST\Server\Tests\Output\ValueObjectVisitor;
8
9
use eZ\Publish\API\Repository\ContentService;
10
use eZ\Publish\API\Repository\ContentTypeService;
11
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
12
use eZ\Publish\API\Repository\Values\Content\Search\SearchHit;
13
use eZ\Publish\API\Repository\Values\Content\Search\SearchResult;
14
use eZ\Publish\Core\Repository\LocationResolver\LocationResolver;
15
use eZ\Publish\Core\Repository\Values\ContentType\ContentType;
16
use eZ\Publish\Core\REST\Common\Tests\Output\ValueObjectVisitorBaseTest;
17
use eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor;
18
use eZ\Publish\Core\Repository\Values\Content;
19
use eZ\Publish\Core\REST\Server\Values\RestExecutedView;
20
use eZ\Publish\Core\Repository\Values\Content as ApiValues;
21
22
class RestExecutedViewTest extends ValueObjectVisitorBaseTest
23
{
24
    /**
25
     * Test the RestExecutedView visitor.
26
     *
27
     * @return \DOMDocument
28
     */
29
    public function testVisit()
30
    {
31
        $visitor = $this->getVisitor();
32
        $generator = $this->getGenerator();
33
34
        $generator->startDocument(null);
35
36
        $view = new RestExecutedView(
37
            [
38
                'identifier' => 'test_view',
39
                'searchResults' => new SearchResult([
40
                    'searchHits' => [
41
                        $this->buildContentSearchHit(),
42
                        $this->buildLocationSearchHit(),
43
                    ],
44
                ]),
45
            ]
46
        );
47
48
        $this->addRouteExpectation(
49
            'ezpublish_rest_views_load',
50
            ['viewId' => $view->identifier],
51
            "/content/views/{$view->identifier}"
52
        );
53
        $this->addRouteExpectation(
54
            'ezpublish_rest_views_load_results',
55
            ['viewId' => $view->identifier],
56
            "/content/views/{$view->identifier}/results"
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
            $view
63
        );
64
65
        $result = $generator->endDocument(null);
66
67
        $this->assertNotNull($result);
68
69
        $dom = new \DOMDocument();
70
        $dom->loadXml($result);
71
72
        return $dom;
73
    }
74
75 View Code Duplication
    public function provideXpathAssertions()
76
    {
77
        return [
78
            ['/View'],
79
            ['/View[@media-type="application/vnd.ez.api.View+xml"]'],
80
            ['/View[@href="/content/views/test_view"]'],
81
            ['/View/identifier'],
82
            ['/View/identifier[text()="test_view"]'],
83
            ['/View/Query'],
84
            ['/View/Query[@media-type="application/vnd.ez.api.Query+xml"]'],
85
            ['/View/Result'],
86
            ['/View/Result[@media-type="application/vnd.ez.api.ViewResult+xml"]'],
87
            ['/View/Result[@href="/content/views/test_view/results"]'],
88
            ['/View/Result/searchHits/searchHit[@score="0.123" and @index="alexandria"]'],
89
            ['/View/Result/searchHits/searchHit[@score="0.234" and @index="waze"]'],
90
        ];
91
    }
92
93
    /**
94
     * @param string $xpath
95
     * @param \DOMDocument $dom
96
     *
97
     * @depends testVisit
98
     * @dataProvider provideXpathAssertions
99
     */
100
    public function testGeneratedXml($xpath, \DOMDocument $dom)
101
    {
102
        $this->assertXPath($dom, $xpath);
103
    }
104
105
    /**
106
     * Get the Relation visitor.
107
     *
108
     * @return \eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\RestExecutedView
109
     */
110
    protected function internalGetVisitor()
111
    {
112
        return new ValueObjectVisitor\RestExecutedView(
113
            $this->getContentServiceMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->getContentServiceMock() targeting eZ\Publish\Core\REST\Ser...getContentServiceMock() can also be of type object<PHPUnit\Framework\MockObject\MockObject>; however, eZ\Publish\Core\REST\Ser...utedView::__construct() does only seem to accept object<eZ\Publish\API\Repository\ContentService>, 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...
114
            $this->getLocationResolverMock()
0 ignored issues
show
Bug introduced by
It seems like $this->getLocationResolverMock() targeting eZ\Publish\Core\REST\Ser...tLocationResolverMock() can also be of type object<PHPUnit\Framework\MockObject\MockObject>; however, eZ\Publish\Core\REST\Ser...utedView::__construct() does only seem to accept object<eZ\Publish\Core\R...olver\LocationResolver>, 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...
115
        );
116
    }
117
118
    /**
119
     * @return \eZ\Publish\API\Repository\ContentService|\PHPUnit\Framework\MockObject\MockObject
120
     */
121
    public function getContentServiceMock()
122
    {
123
        return $this->createMock(ContentService::class);
124
    }
125
126
    /**
127
     * @return \eZ\Publish\API\Repository\ContentTypeService|\PHPUnit\Framework\MockObject\MockObject
128
     */
129
    public function getContentTypeServiceMock()
130
    {
131
        return $this->createMock(ContentTypeService::class);
132
    }
133
134
    /**
135
     * @return \eZ\Publish\Core\Repository\LocationResolver\LocationResolver|\PHPUnit\Framework\MockObject\MockObject
136
     */
137
    public function getLocationResolverMock()
138
    {
139
        return $this->createMock(LocationResolver::class);
140
    }
141
142
    /**
143
     * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchHit
144
     */
145
    protected function buildContentSearchHit()
146
    {
147
        return new SearchHit([
148
            'score' => 0.123,
149
            'index' => 'alexandria',
150
            'valueObject' => new ApiValues\Content([
151
                'versionInfo' => new Content\VersionInfo(['contentInfo' => new ContentInfo()]),
152
                'contentType' => new ContentType(),
153
            ]),
154
        ]);
155
    }
156
157
    /**
158
     * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchHit
159
     */
160
    protected function buildLocationSearchHit()
161
    {
162
        return new SearchHit([
163
            'score' => 0.234,
164
            'index' => 'waze',
165
            'valueObject' => new ApiValues\Location(),
166
        ]);
167
    }
168
}
169