| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This file is part of the Superdesk Web Publisher Templates System. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * Copyright 2015 Sourcefabric z.ú. and contributors. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * For the full copyright and license information, please see the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * AUTHORS and LICENSE files distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @copyright 2015 Sourcefabric z.ú | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @license http://www.superdesk.org/license | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | namespace SWP\Component\TemplatesSystem\Tests\Twig\Node; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use SWP\Component\TemplatesSystem\Twig\Node\ContainerNode; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | class ContainerNodeTest extends \Twig_Test_NodeTestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | { | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 21 |  | View Code Duplication |     public function testConstructor() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         $name = new \Twig_Node([new \Twig_Node_Expression_Constant('container_name', 1)]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         $parameters = new \Twig_Node_Expression_Array([], 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         $body = new \Twig_Node_Text('', 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         $node = new ContainerNode($name, $parameters, $body, 1, 'gimme'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         $this->assertEquals($name, $node->getNode('name')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         $this->assertEquals($parameters, $node->getNode('parameters')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         $this->assertEquals($body, $node->getNode('body')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 32 |  | View Code Duplication |     public function getTests() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         $name1 = new \Twig_Node([new \Twig_Node_Expression_Constant('container_name', 1)]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         $parameters1 = new \Twig_Node_Expression_Array([], 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $body1 = new \Twig_Node_Text('Test body', 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $node1 = new ContainerNode($name1, $parameters1, $body1, 1, 'gimme'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $name2 = new \Twig_Node([new \Twig_Node_Expression_Constant('container_name', 2)]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         $body2 = new \Twig_Node_Text('Test body', 2); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $node2 = new ContainerNode($name2, null, $body2, 2, 'gimme'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $name3 = new \Twig_Node([new \Twig_Node_Expression_Constant('container_name', 3)]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         $parameters3 = new \Twig_Node_Expression_Array([new \Twig_Node_Expression_Constant('foo', 1), new \Twig_Node_Expression_Constant(true, 1)], 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         $body3 = new \Twig_Node_Text('Test body', 3); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $node3 = new ContainerNode($name3, $parameters3, $body3, 3, 'gimme'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |             [$node1, <<<'EOF' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | // line 1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | $containerService = $this->env->getExtension('swp_container')->getContainerService(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | $container = $containerService->getContainer("container_name", array()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | if ($container->isVisible()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     echo $container->renderOpenTag(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     if ($container->hasWidgets()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         echo $container->renderWidgets(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         echo "Test body"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     echo $container->renderCloseTag(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | unset($container);unset($containerService); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | EOF | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |             [$node2, <<<'EOF' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | // line 2 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | $containerService = $this->env->getExtension('swp_container')->getContainerService(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | $container = $containerService->getContainer("container_name", array()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | if ($container->isVisible()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     echo $container->renderOpenTag(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     if ($container->hasWidgets()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         echo $container->renderWidgets(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         echo "Test body"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     echo $container->renderCloseTag(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | unset($container);unset($containerService); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | EOF | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |             [$node3, <<<'EOF' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | // line 3 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | $containerService = $this->env->getExtension('swp_container')->getContainerService(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | $container = $containerService->getContainer("container_name", array("foo" => true)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | if ($container->isVisible()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     echo $container->renderOpenTag(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     if ($container->hasWidgets()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         echo $container->renderWidgets(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         echo "Test body"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     echo $container->renderCloseTag(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | unset($container);unset($containerService); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | EOF | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 100 |  |  |     protected function tearDown() | 
            
                                                        
            
                                    
            
            
                | 101 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 102 |  |  |         $reflection = new \ReflectionObject($this); | 
            
                                                        
            
                                    
            
            
                | 103 |  |  |         foreach ($reflection->getProperties() as $prop) { | 
            
                                                        
            
                                    
            
            
                | 104 |  |  |             if (!$prop->isStatic() && 0 !== strpos($prop->getDeclaringClass()->getName(), 'PHPUnit_')) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 105 |  |  |                 $prop->setAccessible(true); | 
            
                                                        
            
                                    
            
            
                | 106 |  |  |                 $prop->setValue($this, null); | 
            
                                                        
            
                                    
            
            
                | 107 |  |  |             } | 
            
                                                        
            
                                    
            
            
                | 108 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 109 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 110 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 111 |  |  |  | 
            
                        
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.