‪TYPO3CMS  10.4
RegistryTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
21 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
22 
26 class ‪RegistryTest extends FunctionalTestCase
27 {
28 
33  {
34  self::assertNull((new ‪Registry())->get('myExtension', 'myKey'));
35  }
36 
41  {
42  self::assertSame('myDefault', (new ‪Registry())->get('myExtension', 'myKey', 'myDefault'));
43  }
44 
49  {
50  (new ‪ConnectionPool())->getConnectionForTable('sys_registry')
51  ->insert(
52  'sys_registry',
53  [
54  'entry_namespace' => 'myExtension',
55  'entry_key' => 'myKey',
56  'entry_value' => serialize('myValue'),
57  ],
58  [
59  'entry_value' => ‪Connection::PARAM_LOB,
60  ]
61  );
62  self::assertSame('myValue', (new ‪Registry())->get('myExtension', 'myKey'));
63  }
64 
68  public function ‪setInsertsEntryInDatabase()
69  {
70  (new ‪Registry())->set('myExtension', 'myKey', 'myValue');
71  $valueInDatabase = (new ‪ConnectionPool())->getConnectionForTable('sys_registry')
72  ->select(
73  ['entry_value'],
74  'sys_registry',
75  ['entry_namespace' => 'myExtension', 'entry_key' => 'myKey']
76  )
77  ->fetch();
78  self::assertSame('myValue', unserialize($valueInDatabase['entry_value']));
79  }
80 
85  {
86  (new ‪ConnectionPool())->getConnectionForTable('sys_registry')
87  ->insert(
88  'sys_registry',
89  [
90  'entry_namespace' => 'myExtension',
91  'entry_key' => 'myKey',
92  'entry_value' => serialize('myValue'),
93  ],
94  [
95  'entry_value' => ‪Connection::PARAM_LOB,
96  ]
97  );
98  (new ‪Registry())->set('myExtension', 'myKey', 'myNewValue');
99  $valueInDatabase = (new ‪ConnectionPool())->getConnectionForTable('sys_registry')
100  ->select(
101  ['entry_value'],
102  'sys_registry',
103  ['entry_namespace' => 'myExtension', 'entry_key' => 'myKey']
104  )
105  ->fetch();
106  self::assertSame('myNewValue', unserialize($valueInDatabase['entry_value']));
107  }
108 
113  {
114  $connection = (new ‪ConnectionPool())->getConnectionForTable('sys_registry');
115  $connection->bulkInsert(
116  'sys_registry',
117  [
118  ['ns1', 'k1', serialize('v1')],
119  ['ns1', 'k2', serialize('v2')],
120  ['ns2', 'k1', serialize('v1')],
121  ],
122  ['entry_namespace', 'entry_key', 'entry_value'],
123  [
124  'entry_value' => ‪Connection::PARAM_LOB,
125  ]
126  );
127 
128  (new ‪Registry())->remove('ns1', 'k1');
129 
130  self::assertSame(0, $connection->count('*', 'sys_registry', ['entry_namespace' => 'ns1', 'entry_key' => 'k1']));
131  self::assertSame(1, $connection->count('*', 'sys_registry', ['entry_namespace' => 'ns1', 'entry_key' => 'k2']));
132  self::assertSame(1, $connection->count('*', 'sys_registry', ['entry_namespace' => 'ns2', 'entry_key' => 'k1']));
133  }
134 
139  {
140  $connection = (new ‪ConnectionPool())->getConnectionForTable('sys_registry');
141  $connection->bulkInsert(
142  'sys_registry',
143  [
144  ['ns1', 'k1', serialize('v1')],
145  ['ns1', 'k2', serialize('v2')],
146  ['ns2', 'k1', serialize('v1')],
147  ],
148  ['entry_namespace', 'entry_key', 'entry_value'],
149  [
150  'entry_value' => ‪Connection::PARAM_LOB,
151  ]
152  );
153 
154  (new ‪Registry())->removeAllByNamespace('ns1');
155 
156  self::assertSame(0, $connection->count('*', 'sys_registry', ['entry_namespace' => 'ns1', 'entry_key' => 'k1']));
157  self::assertSame(0, $connection->count('*', 'sys_registry', ['entry_namespace' => 'ns1', 'entry_key' => 'k2']));
158  self::assertSame(1, $connection->count('*', 'sys_registry', ['entry_namespace' => 'ns2', 'entry_key' => 'k1']));
159  }
160 
164  public function ‪canGetSetEntry()
165  {
166  $registry = new ‪Registry();
167  $registry->set('ns1', 'key1', 'value1');
168  self::assertSame('value1', $registry->get('ns1', 'key1'));
169  }
170 
175  {
176  $registry = new ‪Registry();
177  $registry->set('ns1', 'key1', 'value1');
178  $registry->set('ns1', 'key1', 'value2');
179  self::assertSame('value2', $registry->get('ns1', 'key1'));
180  }
181 
185  public function ‪canNotGetRemovedEntry()
186  {
187  $registry = new ‪Registry();
188  $registry->set('ns1', 'key1', 'value1');
189  $registry->remove('ns1', 'key1');
190  self::assertNull($registry->get('ns1', 'key1'));
191  }
192 
197  {
198  $registry = new ‪Registry();
199  $registry->set('ns1', 'key1', 'value1');
200  $registry->removeAllByNamespace('ns1');
201  self::assertNull($registry->get('ns1', 'key1'));
202  }
203 }
‪TYPO3\CMS\Core\Tests\Functional\RegistryTest\setInsertsEntryInDatabase
‪setInsertsEntryInDatabase()
Definition: RegistryTest.php:68
‪TYPO3\CMS\Core\Tests\Functional\RegistryTest\canNotGetRemovedEntry
‪canNotGetRemovedEntry()
Definition: RegistryTest.php:185
‪TYPO3\CMS\Core\Tests\Functional\RegistryTest\getReturnsNewValueIfValueHasBeenSetMultipleTimes
‪getReturnsNewValueIfValueHasBeenSetMultipleTimes()
Definition: RegistryTest.php:174
‪TYPO3\CMS\Core\Registry
Definition: Registry.php:33
‪TYPO3\CMS\Core\Tests\Functional\RegistryTest\getReturnsEntryFromDatabase
‪getReturnsEntryFromDatabase()
Definition: RegistryTest.php:48
‪TYPO3\CMS\Core\Tests\Functional\RegistryTest
Definition: RegistryTest.php:27
‪TYPO3\CMS\Core\Tests\Functional\RegistryTest\canGetSetEntry
‪canGetSetEntry()
Definition: RegistryTest.php:164
‪TYPO3\CMS\Core\Tests\Functional
‪TYPO3\CMS\Core\Tests\Functional\RegistryTest\removeAllByNamespaceDeletesEntryInDatabaseAndLeavesOthers
‪removeAllByNamespaceDeletesEntryInDatabaseAndLeavesOthers()
Definition: RegistryTest.php:138
‪TYPO3\CMS\Core\Tests\Functional\RegistryTest\getReturnsDefaultValueIfEntryIsNotInDatabase
‪getReturnsDefaultValueIfEntryIsNotInDatabase()
Definition: RegistryTest.php:40
‪TYPO3\CMS\Core\Tests\Functional\RegistryTest\canNotGetRemovedAllByNamespaceEntry
‪canNotGetRemovedAllByNamespaceEntry()
Definition: RegistryTest.php:196
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:36
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Tests\Functional\RegistryTest\removeDeletesEntryInDatabaseButLeavesOthers
‪removeDeletesEntryInDatabaseButLeavesOthers()
Definition: RegistryTest.php:112
‪TYPO3\CMS\Core\Tests\Functional\RegistryTest\getReturnsNullIfEntryIsNotInDatabase
‪getReturnsNullIfEntryIsNotInDatabase()
Definition: RegistryTest.php:32
‪TYPO3\CMS\Core\Database\Connection\PARAM_LOB
‪const PARAM_LOB
Definition: Connection.php:57
‪TYPO3\CMS\Core\Tests\Functional\RegistryTest\setOverridesExistingEntryInDatabase
‪setOverridesExistingEntryInDatabase()
Definition: RegistryTest.php:84