‪TYPO3CMS  11.5
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 
20 use Prophecy\PhpUnit\ProphecyTrait;
21 use Prophecy\Prophecy\ObjectProphecy;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 class ‪BackendUserConfigurationTest extends UnitTestCase
30 {
31  use ProphecyTrait;
32 
34 
36  protected ObjectProphecy ‪$backendUserProphecy;
37 
39 
43  protected function ‪setUp(): void
44  {
45  parent::setUp();
46  $this->backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
47  $this->backendUser = $this->backendUserProphecy->reveal();
48  $this->backendUserConfiguration = new ‪BackendUserConfiguration($this->backendUser);
49  }
50 
54  public function ‪getsConfiguration(): void
55  {
56  $this->backendUser->uc = [
57  'key' => 'A',
58  'nested' => [
59  'key' => 'B',
60  ],
61  ];
62 
63  self::assertEquals('A', $this->backendUserConfiguration->get('key'));
64  self::assertEquals('B', $this->backendUserConfiguration->get('nested.key'));
65  }
66 
70  public function ‪getsAllConfiguration(): void
71  {
72  $configuration = [
73  'foo' => 'A',
74  'bar' => 'B',
75  ];
76  $this->backendUser->uc = $configuration;
77 
78  self::assertEquals($configuration, $this->backendUserConfiguration->getAll());
79  }
80 
84  public function ‪setsConfiguration(): void
85  {
86  $this->backendUser->uc = [
87  'foo' => 'A',
88  ];
89 
90  $this->backendUserConfiguration->set('foo', 'X');
91  $this->backendUserConfiguration->set('bar', 'Y');
92  $this->backendUserConfiguration->set('nested.bar', 'Z');
93 
94  $expected = [
95  'foo' => 'X',
96  'bar' => 'Y',
97  'nested' => [
98  'bar' => 'Z',
99  ],
100  ];
101 
102  $this->backendUserProphecy->writeUC()->shouldHaveBeenCalled();
103  self::assertEquals($expected, $this->backendUser->uc);
104  }
105 
109  public function ‪addsToListConfigurationOption(): void
110  {
111  $this->backendUser->uc = [
112  'foo' => 'A',
113  'nested' => [
114  'foo' => '',
115  ],
116  ];
117 
118  $this->backendUserConfiguration->addToList('foo', 'X');
119  $this->backendUserConfiguration->addToList('nested.foo', 'X');
120  $this->backendUserConfiguration->addToList('nested.foo', 'Z');
121  $this->backendUserConfiguration->addToList('nested.foo', 'Z');
122  $expected = [
123  'foo' => 'A,X',
124  'nested' => [
125  'foo' => ',X,Z',
126  ],
127  ];
128  $this->backendUserProphecy->writeUC()->shouldHaveBeenCalled();
129  self::assertEquals($expected, $this->backendUser->uc);
130  }
131 
135  public function ‪removesFromListConfigurationOption(): void
136  {
137  $this->backendUser->uc = [
138  'foo' => 'A,B',
139  'nested' => [
140  'foo' => 'A,B,C',
141  ],
142  ];
143 
144  $this->backendUserConfiguration->removeFromList('foo', 'B');
145  $this->backendUserConfiguration->removeFromList('nested.foo', 'B');
146 
147  $expected = [
148  'foo' => 'A',
149  'nested' => [
150  'foo' => 'A,C',
151  ],
152  ];
153  $this->backendUserProphecy->writeUC()->shouldHaveBeenCalled();
154  self::assertEquals($expected, $this->backendUser->uc);
155  }
156 
160  public function ‪clearsConfiguration(): void
161  {
162  $this->backendUserConfiguration->clear();
163  $this->backendUserProphecy->resetUC()->shouldHaveBeenCalled();
164  }
165 
169  public function ‪unsetsConfigurationOption(): void
170  {
171  $this->backendUser->uc = [
172  'foo' => 'A',
173  'bar' => 'B',
174  ];
175 
176  $this->backendUserConfiguration->unsetOption('foo');
177  $this->backendUserConfiguration->unsetOption('foo');
178 
179  $expected = [
180  'bar' => 'B',
181  ];
182  $this->backendUserProphecy->writeUC()->shouldHaveBeenCalled();
183  self::assertEquals($expected, $this->backendUser->uc);
184  }
185 }
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\BackendUserConfigurationTest\getsConfiguration
‪getsConfiguration()
Definition: BackendUserConfigurationTest.php:53
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\BackendUserConfigurationTest\getsAllConfiguration
‪getsAllConfiguration()
Definition: BackendUserConfigurationTest.php:69
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\BackendUserConfigurationTest\$backendUserProphecy
‪ObjectProphecy $backendUserProphecy
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:134
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\BackendUserConfigurationTest\$backendUser
‪BackendUserAuthentication $backendUser
Definition: BackendUserConfigurationTest.php:37
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\BackendUserConfigurationTest\setUp
‪setUp()
Definition: BackendUserConfigurationTest.php:42
‪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:83
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\BackendUserConfigurationTest\$backendUserConfiguration
‪BackendUserConfiguration $backendUserConfiguration
Definition: BackendUserConfigurationTest.php:32
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\BackendUserConfigurationTest
Definition: BackendUserConfigurationTest.php:30
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\BackendUserConfigurationTest\unsetsConfigurationOption
‪unsetsConfigurationOption()
Definition: BackendUserConfigurationTest.php:168
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\BackendUserConfigurationTest\addsToListConfigurationOption
‪addsToListConfigurationOption()
Definition: BackendUserConfigurationTest.php:108
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\BackendUserConfigurationTest\clearsConfiguration
‪clearsConfiguration()
Definition: BackendUserConfigurationTest.php:159