TYPO3 CMS  TYPO3_7-6
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 
19 
24 {
25  protected function setUp()
26  {
27  }
28 
29  protected function tearDown()
30  {
32  parent::tearDown();
33  }
34 
36  // Tests concerning get
38 
43  {
44  FormProtectionFactory::get('noSuchClass');
45  }
46 
52  {
53  FormProtectionFactory::get(\TYPO3\CMS\Core\Tests\Unit\FormProtection\FormProtectionFactoryTest::class);
54  }
55 
60  {
61  $userMock = $this->getMock(\TYPO3\CMS\Core\Authentication\BackendUserAuthentication::class, [], [], '', false);
62  $userMock->user = ['uid' => $this->getUniqueId()];
63  $this->assertInstanceOf(
64  \TYPO3\CMS\Core\FormProtection\BackendFormProtection::class,
66  \TYPO3\CMS\Core\FormProtection\BackendFormProtection::class,
67  $userMock,
68  $this->getMock(Registry::class)
69  )
70  );
71  }
72 
77  {
78  $userMock = $this->getMock(\TYPO3\CMS\Core\Authentication\BackendUserAuthentication::class, [], [], '', false);
79  $userMock->user = ['uid' => $this->getUniqueId()];
80  $arguments = [
81  \TYPO3\CMS\Core\FormProtection\BackendFormProtection::class,
82  $userMock,
83  $this->getMock(Registry::class)
84  ];
85  $this->assertSame(
86  call_user_func_array([FormProtectionFactory::class, 'get'], $arguments),
87  call_user_func_array([FormProtectionFactory::class, 'get'], $arguments)
88  );
89  }
90 
95  {
96  $this->assertTrue(FormProtectionFactory::get(\TYPO3\CMS\Core\FormProtection\InstallToolFormProtection::class) instanceof \TYPO3\CMS\Core\FormProtection\InstallToolFormProtection);
97  }
98 
103  {
104  $this->assertSame(FormProtectionFactory::get(\TYPO3\CMS\Core\FormProtection\InstallToolFormProtection::class), FormProtectionFactory::get(\TYPO3\CMS\Core\FormProtection\InstallToolFormProtection::class));
105  }
106 
111  {
112  $this->assertNotSame(FormProtectionFactory::get(\TYPO3\CMS\Core\FormProtection\InstallToolFormProtection::class), FormProtectionFactory::get(\TYPO3\CMS\Core\FormProtection\DisabledFormProtection::class));
113  }
114 
116  // Tests concerning set
118 
121  public function setSetsInstanceForType()
122  {
123  $instance = new \TYPO3\CMS\Core\Tests\Unit\FormProtection\Fixtures\FormProtectionTesting();
124  FormProtectionFactory::set(\TYPO3\CMS\Core\FormProtection\BackendFormProtection::class, $instance);
125  $this->assertSame($instance, FormProtectionFactory::get(\TYPO3\CMS\Core\FormProtection\BackendFormProtection::class));
126  }
127 
132  {
133  $instance = new \TYPO3\CMS\Core\Tests\Unit\FormProtection\Fixtures\FormProtectionTesting();
134  FormProtectionFactory::set(\TYPO3\CMS\Core\FormProtection\BackendFormProtection::class, $instance);
135  $this->assertNotSame($instance, FormProtectionFactory::get(\TYPO3\CMS\Core\FormProtection\InstallToolFormProtection::class));
136  }
137 
142  {
143  $flashMessageQueueMock = $this->getMock(
144  \TYPO3\CMS\Core\Messaging\FlashMessageQueue::class,
145  [],
146  [],
147  '',
148  false
149  );
150  $flashMessageQueueMock
151  ->expects($this->once())
152  ->method('enqueue')
153  ->with($this->isInstanceOf(\TYPO3\CMS\Core\Messaging\FlashMessage::class))
154  ->will($this->returnCallback([$this, 'enqueueAjaxFlashMessageCallback']));
155  $languageServiceMock = $this->getMock(\TYPO3\CMS\Lang\LanguageService::class, [], [], '', false);
156  $languageServiceMock->expects($this->once())->method('sL')->will($this->returnValue('foo'));
157 
158  FormProtectionFactory::getMessageClosure($languageServiceMock, $flashMessageQueueMock, true)->__invoke();
159  }
160 
164  public function enqueueAjaxFlashMessageCallback(\TYPO3\CMS\Core\Messaging\FlashMessage $flashMessage)
165  {
166  $this->assertFalse($flashMessage->isSessionMessage());
167  }
168 }
enqueueAjaxFlashMessageCallback(\TYPO3\CMS\Core\Messaging\FlashMessage $flashMessage)
static set($classNameOrType, AbstractFormProtection $instance)