‪TYPO3CMS  9.5
FormProtectionFactoryTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 class ‪FormProtectionFactoryTest extends UnitTestCase
30 {
31  protected function ‪tearDown()
32  {
34  parent::tearDown();
35  }
36 
38  // Tests concerning get
40 
44  {
45  $this->expectException(\InvalidArgumentException::class);
46  $this->expectExceptionCode(1285352962);
47 
48  ‪FormProtectionFactory::get('noSuchClass');
49  }
50 
55  {
56  $this->expectException(\InvalidArgumentException::class);
57  $this->expectExceptionCode(1285353026);
58 
59  ‪FormProtectionFactory::get(self::class);
60  }
61 
66  {
67  $userMock = $this->createMock(BackendUserAuthentication::class);
68  $userMock->user = ['uid' => $this->getUniqueId()];
69  $this->assertInstanceOf(
70  BackendFormProtection::class,
72  BackendFormProtection::class,
73  $userMock,
74  $this->createMock(Registry::class)
75  )
76  );
77  }
78 
83  {
84  $userMock = $this->createMock(BackendUserAuthentication::class);
85  $userMock->user = ['uid' => $this->getUniqueId()];
86  $arguments = [
87  BackendFormProtection::class,
88  $userMock,
89  $this->createMock(Registry::class)
90  ];
91  $this->assertSame(
92  call_user_func_array([FormProtectionFactory::class, 'get'], $arguments),
93  call_user_func_array([FormProtectionFactory::class, 'get'], $arguments)
94  );
95  }
96 
101  {
102  $this->assertTrue(‪FormProtectionFactory::get(InstallToolFormProtection::class) instanceof ‪InstallToolFormProtection);
103  }
104 
109  {
110  $this->assertSame(‪FormProtectionFactory::get(InstallToolFormProtection::class), ‪FormProtectionFactory::get(InstallToolFormProtection::class));
111  }
112 
117  {
118  $this->assertNotSame(‪FormProtectionFactory::get(InstallToolFormProtection::class), ‪FormProtectionFactory::get(DisabledFormProtection::class));
119  }
120 
122  // Tests concerning set
124 
127  public function ‪setSetsInstanceForType()
128  {
129  $instance = new ‪FormProtectionTesting();
130  ‪FormProtectionFactory::set(BackendFormProtection::class, $instance);
131  $this->assertSame($instance, ‪FormProtectionFactory::get(BackendFormProtection::class));
132  }
133 
138  {
139  $instance = new ‪FormProtectionTesting();
140  ‪FormProtectionFactory::set(BackendFormProtection::class, $instance);
141  $this->assertNotSame($instance, ‪FormProtectionFactory::get(InstallToolFormProtection::class));
142  }
143 }
‪TYPO3\CMS\Core\Tests\Unit\FormProtection\FormProtectionFactoryTest\setSetsInstanceForType
‪setSetsInstanceForType()
Definition: FormProtectionFactoryTest.php:127
‪TYPO3\CMS\Core\FormProtection\FormProtectionFactory\get
‪static TYPO3 CMS Core FormProtection AbstractFormProtection get($classNameOrType='default',... $constructorArguments)
Definition: FormProtectionFactory.php:72
‪TYPO3\CMS\Core\Tests\Unit\FormProtection\FormProtectionFactoryTest\getForNotExistingClassThrowsException
‪getForNotExistingClassThrowsException()
Definition: FormProtectionFactoryTest.php:43
‪TYPO3\CMS\Core\FormProtection\DisabledFormProtection
Definition: DisabledFormProtection.php:22
‪TYPO3\CMS\Core\Tests\Unit\FormProtection\FormProtectionFactoryTest\setNotSetsInstanceForOtherType
‪setNotSetsInstanceForOtherType()
Definition: FormProtectionFactoryTest.php:137
‪TYPO3\CMS\Core\FormProtection\FormProtectionFactory\set
‪static set($classNameOrType, AbstractFormProtection $instance)
Definition: FormProtectionFactory.php:207
‪TYPO3\CMS\Core\Tests\Unit\FormProtection\FormProtectionFactoryTest\getForTypeInstallToolCalledTwoTimesReturnsTheSameInstance
‪getForTypeInstallToolCalledTwoTimesReturnsTheSameInstance()
Definition: FormProtectionFactoryTest.php:108
‪TYPO3\CMS\Core\Registry
Definition: Registry.php:32
‪TYPO3\CMS\Core\FormProtection\BackendFormProtection
Definition: BackendFormProtection.php:73
‪TYPO3\CMS\Core\Tests\Unit\FormProtection\FormProtectionFactoryTest\getForTypesInstallToolAndDisabledReturnsDifferentInstances
‪getForTypesInstallToolAndDisabledReturnsDifferentInstances()
Definition: FormProtectionFactoryTest.php:116
‪TYPO3\CMS\Core\FormProtection\FormProtectionFactory\purgeInstances
‪static purgeInstances()
Definition: FormProtectionFactory.php:217
‪TYPO3\CMS\Core\Tests\Unit\FormProtection\FormProtectionFactoryTest
Definition: FormProtectionFactoryTest.php:30
‪TYPO3\CMS\Core\Tests\Unit\FormProtection\FormProtectionFactoryTest\getForTypeBackEndCalledTwoTimesReturnsTheSameInstance
‪getForTypeBackEndCalledTwoTimesReturnsTheSameInstance()
Definition: FormProtectionFactoryTest.php:82
‪TYPO3\CMS\Core\FormProtection\InstallToolFormProtection
Definition: InstallToolFormProtection.php:60
‪TYPO3\CMS\Core\Tests\Unit\FormProtection\Fixtures\FormProtectionTesting
Definition: FormProtectionTesting.php:24
‪TYPO3\CMS\Core\Tests\Unit\FormProtection\FormProtectionFactoryTest\getForTypeInstallToolReturnsInstallToolFormProtection
‪getForTypeInstallToolReturnsInstallToolFormProtection()
Definition: FormProtectionFactoryTest.php:100
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:45
‪TYPO3\CMS\Core\Tests\Unit\FormProtection\FormProtectionFactoryTest\getForClassThatIsNoFormProtectionSubclassThrowsException
‪getForClassThatIsNoFormProtectionSubclassThrowsException()
Definition: FormProtectionFactoryTest.php:54
‪TYPO3\CMS\Core\FormProtection\FormProtectionFactory
Definition: FormProtectionFactory.php:45
‪TYPO3\CMS\Core\Tests\Unit\FormProtection\FormProtectionFactoryTest\getForTypeBackEndWithExistingBackEndReturnsBackEndFormProtection
‪getForTypeBackEndWithExistingBackEndReturnsBackEndFormProtection()
Definition: FormProtectionFactoryTest.php:65
‪TYPO3\CMS\Core\Tests\Unit\FormProtection\FormProtectionFactoryTest\tearDown
‪tearDown()
Definition: FormProtectionFactoryTest.php:31
‪TYPO3\CMS\Core\Tests\Unit\FormProtection
Definition: AbstractFormProtectionTest.php:3