|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2010-2011 Oliver Klee (typo3-coding@oliverklee.de) 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * 00017 * This script is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 * GNU General Public License for more details. 00021 * 00022 * This copyright notice MUST APPEAR in all copies of the script! 00023 ***************************************************************/ 00024 00025 require_once('fixtures/class.t3lib_formprotection_testing.php'); 00026 00027 /** 00028 * Testcase for the t3lib_formprotection_Factory class. 00029 * 00030 * $Id$ 00031 * 00032 * @package TYPO3 00033 * @subpackage t3lib 00034 * 00035 * @author Oliver Klee <typo3-coding@oliverklee.de> 00036 * @author Ernesto Baschny <ernst@cron-it.de> 00037 */ 00038 class t3lib_formprotection_FactoryTest extends tx_phpunit_testcase { 00039 public function setUp() { 00040 } 00041 00042 public function tearDown() { 00043 t3lib_formprotection_Factory::purgeInstances(); 00044 } 00045 00046 00047 ///////////////////////// 00048 // Tests concerning get 00049 ///////////////////////// 00050 00051 /** 00052 * @test 00053 * 00054 * @expectedException InvalidArgumentException 00055 */ 00056 public function getForInexistentClassThrowsException() { 00057 t3lib_formprotection_Factory::get('noSuchClass'); 00058 } 00059 00060 /** 00061 * @test 00062 * 00063 * @expectedException InvalidArgumentException 00064 */ 00065 public function getForClassThatIsNoFormProtectionSubclassThrowsException() { 00066 t3lib_formprotection_Factory::get('t3lib_formprotection_FactoryTest'); 00067 } 00068 00069 /** 00070 * @test 00071 */ 00072 public function getForTypeBackEndWithExistingBackEndReturnsBackEndFormProtection() { 00073 $this->assertTrue( 00074 t3lib_formprotection_Factory::get( 00075 't3lib_formprotection_BackendFormProtection' 00076 ) instanceof t3lib_formprotection_BackendFormProtection 00077 ); 00078 } 00079 00080 /** 00081 * @test 00082 */ 00083 public function getForTypeBackEndCalledTwoTimesReturnsTheSameInstance() { 00084 $this->assertSame( 00085 t3lib_formprotection_Factory::get( 00086 't3lib_formprotection_BackendFormProtection' 00087 ), 00088 t3lib_formprotection_Factory::get( 00089 't3lib_formprotection_BackendFormProtection' 00090 ) 00091 ); 00092 } 00093 00094 /** 00095 * @test 00096 */ 00097 public function getForTypeInstallToolReturnsInstallToolFormProtection() { 00098 $this->assertTrue( 00099 t3lib_formprotection_Factory::get( 00100 't3lib_formprotection_InstallToolFormProtection' 00101 ) instanceof t3lib_formprotection_InstallToolFormProtection 00102 ); 00103 } 00104 00105 /** 00106 * @test 00107 */ 00108 public function getForTypeInstallToolCalledTwoTimesReturnsTheSameInstance() { 00109 $this->assertSame( 00110 t3lib_formprotection_Factory::get( 00111 't3lib_formprotection_InstallToolFormProtection' 00112 ), 00113 t3lib_formprotection_Factory::get( 00114 't3lib_formprotection_InstallToolFormProtection' 00115 ) 00116 ); 00117 } 00118 00119 /** 00120 * @test 00121 */ 00122 public function getForTypesInstallToolAndBackEndReturnsDifferentInstances() { 00123 $this->assertNotSame( 00124 t3lib_formprotection_Factory::get( 00125 't3lib_formprotection_InstallToolFormProtection' 00126 ), 00127 t3lib_formprotection_Factory::get( 00128 't3lib_formprotection_BackendFormProtection' 00129 ) 00130 ); 00131 } 00132 00133 00134 ///////////////////////// 00135 // Tests concerning set 00136 ///////////////////////// 00137 00138 /** 00139 * @test 00140 */ 00141 public function setSetsInstanceForType() { 00142 $instance = new t3lib_formProtection_Testing(); 00143 t3lib_formprotection_Factory::set( 00144 't3lib_formprotection_BackendFormProtection', $instance 00145 ); 00146 00147 $this->assertSame( 00148 $instance, 00149 t3lib_formprotection_Factory::get( 00150 't3lib_formprotection_BackendFormProtection' 00151 ) 00152 ); 00153 } 00154 00155 /** 00156 * @test 00157 */ 00158 public function setNotSetsInstanceForOtherType() { 00159 $instance = new t3lib_formProtection_Testing(); 00160 t3lib_formprotection_Factory::set( 00161 't3lib_formprotection_BackendFormProtection', $instance 00162 ); 00163 00164 $this->assertNotSame( 00165 $instance, 00166 t3lib_formprotection_Factory::get( 00167 't3lib_formprotection_InstallToolFormProtection' 00168 ) 00169 ); 00170 } 00171 } 00172 ?>
1.8.0