‪TYPO3CMS  11.5
FormProtectionFactoryTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
27 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
28 
32 class ‪FormProtectionFactoryTest extends UnitTestCase
33 {
34  protected function ‪tearDown(): void
35  {
37  parent::tearDown();
38  }
39 
41  // Tests concerning get
43 
47  {
48  $this->expectException(\InvalidArgumentException::class);
49  $this->expectExceptionCode(1285352962);
50 
51  ‪FormProtectionFactory::get('noSuchClass');
52  }
53 
58  {
59  $this->expectException(\InvalidArgumentException::class);
60  $this->expectExceptionCode(1285353026);
61 
62  ‪FormProtectionFactory::get(self::class);
63  }
64 
69  {
70  $userMock = $this->createMock(BackendUserAuthentication::class);
71  $userMock->user = ['uid' => 4711];
72  self::assertInstanceOf(
73  BackendFormProtection::class,
75  BackendFormProtection::class,
76  $userMock,
77  $this->createMock(Registry::class)
78  )
79  );
80  }
81 
86  {
87  $userMock = $this->createMock(BackendUserAuthentication::class);
88  $userMock->user = ['uid' => 4711];
89  $arguments = [
90  BackendFormProtection::class,
91  $userMock,
92  $this->createMock(Registry::class),
93  ];
94  self::assertSame(
95  ‪FormProtectionFactory::get(...$arguments),
96  ‪FormProtectionFactory::get(...$arguments)
97  );
98  }
99 
104  {
105  self::assertInstanceOf(
106  InstallToolFormProtection::class,
107  ‪FormProtectionFactory::get(InstallToolFormProtection::class)
108  );
109  }
110 
115  {
116  self::assertSame(‪FormProtectionFactory::get(InstallToolFormProtection::class), ‪FormProtectionFactory::get(InstallToolFormProtection::class));
117  }
118 
123  {
124  self::assertNotSame(‪FormProtectionFactory::get(InstallToolFormProtection::class), ‪FormProtectionFactory::get(DisabledFormProtection::class));
125  }
126 
128  // Tests concerning set
130 
133  public function ‪setSetsInstanceForType(): void
134  {
135  $instance = new ‪FormProtectionTesting();
136  ‪FormProtectionFactory::set(BackendFormProtection::class, $instance);
137  self::assertSame($instance, ‪FormProtectionFactory::get(BackendFormProtection::class));
138  }
139 
143  public function ‪setNotSetsInstanceForOtherType(): void
144  {
145  $instance = new ‪FormProtectionTesting();
146  ‪FormProtectionFactory::set(BackendFormProtection::class, $instance);
147  self::assertNotSame($instance, ‪FormProtectionFactory::get(InstallToolFormProtection::class));
148  }
149 }
‪TYPO3\CMS\Core\Tests\Unit\FormProtection\FormProtectionFactoryTest\setSetsInstanceForType
‪setSetsInstanceForType()
Definition: FormProtectionFactoryTest.php:133
‪TYPO3\CMS\Core\FormProtection\FormProtectionFactory\get
‪static TYPO3 CMS Core FormProtection AbstractFormProtection get($classNameOrType='default',... $constructorArguments)
Definition: FormProtectionFactory.php:73
‪TYPO3\CMS\Core\Tests\Unit\FormProtection\FormProtectionFactoryTest\getForNotExistingClassThrowsException
‪getForNotExistingClassThrowsException()
Definition: FormProtectionFactoryTest.php:46
‪TYPO3\CMS\Core\FormProtection\DisabledFormProtection
Definition: DisabledFormProtection.php:23
‪TYPO3\CMS\Core\Tests\Unit\FormProtection\FormProtectionFactoryTest\setNotSetsInstanceForOtherType
‪setNotSetsInstanceForOtherType()
Definition: FormProtectionFactoryTest.php:143
‪TYPO3\CMS\Core\FormProtection\FormProtectionFactory\set
‪static set($classNameOrType, AbstractFormProtection $instance)
Definition: FormProtectionFactory.php:221
‪TYPO3\CMS\Core\Tests\Unit\FormProtection\FormProtectionFactoryTest\getForTypeInstallToolCalledTwoTimesReturnsTheSameInstance
‪getForTypeInstallToolCalledTwoTimesReturnsTheSameInstance()
Definition: FormProtectionFactoryTest.php:114
‪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:122
‪TYPO3\CMS\Core\FormProtection\FormProtectionFactory\purgeInstances
‪static purgeInstances()
Definition: FormProtectionFactory.php:231
‪TYPO3\CMS\Core\Tests\Unit\FormProtection\FormProtectionFactoryTest
Definition: FormProtectionFactoryTest.php:33
‪TYPO3\CMS\Core\Tests\Unit\FormProtection\FormProtectionFactoryTest\getForTypeBackEndCalledTwoTimesReturnsTheSameInstance
‪getForTypeBackEndCalledTwoTimesReturnsTheSameInstance()
Definition: FormProtectionFactoryTest.php:85
‪TYPO3\CMS\Core\FormProtection\InstallToolFormProtection
Definition: InstallToolFormProtection.php:61
‪TYPO3\CMS\Core\Tests\Unit\FormProtection\Fixtures\FormProtectionTesting
Definition: FormProtectionTesting.php:29
‪TYPO3\CMS\Core\Tests\Unit\FormProtection\FormProtectionFactoryTest\getForTypeInstallToolReturnsInstallToolFormProtection
‪getForTypeInstallToolReturnsInstallToolFormProtection()
Definition: FormProtectionFactoryTest.php:103
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Core\Tests\Unit\FormProtection\FormProtectionFactoryTest\getForClassThatIsNoFormProtectionSubclassThrowsException
‪getForClassThatIsNoFormProtectionSubclassThrowsException()
Definition: FormProtectionFactoryTest.php:57
‪TYPO3\CMS\Core\FormProtection\FormProtectionFactory
Definition: FormProtectionFactory.php:48
‪TYPO3\CMS\Core\Tests\Unit\FormProtection\FormProtectionFactoryTest\getForTypeBackEndWithExistingBackEndReturnsBackEndFormProtection
‪getForTypeBackEndWithExistingBackEndReturnsBackEndFormProtection()
Definition: FormProtectionFactoryTest.php:68
‪TYPO3\CMS\Core\Tests\Unit\FormProtection\FormProtectionFactoryTest\tearDown
‪tearDown()
Definition: FormProtectionFactoryTest.php:34
‪TYPO3\CMS\Core\Tests\Unit\FormProtection
Definition: AbstractFormProtectionTest.php:18