[TASK] Update caching framework to latest FLOW3 version
[Packages/TYPO3.CMS.git] / tests / t3lib / formprotection / class.t3lib_formprotection_FactoryTest.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010-2011 Oliver Klee (typo3-coding@oliverklee.de)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 require_once('fixtures/class.t3lib_formprotection_testing.php');
26
27 /**
28 * Testcase for the t3lib_formprotection_Factory class.
29 *
30 * @package TYPO3
31 * @subpackage t3lib
32 *
33 * @author Oliver Klee <typo3-coding@oliverklee.de>
34 * @author Ernesto Baschny <ernst@cron-it.de>
35 */
36 class t3lib_formprotection_FactoryTest extends tx_phpunit_testcase {
37 public function setUp() {
38 }
39
40 public function tearDown() {
41 t3lib_formprotection_Factory::purgeInstances();
42 }
43
44
45 /////////////////////////
46 // Tests concerning get
47 /////////////////////////
48
49 /**
50 * @test
51 *
52 * @expectedException InvalidArgumentException
53 */
54 public function getForInexistentClassThrowsException() {
55 t3lib_formprotection_Factory::get('noSuchClass');
56 }
57
58 /**
59 * @test
60 *
61 * @expectedException InvalidArgumentException
62 */
63 public function getForClassThatIsNoFormProtectionSubclassThrowsException() {
64 t3lib_formprotection_Factory::get('t3lib_formprotection_FactoryTest');
65 }
66
67 /**
68 * @test
69 */
70 public function getForTypeBackEndWithExistingBackEndReturnsBackEndFormProtection() {
71 $this->assertTrue(
72 t3lib_formprotection_Factory::get(
73 't3lib_formprotection_BackendFormProtection'
74 ) instanceof t3lib_formprotection_BackendFormProtection
75 );
76 }
77
78 /**
79 * @test
80 */
81 public function getForTypeBackEndCalledTwoTimesReturnsTheSameInstance() {
82 $this->assertSame(
83 t3lib_formprotection_Factory::get(
84 't3lib_formprotection_BackendFormProtection'
85 ),
86 t3lib_formprotection_Factory::get(
87 't3lib_formprotection_BackendFormProtection'
88 )
89 );
90 }
91
92 /**
93 * @test
94 */
95 public function getForTypeInstallToolReturnsInstallToolFormProtection() {
96 $this->assertTrue(
97 t3lib_formprotection_Factory::get(
98 't3lib_formprotection_InstallToolFormProtection'
99 ) instanceof t3lib_formprotection_InstallToolFormProtection
100 );
101 }
102
103 /**
104 * @test
105 */
106 public function getForTypeInstallToolCalledTwoTimesReturnsTheSameInstance() {
107 $this->assertSame(
108 t3lib_formprotection_Factory::get(
109 't3lib_formprotection_InstallToolFormProtection'
110 ),
111 t3lib_formprotection_Factory::get(
112 't3lib_formprotection_InstallToolFormProtection'
113 )
114 );
115 }
116
117 /**
118 * @test
119 */
120 public function getForTypesInstallToolAndBackEndReturnsDifferentInstances() {
121 $this->assertNotSame(
122 t3lib_formprotection_Factory::get(
123 't3lib_formprotection_InstallToolFormProtection'
124 ),
125 t3lib_formprotection_Factory::get(
126 't3lib_formprotection_BackendFormProtection'
127 )
128 );
129 }
130
131
132 /////////////////////////
133 // Tests concerning set
134 /////////////////////////
135
136 /**
137 * @test
138 */
139 public function setSetsInstanceForType() {
140 $instance = new t3lib_formProtection_Testing();
141 t3lib_formprotection_Factory::set(
142 't3lib_formprotection_BackendFormProtection', $instance
143 );
144
145 $this->assertSame(
146 $instance,
147 t3lib_formprotection_Factory::get(
148 't3lib_formprotection_BackendFormProtection'
149 )
150 );
151 }
152
153 /**
154 * @test
155 */
156 public function setNotSetsInstanceForOtherType() {
157 $instance = new t3lib_formProtection_Testing();
158 t3lib_formprotection_Factory::set(
159 't3lib_formprotection_BackendFormProtection', $instance
160 );
161
162 $this->assertNotSame(
163 $instance,
164 t3lib_formprotection_Factory::get(
165 't3lib_formprotection_InstallToolFormProtection'
166 )
167 );
168 }
169 }
170 ?>