| 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\LocationService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use eZ\Publish\API\Repository\Values\Content\ContentInfo; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use eZ\Publish\API\Repository\Values\Content\Search\SearchHit; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use eZ\Publish\API\Repository\Values\Content\Search\SearchResult; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use eZ\Publish\Core\Repository\LocationResolver\LocationResolver; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use eZ\Publish\Core\Repository\Values\ContentType\ContentType; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use eZ\Publish\Core\REST\Common\Tests\Output\ValueObjectVisitorBaseTest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use eZ\Publish\Core\Repository\Values\Content; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use eZ\Publish\Core\REST\Server\Values\RestExecutedView; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | use eZ\Publish\Core\Repository\Values\Content as ApiValues; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | class RestExecutedViewTest extends ValueObjectVisitorBaseTest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      * Test the RestExecutedView visitor. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * @return \DOMDocument | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     public function testVisit() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         $visitor = $this->getVisitor(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $generator = $this->getGenerator(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         $generator->startDocument(null); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $view = new RestExecutedView( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |                 'identifier' => 'test_view', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |                 'searchResults' => new SearchResult([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |                     'searchHits' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |                         $this->buildContentSearchHit(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |                         $this->buildLocationSearchHit(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |                     ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |                 ]), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         $this->addRouteExpectation( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |             'ezpublish_rest_views_load', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             ['viewId' => $view->identifier], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |             "/content/views/{$view->identifier}" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $this->addRouteExpectation( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             'ezpublish_rest_views_load_results', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |             ['viewId' => $view->identifier], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |             "/content/views/{$view->identifier}/results" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $visitor->visit( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |             $this->getVisitorMock(), | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |             $generator, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |             $view | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         $result = $generator->endDocument(null); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         $this->assertNotNull($result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         $dom = new \DOMDocument(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         $dom->loadXml($result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         return $dom; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 76 |  | View Code Duplication |     public function provideXpathAssertions() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |             ['/View'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |             ['/View[@media-type="application/vnd.ez.api.View+xml"]'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |             ['/View[@href="/content/views/test_view"]'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |             ['/View/identifier'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |             ['/View/identifier[text()="test_view"]'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |             ['/View/Query'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |             ['/View/Query[@media-type="application/vnd.ez.api.Query+xml"]'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |             ['/View/Result'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |             ['/View/Result[@media-type="application/vnd.ez.api.ViewResult+xml"]'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |             ['/View/Result[@href="/content/views/test_view/results"]'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |             ['/View/Result/searchHits/searchHit[@score="0.123" and @index="alexandria"]'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |             ['/View/Result/searchHits/searchHit[@score="0.234" and @index="waze"]'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |      * @param string $xpath | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |      * @param \DOMDocument $dom | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |      * @depends testVisit | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |      * @dataProvider provideXpathAssertions | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     public function testGeneratedXml($xpath, \DOMDocument $dom) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         $this->assertXPath($dom, $xpath); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |      * Get the Relation visitor. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |      * @return \eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\RestExecutedView | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |     protected function internalGetVisitor() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |         return new ValueObjectVisitor\RestExecutedView( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |             $this->getLocationServiceMock(), | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |             $this->getContentServiceMock(), | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |             $this->getLocationResolverMock() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |      * @return \eZ\Publish\API\Repository\LocationService|\PHPUnit\Framework\MockObject\MockObject | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |     public function getLocationServiceMock() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |         return $this->createMock(LocationService::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |      * @return \eZ\Publish\API\Repository\ContentService|\PHPUnit\Framework\MockObject\MockObject | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |     public function getContentServiceMock() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |         return $this->createMock(ContentService::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |      * @return \eZ\Publish\API\Repository\ContentTypeService|\PHPUnit\Framework\MockObject\MockObject | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |     public function getContentTypeServiceMock() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |         return $this->createMock(ContentTypeService::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |      * @return \eZ\Publish\Core\Repository\LocationResolver\LocationResolver|\PHPUnit\Framework\MockObject\MockObject | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 146 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 147 |  |  |     public function getLocationResolverMock() | 
            
                                                                        
                            
            
                                    
            
            
                | 148 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 149 |  |  |         return $this->createMock(LocationResolver::class); | 
            
                                                                        
                            
            
                                    
            
            
                | 150 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |      * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchHit | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |     protected function buildContentSearchHit() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |         return new SearchHit([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |             'score' => 0.123, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |             'index' => 'alexandria', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |             'valueObject' => new ApiValues\Content([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |                 'versionInfo' => new Content\VersionInfo(['contentInfo' => new ContentInfo()]), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |                 'contentType' => new ContentType(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |             ]), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |      * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchHit | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |     protected function buildLocationSearchHit() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |         return new SearchHit([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |             'score' => 0.234, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |             'index' => 'waze', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |             'valueObject' => new ApiValues\Location(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 178 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 179 |  |  |  | 
            
                        
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.