| 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 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | namespace eZ\Publish\Core\MVC\Symfony\View\Tests; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use eZ\Publish\Core\MVC\Symfony\View\ContentView; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use eZ\Publish\Core\MVC\Symfony\View\View; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * @group mvc | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | class ContentViewTest extends AbstractViewTest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      * Params that are always returned by this view. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     private $valueParams = ['content' => null]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      * @dataProvider constructProvider | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * @covers \eZ\Publish\Core\MVC\Symfony\View\ContentView::__construct | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * @covers \eZ\Publish\Core\MVC\Symfony\View\ContentView::getTemplateIdentifier | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * @covers \eZ\Publish\Core\MVC\Symfony\View\ContentView::getParameters | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     public function testConstruct($templateIdentifier, array $params) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $contentView = new ContentView($templateIdentifier, $params); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         self::assertSame($templateIdentifier, $contentView->getTemplateIdentifier()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         self::assertSame($this->valueParams + $params, $contentView->getParameters()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |     public function constructProvider() | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |         return [ | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |             ['some:valid:identifier', ['foo' => 'bar']], | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |             ['another::identifier', []], | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |             ['oops:i_did_it:again', ['singer' => 'Britney Spears']], | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |             [ | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |                 function () { | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |                     return true; | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |                 }, | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |                 [], | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |             ], | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |             [ | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |                 function () { | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |                     return true; | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |                 }, | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |                 ['truc' => 'muche'], | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |             ], | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |         ]; | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      * @dataProvider constructFailProvider | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      * @expectedException \eZ\Publish\Core\Base\Exceptions\InvalidArgumentType | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * @covers \eZ\Publish\Core\MVC\Symfony\View\ContentView::__construct | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     public function testConstructFail($templateIdentifier) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         new ContentView($templateIdentifier); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 69 |  | View Code Duplication |     public function constructFailProvider() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |             [123], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |             [new \stdClass()], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |             [[1, 2, 3]], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     protected function createViewUnderTest($template = null, array $parameters = [], $viewType = 'full'): View | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         return new ContentView($template, $parameters, $viewType); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     protected function getAlwaysAvailableParams(): array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         return $this->valueParams; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 87 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 88 |  |  |  |