TYPO3 API  SVNRelease
AbstractTemplateViewTest.php
Go to the documentation of this file.
00001 <?php
00002 
00003 /*                                                                        *
00004  * This script belongs to the FLOW3 package "Fluid".                      *
00005  *                                                                        *
00006  * It is free software; you can redistribute it and/or modify it under    *
00007  * the terms of the GNU Lesser General Public License as published by the *
00008  * Free Software Foundation, either version 3 of the License, or (at your *
00009  * option) any later version.                                             *
00010  *                                                                        *
00011  * This script is distributed in the hope that it will be useful, but     *
00012  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
00013  * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser       *
00014  * General Public License for more details.                               *
00015  *                                                                        *
00016  * You should have received a copy of the GNU Lesser General Public       *
00017  * License along with the script.                                         *
00018  * If not, see http://www.gnu.org/licenses/lgpl.html                      *
00019  *                                                                        *
00020  * The TYPO3 project - inspiring people to share!                         *
00021  *                                                                        */
00022 
00023 /**
00024  * Testcase for the TemplateView
00025  *
00026  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
00027  */
00028 class Tx_Fluid_Tests_Unit_View_AbstractTemplateViewTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
00029 
00030     /**
00031      * @var Tx_Fluid_View_AbstractTemplateView
00032      */
00033     protected $view;
00034 
00035     /**
00036      * @var Tx_Fluid_Core_Rendering_RenderingContext
00037      */
00038     protected $renderingContext;
00039 
00040     /**
00041      * @var Tx_Fluid_Core_ViewHelper_ViewHelperVariableContainer
00042      */
00043     protected $viewHelperVariableContainer;
00044 
00045     /**
00046      * @var Tx_Fluid_Core_ViewHelper_TemplateVariableContainer
00047      */
00048     protected $templateVariableContainer;
00049 
00050     /**
00051      * Sets up this test case
00052      * @return void
00053      */
00054     public function setUp() {
00055         $this->templateVariableContainer = $this->getMock('Tx_Fluid_Core_ViewHelper_TemplateVariableContainer', array('exists', 'remove', 'add'));
00056         $this->viewHelperVariableContainer = $this->getMock('Tx_Fluid_Core_ViewHelper_ViewHelperVariableContainer', array('setView'));
00057         $this->renderingContext = $this->getMock('Tx_Fluid_Core_Rendering_RenderingContext', array('getViewHelperVariableContainer', 'getTemplateVariableContainer'));
00058         $this->renderingContext->expects($this->any())->method('getViewHelperVariableContainer')->will($this->returnValue($this->viewHelperVariableContainer));
00059         $this->renderingContext->expects($this->any())->method('getTemplateVariableContainer')->will($this->returnValue($this->templateVariableContainer));
00060         $this->view = $this->getMock('Tx_Fluid_View_AbstractTemplateView', array('getTemplateSource', 'getLayoutSource', 'getPartialSource', 'canRender'));
00061         $this->view->setRenderingContext($this->renderingContext);
00062     }
00063 
00064     /**
00065      * @test
00066      * @author Sebastian Kurfürst <sebastian@typo3.org>
00067      * @author Bastian Waidelich <bastian@typo3.org>
00068      */
00069     public function viewIsPlacedInViewHelperVariableContainer() {
00070         $this->viewHelperVariableContainer->expects($this->once())->method('setView')->with($this->view);
00071         $this->view->setRenderingContext($this->renderingContext);
00072     }
00073 
00074     /**
00075      * @test
00076      * @author Bastian Waidelich <bastian@typo3.org>
00077      */
00078     public function assignAddsValueToTemplateVariableContainer() {
00079         $this->templateVariableContainer->expects($this->at(0))->method('exists')->with('foo')->will($this->returnValue(FALSE));
00080         $this->templateVariableContainer->expects($this->at(1))->method('add')->with('foo', 'FooValue');
00081         $this->templateVariableContainer->expects($this->at(2))->method('exists')->with('bar')->will($this->returnValue(FALSE));
00082         $this->templateVariableContainer->expects($this->at(3))->method('add')->with('bar', 'BarValue');
00083 
00084         $this->view
00085             ->assign('foo', 'FooValue')
00086             ->assign('bar', 'BarValue');
00087     }
00088 
00089     /**
00090      * @test
00091      * @author Bastian Waidelich <bastian@typo3.org>
00092      */
00093     public function assignCanOverridePreviouslyAssignedValues() {
00094         $this->templateVariableContainer->expects($this->at(0))->method('exists')->with('foo')->will($this->returnValue(FALSE));
00095         $this->templateVariableContainer->expects($this->at(1))->method('add')->with('foo', 'FooValue');
00096         $this->templateVariableContainer->expects($this->at(2))->method('exists')->with('foo')->will($this->returnValue(TRUE));
00097         $this->templateVariableContainer->expects($this->at(3))->method('remove')->with('foo');
00098         $this->templateVariableContainer->expects($this->at(4))->method('add')->with('foo', 'FooValueOverridden');
00099 
00100         $this->view->assign('foo', 'FooValue');
00101         $this->view->assign('foo', 'FooValueOverridden');
00102     }
00103 
00104     /**
00105      * @test
00106      * @author Bastian Waidelich <bastian@typo3.org>
00107      */
00108     public function assignMultipleAddsValuesToTemplateVariableContainer() {
00109         $this->templateVariableContainer->expects($this->at(0))->method('exists')->with('foo')->will($this->returnValue(FALSE));
00110         $this->templateVariableContainer->expects($this->at(1))->method('add')->with('foo', 'FooValue');
00111         $this->templateVariableContainer->expects($this->at(2))->method('exists')->with('bar')->will($this->returnValue(FALSE));
00112         $this->templateVariableContainer->expects($this->at(3))->method('add')->with('bar', 'BarValue');
00113         $this->templateVariableContainer->expects($this->at(4))->method('exists')->with('baz')->will($this->returnValue(FALSE));
00114         $this->templateVariableContainer->expects($this->at(5))->method('add')->with('baz', 'BazValue');
00115 
00116         $this->view
00117             ->assignMultiple(array('foo' => 'FooValue', 'bar' => 'BarValue'))
00118             ->assignMultiple(array('baz' => 'BazValue'));
00119     }
00120 
00121     /**
00122      * @test
00123      * @author Bastian Waidelich <bastian@typo3.org>
00124      */
00125     public function assignMultipleCanOverridePreviouslyAssignedValues() {
00126         $this->templateVariableContainer->expects($this->at(0))->method('exists')->with('foo')->will($this->returnValue(FALSE));
00127         $this->templateVariableContainer->expects($this->at(1))->method('add')->with('foo', 'FooValue');
00128         $this->templateVariableContainer->expects($this->at(2))->method('exists')->with('foo')->will($this->returnValue(TRUE));
00129         $this->templateVariableContainer->expects($this->at(3))->method('remove')->with('foo');
00130         $this->templateVariableContainer->expects($this->at(4))->method('add')->with('foo', 'FooValueOverridden');
00131         $this->templateVariableContainer->expects($this->at(5))->method('exists')->with('bar')->will($this->returnValue(FALSE));
00132         $this->templateVariableContainer->expects($this->at(6))->method('add')->with('bar', 'BarValue');
00133 
00134         $this->view->assign('foo', 'FooValue');
00135         $this->view->assignMultiple(array('foo' => 'FooValueOverridden', 'bar' => 'BarValue'));
00136     }
00137 }
00138 
00139 ?>