|
TYPO3 API
SVNRelease
|
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 require_once(dirname(__FILE__) . '/../Fixtures/TestViewHelper.php'); 00024 00025 /** 00026 * Testcase for AbstractViewHelper 00027 * 00028 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later 00029 */ 00030 class Tx_Fluid_Tests_Unit_Core_ViewHelper_ViewHelperVariableContainerTest extends Tx_Extbase_Tests_Unit_BaseTestCase { 00031 00032 /** 00033 * 00034 * @var Tx_Fluid_Core_ViewHelper_ViewHelperVariableContainer 00035 */ 00036 protected $viewHelperVariableContainer; 00037 00038 protected function setUp() { 00039 $this->viewHelperVariableContainer = new Tx_Fluid_Core_ViewHelper_ViewHelperVariableContainer(); 00040 } 00041 /** 00042 * @test 00043 * @author Sebastian Kurfürst <sebastian@typo3.org> 00044 */ 00045 public function storedDataCanBeReadOutAgain() { 00046 $variable = 'Hello world'; 00047 $this->assertFalse($this->viewHelperVariableContainer->exists('Tx_Fluid_ViewHelpers_TestViewHelper', 'test')); 00048 $this->viewHelperVariableContainer->add('Tx_Fluid_ViewHelpers_TestViewHelper', 'test', $variable); 00049 $this->assertTrue($this->viewHelperVariableContainer->exists('Tx_Fluid_ViewHelpers_TestViewHelper', 'test')); 00050 00051 $this->assertEquals($variable, $this->viewHelperVariableContainer->get('Tx_Fluid_ViewHelpers_TestViewHelper', 'test')); 00052 } 00053 00054 /** 00055 * @test 00056 * @author Sebastian Kurfürst <sebastian@typo3.org> 00057 * @expectedException Tx_Fluid_Core_ViewHelper_Exception_InvalidVariableException 00058 */ 00059 public function gettingNonNonExistentValueThrowsException() { 00060 $this->viewHelperVariableContainer->get('Tx_Fluid_ViewHelper_NonExistent', 'nonExistentKey'); 00061 } 00062 00063 /** 00064 * @test 00065 * @author Sebastian Kurfürst <sebastian@typo3.org> 00066 * @expectedException Tx_Fluid_Core_ViewHelper_Exception_InvalidVariableException 00067 */ 00068 public function settingKeyWhichIsAlreadyStoredThrowsException() { 00069 $this->viewHelperVariableContainer->add('Tx_Fluid_ViewHelper_NonExistent', 'nonExistentKey', 'value1'); 00070 $this->viewHelperVariableContainer->add('Tx_Fluid_ViewHelper_NonExistent', 'nonExistentKey', 'value2'); 00071 } 00072 00073 /** 00074 * @test 00075 * @author Sebastian Kurfürst <sebastian@typo3.org> 00076 */ 00077 public function addOrUpdateWorks() { 00078 $this->viewHelperVariableContainer->add('Tx_Fluid_ViewHelper_NonExistent', 'nonExistentKey', 'value1'); 00079 $this->viewHelperVariableContainer->addOrUpdate('Tx_Fluid_ViewHelper_NonExistent', 'nonExistentKey', 'value2'); 00080 $this->assertEquals($this->viewHelperVariableContainer->get('Tx_Fluid_ViewHelper_NonExistent', 'nonExistentKey'), 'value2'); 00081 } 00082 00083 /** 00084 * @test 00085 * @author Sebastian Kurfürst <sebastian@typo3.org> 00086 */ 00087 public function aSetValueCanBeRemovedAgain() { 00088 $this->viewHelperVariableContainer->add('Tx_Fluid_ViewHelper_NonExistent', 'nonExistentKey', 'value1'); 00089 $this->viewHelperVariableContainer->remove('Tx_Fluid_ViewHelper_NonExistent', 'nonExistentKey'); 00090 $this->assertFalse($this->viewHelperVariableContainer->exists('Tx_Fluid_ViewHelper_NonExistent', 'nonExistentKey')); 00091 } 00092 00093 /** 00094 * @test 00095 * @author Sebastian Kurfürst <sebastian@typo3.org> 00096 * @expectedException Tx_Fluid_Core_ViewHelper_Exception_InvalidVariableException 00097 */ 00098 public function removingNonExistentKeyThrowsException() { 00099 $this->viewHelperVariableContainer->remove('Tx_Fluid_ViewHelper_NonExistent', 'nonExistentKey'); 00100 } 00101 00102 /** 00103 * @test 00104 * @author Sebastian Kurfürst <sebastian@typo3.org> 00105 */ 00106 public function viewCanBeReadOutAgain() { 00107 $view = $this->getMock('Tx_Fluid_View_AbstractTemplateView', array('getTemplateSource', 'getLayoutSource', 'getPartialSource', 'hasTemplate', 'canRender')); 00108 $this->viewHelperVariableContainer->setView($view); 00109 $this->assertSame($view, $this->viewHelperVariableContainer->getView()); 00110 } 00111 } 00112 ?>
1.8.0