Revert "[TASK] Namespace and move t3lib unit tests - 3"
[Packages/TYPO3.CMS.git] / tests / Unit / 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 require_once 'fixtures/class.t3lib_formprotection_testing.php';
25 /**
26 * Testcase for the t3lib_formprotection_Factory class.
27 *
28 * @package TYPO3
29 * @subpackage t3lib
30 * @author Oliver Klee <typo3-coding@oliverklee.de>
31 * @author Ernesto Baschny <ernst@cron-it.de>
32 */
33 class t3lib_formprotection_FactoryTest extends tx_phpunit_testcase {
34
35 public function setUp() {
36
37 }
38
39 public function tearDown() {
40 \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::purgeInstances();
41 }
42
43 /////////////////////////
44 // Tests concerning get
45 /////////////////////////
46 /**
47 * @test
48 * @expectedException InvalidArgumentException
49 */
50 public function getForInexistentClassThrowsException() {
51 \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('noSuchClass');
52 }
53
54 /**
55 * @test
56 * @expectedException InvalidArgumentException
57 */
58 public function getForClassThatIsNoFormProtectionSubclassThrowsException() {
59 \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\FormProtectionFactoryTest');
60 }
61
62 /**
63 * @test
64 */
65 public function getForTypeBackEndWithExistingBackEndReturnsBackEndFormProtection() {
66 $this->assertTrue(\TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\BackendFormProtection') instanceof \TYPO3\CMS\Core\FormProtection\BackendFormProtection);
67 }
68
69 /**
70 * @test
71 */
72 public function getForTypeBackEndCalledTwoTimesReturnsTheSameInstance() {
73 $this->assertSame(\TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\BackendFormProtection'), \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\BackendFormProtection'));
74 }
75
76 /**
77 * @test
78 */
79 public function getForTypeInstallToolReturnsInstallToolFormProtection() {
80 $this->assertTrue(\TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\InstallToolFormProtection') instanceof \TYPO3\CMS\Core\FormProtection\InstallToolFormProtection);
81 }
82
83 /**
84 * @test
85 */
86 public function getForTypeInstallToolCalledTwoTimesReturnsTheSameInstance() {
87 $this->assertSame(\TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\InstallToolFormProtection'), \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\InstallToolFormProtection'));
88 }
89
90 /**
91 * @test
92 */
93 public function getForTypesInstallToolAndBackEndReturnsDifferentInstances() {
94 $this->assertNotSame(\TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\InstallToolFormProtection'), \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\BackendFormProtection'));
95 }
96
97 /////////////////////////
98 // Tests concerning set
99 /////////////////////////
100 /**
101 * @test
102 */
103 public function setSetsInstanceForType() {
104 $instance = new t3lib_formProtection_Testing();
105 \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::set('TYPO3\\CMS\\Core\\FormProtection\\BackendFormProtection', $instance);
106 $this->assertSame($instance, \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\BackendFormProtection'));
107 }
108
109 /**
110 * @test
111 */
112 public function setNotSetsInstanceForOtherType() {
113 $instance = new t3lib_formProtection_Testing();
114 \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::set('TYPO3\\CMS\\Core\\FormProtection\\BackendFormProtection', $instance);
115 $this->assertNotSame($instance, \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\InstallToolFormProtection'));
116 }
117
118 }
119
120 ?>