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