‪TYPO3CMS  ‪main
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 PHPUnit\Framework\Attributes\Test;
21 use PHPUnit\Framework\MockObject\MockObject;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
26 final class ‪BackendUserConfigurationTest extends UnitTestCase
27 {
30 
31  protected function ‪setUp(): void
32  {
33  parent::setUp();
34  $this->backendUserMock = $this->createMock(BackendUserAuthentication::class);
35  $this->backendUserConfiguration = new ‪BackendUserConfiguration($this->backendUserMock);
36  }
37 
38  #[Test]
39  public function ‪getsConfiguration(): void
40  {
41  $this->backendUserMock->uc = [
42  'key' => 'A',
43  'nested' => [
44  'key' => 'B',
45  ],
46  ];
47 
48  self::assertEquals('A', $this->backendUserConfiguration->get('key'));
49  self::assertEquals('B', $this->backendUserConfiguration->get('nested.key'));
50  }
51 
52  #[Test]
53  public function ‪getsAllConfiguration(): void
54  {
55  $configuration = [
56  'foo' => 'A',
57  'bar' => 'B',
58  ];
59  $this->backendUserMock->uc = $configuration;
60 
61  self::assertEquals($configuration, $this->backendUserConfiguration->getAll());
62  }
63 
64  #[Test]
65  public function ‪setsConfiguration(): void
66  {
67  $this->backendUserMock->uc = [
68  'foo' => 'A',
69  ];
70 
71  $this->backendUserMock->expects(self::atLeastOnce())->method('writeUC');
72 
73  $this->backendUserConfiguration->set('foo', 'X');
74  $this->backendUserConfiguration->set('bar', 'Y');
75  $this->backendUserConfiguration->set('nested.bar', 'Z');
76 
77  $expected = [
78  'foo' => 'X',
79  'bar' => 'Y',
80  'nested' => [
81  'bar' => 'Z',
82  ],
83  ];
84  self::assertEquals($expected, $this->backendUserMock->uc);
85  }
86 
87  #[Test]
88  public function ‪addsToListConfigurationOption(): void
89  {
90  $this->backendUserMock->uc = [
91  'foo' => 'A',
92  'nested' => [
93  'foo' => '',
94  ],
95  ];
96 
97  $this->backendUserMock->expects(self::atLeastOnce())->method('writeUC');
98 
99  $this->backendUserConfiguration->addToList('foo', 'X');
100  $this->backendUserConfiguration->addToList('nested.foo', 'X');
101  $this->backendUserConfiguration->addToList('nested.foo', 'Z');
102  $this->backendUserConfiguration->addToList('nested.foo', 'Z');
103  $expected = [
104  'foo' => 'A,X',
105  'nested' => [
106  'foo' => ',X,Z',
107  ],
108  ];
109  self::assertEquals($expected, $this->backendUserMock->uc);
110  }
111 
112  #[Test]
114  {
115  $this->backendUserMock->uc = [
116  'foo' => 'A,B',
117  'nested' => [
118  'foo' => 'A,B,C',
119  ],
120  ];
121 
122  $this->backendUserMock->expects(self::atLeastOnce())->method('writeUC');
123 
124  $this->backendUserConfiguration->removeFromList('foo', 'B');
125  $this->backendUserConfiguration->removeFromList('nested.foo', 'B');
126 
127  $expected = [
128  'foo' => 'A',
129  'nested' => [
130  'foo' => 'A,C',
131  ],
132  ];
133  self::assertEquals($expected, $this->backendUserMock->uc);
134  }
135 
136  #[Test]
137  public function ‪clearsConfiguration(): void
138  {
139  $this->backendUserMock->expects(self::atLeastOnce())->method('resetUC');
140  $this->backendUserConfiguration->clear();
141  }
142 
143  #[Test]
144  public function ‪unsetsConfigurationOption(): void
145  {
146  $this->backendUserMock->uc = [
147  'foo' => 'A',
148  'bar' => 'B',
149  ];
150 
151  $this->backendUserMock->expects(self::atLeastOnce())->method('writeUC');
152 
153  $this->backendUserConfiguration->unsetOption('foo');
154  $this->backendUserConfiguration->unsetOption('foo');
155 
156  $expected = [
157  'bar' => 'B',
158  ];
159  self::assertEquals($expected, $this->backendUserMock->uc);
160  }
161 }
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\BackendUserConfigurationTest\$backendUserMock
‪BackendUserAuthentication &MockObject $backendUserMock
Definition: BackendUserConfigurationTest.php:29
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\BackendUserConfigurationTest\getsConfiguration
‪getsConfiguration()
Definition: BackendUserConfigurationTest.php:39
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\BackendUserConfigurationTest\getsAllConfiguration
‪getsAllConfiguration()
Definition: BackendUserConfigurationTest.php:53
‪TYPO3\CMS\Backend\Tests\Unit\Configuration
Definition: BackendUserConfigurationTest.php:18
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\BackendUserConfigurationTest\removesFromListConfigurationOption
‪removesFromListConfigurationOption()
Definition: BackendUserConfigurationTest.php:113
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\BackendUserConfigurationTest\setUp
‪setUp()
Definition: BackendUserConfigurationTest.php:31
‪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:65
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\BackendUserConfigurationTest\$backendUserConfiguration
‪BackendUserConfiguration $backendUserConfiguration
Definition: BackendUserConfigurationTest.php:28
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\BackendUserConfigurationTest
Definition: BackendUserConfigurationTest.php:27
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\BackendUserConfigurationTest\unsetsConfigurationOption
‪unsetsConfigurationOption()
Definition: BackendUserConfigurationTest.php:144
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\BackendUserConfigurationTest\addsToListConfigurationOption
‪addsToListConfigurationOption()
Definition: BackendUserConfigurationTest.php:88
‪TYPO3\CMS\Backend\Tests\Unit\Configuration\BackendUserConfigurationTest\clearsConfiguration
‪clearsConfiguration()
Definition: BackendUserConfigurationTest.php:137