[TASK] Namespace and move t3lib unit tests - 3
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / FormProtection / FormProtectionFactoryTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\FormProtection;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2010-2011 Oliver Klee (typo3-coding@oliverklee.de)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 require_once 'Fixtures/FormProtectionTesting.php';
28
29 /**
30 * Testcase for the t3lib_formprotection_Factory class.
31 *
32 * @package TYPO3
33 * @subpackage t3lib
34 * @author Oliver Klee <typo3-coding@oliverklee.de>
35 * @author Ernesto Baschny <ernst@cron-it.de>
36 */
37 class FormprotectionFactoryTest extends \tx_phpunit_testcase {
38
39 public function setUp() {
40
41 }
42
43 public function tearDown() {
44 \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::purgeInstances();
45 }
46
47 /////////////////////////
48 // Tests concerning get
49 /////////////////////////
50 /**
51 * @test
52 * @expectedException InvalidArgumentException
53 */
54 public function getForInexistentClassThrowsException() {
55 \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('noSuchClass');
56 }
57
58 /**
59 * @test
60 * @expectedException InvalidArgumentException
61 */
62 public function getForClassThatIsNoFormProtectionSubclassThrowsException() {
63 \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\FormProtectionFactoryTest');
64 }
65
66 /**
67 * @test
68 */
69 public function getForTypeBackEndWithExistingBackEndReturnsBackEndFormProtection() {
70 $this->assertTrue(\TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\BackendFormProtection') instanceof \TYPO3\CMS\Core\FormProtection\BackendFormProtection);
71 }
72
73 /**
74 * @test
75 */
76 public function getForTypeBackEndCalledTwoTimesReturnsTheSameInstance() {
77 $this->assertSame(\TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\BackendFormProtection'), \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\BackendFormProtection'));
78 }
79
80 /**
81 * @test
82 */
83 public function getForTypeInstallToolReturnsInstallToolFormProtection() {
84 $this->assertTrue(\TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\InstallToolFormProtection') instanceof \TYPO3\CMS\Core\FormProtection\InstallToolFormProtection);
85 }
86
87 /**
88 * @test
89 */
90 public function getForTypeInstallToolCalledTwoTimesReturnsTheSameInstance() {
91 $this->assertSame(\TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\InstallToolFormProtection'), \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\InstallToolFormProtection'));
92 }
93
94 /**
95 * @test
96 */
97 public function getForTypesInstallToolAndBackEndReturnsDifferentInstances() {
98 $this->assertNotSame(\TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\InstallToolFormProtection'), \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\BackendFormProtection'));
99 }
100
101 /////////////////////////
102 // Tests concerning set
103 /////////////////////////
104 /**
105 * @test
106 */
107 public function setSetsInstanceForType() {
108 $instance = new \TYPO3\CMS\Core\Tests\Unit\FormProtection\Fixtures\FormProtectionTesting();
109 \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::set('TYPO3\\CMS\\Core\\FormProtection\\BackendFormProtection', $instance);
110 $this->assertSame($instance, \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\BackendFormProtection'));
111 }
112
113 /**
114 * @test
115 */
116 public function setNotSetsInstanceForOtherType() {
117 $instance = new \TYPO3\CMS\Core\Tests\Unit\FormProtection\Fixtures\FormProtectionTesting();
118 \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::set('TYPO3\\CMS\\Core\\FormProtection\\BackendFormProtection', $instance);
119 $this->assertNotSame($instance, \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\InstallToolFormProtection'));
120 }
121
122 }
123
124 ?>