‪TYPO3CMS  9.5
BackendUserConfigurationTest.php
Go to the documentation of this file.
1 <?php
2 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 
20 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
21 
25 class ‪BackendUserConfigurationTest extends UnitTestCase
26 {
31 
35  protected ‪$backendUser;
36 
40  protected function ‪setUp()
41  {
43  $this->backendUser = $this->prophesize(BackendUserAuthentication::class);
44  $this->backendUserConfiguration = new ‪BackendUserConfiguration($this->backendUser->reveal());
45  }
46 
50  public function ‪getsConfiguration()
51  {
52  $this->backendUser->reveal()->uc = [
53  'key' => 'A',
54  'nested' => [
55  'key' => 'B',
56  ],
57  ];
58 
59  $this->assertEquals('A', $this->backendUserConfiguration->get('key'));
60  $this->assertEquals('B', $this->backendUserConfiguration->get('nested.key'));
61  }
62 
66  public function ‪getsAllConfiguration()
67  {
68  $configuration = [
69  'foo' => 'A',
70  'bar' => 'B',
71  ];
72  $this->backendUser->reveal()->uc = $configuration;
73 
74  $this->assertEquals($configuration, $this->backendUserConfiguration->getAll());
75  }
76 
80  public function ‪setsConfiguration()
81  {
82  $this->backendUser->reveal()->uc = [
83  'foo' => 'A',
84  ];
85 
86  $this->backendUserConfiguration->set('foo', 'X');
87  $this->backendUserConfiguration->set('bar', 'Y');
88  $this->backendUserConfiguration->set('nested.bar', 'Z');
89 
90  $expected = [
91  'foo' => 'X',
92  'bar' => 'Y',
93  'nested' => [
94  'bar' => 'Z',
95  ],
96  ];
97 
98  $this->backendUser->writeUC($expected)->shouldHaveBeenCalled();
99  }
100 
104  public function ‪addsToListConfigurationOption()
105  {
106  $this->backendUser->reveal()->uc = [
107  'foo' => 'A',
108  'nested' => [
109  'foo' => '',
110  ],
111  ];
112 
113  $this->backendUserConfiguration->addToList('foo', 'X');
114  $this->backendUserConfiguration->addToList('nested.foo', 'X');
115  $this->backendUserConfiguration->addToList('nested.foo', 'Z');
116  $this->backendUserConfiguration->addToList('nested.foo', 'Z');
117 
118  $expected = [
119  'foo' => 'A,X',
120  'nested' => [
121  'foo' => '',
122  ],
123  ];
124  $this->backendUser->writeUC($expected)->shouldHaveBeenCalled();
125  $expected = [
126  'foo' => 'A,X',
127  'nested' => [
128  'foo' => ',X',
129  ],
130  ];
131  $this->backendUser->writeUC($expected)->shouldHaveBeenCalled();
132  $expected = [
133  'foo' => 'A,X',
134  'nested' => [
135  'foo' => ',X,Z',
136  ],
137  ];
138  $this->backendUser->writeUC($expected)->shouldHaveBeenCalled();
139  }
140 
144  public function ‪removesFromListConfigurationOption()
145  {
146  $this->backendUser->reveal()->uc = [
147  'foo' => 'A,B',
148  'nested' => [
149  'foo' => 'A,B,C',
150  ],
151  ];
152 
153  $this->backendUserConfiguration->removeFromList('foo', 'B');
154  $this->backendUserConfiguration->removeFromList('nested.foo', 'B');
155  $this->backendUserConfiguration->removeFromList('nested.foo', 'B');
156 
157  $expected = [
158  'foo' => 'A',
159  'nested' => [
160  'foo' => 'A,B,C',
161  ],
162  ];
163  $this->backendUser->writeUC($expected)->shouldHaveBeenCalled();
164  $expected = [
165  'foo' => 'A',
166  'nested' => [
167  'foo' => 'A,C',
168  ],
169  ];
170  $this->backendUser->writeUC($expected)->shouldHaveBeenCalled();
171  }
172 
176  public function ‪clearsConfiguration()
177  {
178  $this->backendUserConfiguration->clear();
179 
180  $this->backendUser->resetUC()->shouldHaveBeenCalled();
181  }
182 
186  public function ‪unsetsConfigurationOption()
187  {
188  $this->backendUser->reveal()->uc = [
189  'foo' => 'A',
190  'bar' => 'B',
191  ];
192 
193  $this->backendUserConfiguration->unsetOption('foo');
194  $this->backendUserConfiguration->unsetOption('foo');
195 
196  $expected = [
197  'bar' => 'B',
198  ];
199  $this->backendUser->writeUC($expected)->shouldHaveBeenCalled();
200  }
201 }
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\BackendUserConfigurationTest\getsConfiguration
‪getsConfiguration()
Definition: BackendUserConfigurationTest.php:48
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\BackendUserConfigurationTest\getsAllConfiguration
‪getsAllConfiguration()
Definition: BackendUserConfigurationTest.php:64
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\BackendUserConfigurationTest\$backendUser
‪BackendUserAuthentication Prophecy Prophecy ObjectProphecy $backendUser
Definition: BackendUserConfigurationTest.php:33
‪TYPO3\CMS\Backend\Tests\Unit\Configuration
Definition: BackendUserConfigurationTest.php:3
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\BackendUserConfigurationTest\removesFromListConfigurationOption
‪removesFromListConfigurationOption()
Definition: BackendUserConfigurationTest.php:142
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\BackendUserConfigurationTest\setUp
‪setUp()
Definition: BackendUserConfigurationTest.php:38
‪TYPO3\CMS\Backend\Configuration\BackendUserConfiguration
Definition: BackendUserConfiguration.php:28
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:45
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\BackendUserConfigurationTest\setsConfiguration
‪setsConfiguration()
Definition: BackendUserConfigurationTest.php:78
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\BackendUserConfigurationTest\$backendUserConfiguration
‪BackendUserConfiguration $backendUserConfiguration
Definition: BackendUserConfigurationTest.php:29
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\BackendUserConfigurationTest
Definition: BackendUserConfigurationTest.php:26
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\BackendUserConfigurationTest\unsetsConfigurationOption
‪unsetsConfigurationOption()
Definition: BackendUserConfigurationTest.php:184
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\BackendUserConfigurationTest\addsToListConfigurationOption
‪addsToListConfigurationOption()
Definition: BackendUserConfigurationTest.php:102
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\BackendUserConfigurationTest\clearsConfiguration
‪clearsConfiguration()
Definition: BackendUserConfigurationTest.php:174