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