TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
Functional/RegistryTest.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Functional;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
20 
25 {
26 
31  {
32  $this->assertNull((new Registry())->get('myExtension', 'myKey'));
33  }
34 
39  {
40  $this->assertSame('myDefault', (new Registry())->get('myExtension', 'myKey', 'myDefault'));
41  }
42 
46  public function getReturnsEntryFromDatabase()
47  {
48  (new ConnectionPool())->getConnectionForTable('sys_registry')
49  ->insert(
50  'sys_registry',
51  [
52  'entry_namespace' => 'myExtension',
53  'entry_key' => 'myKey',
54  'entry_value' => serialize('myValue'),
55  ]
56  );
57  $this->assertSame('myValue', (new Registry())->get('myExtension', 'myKey'));
58  }
59 
63  public function setInsertsEntryInDatabase()
64  {
65  (new Registry())->set('myExtension', 'myKey', 'myValue');
66  $valueInDatabase = (new ConnectionPool())->getConnectionForTable('sys_registry')
67  ->select(
68  ['entry_value'],
69  'sys_registry',
70  ['entry_namespace' => 'myExtension', 'entry_key' => 'myKey']
71  )
72  ->fetch();
73  $this->assertSame('myValue', unserialize($valueInDatabase['entry_value']));
74  }
75 
80  {
81  (new ConnectionPool())->getConnectionForTable('sys_registry')
82  ->insert(
83  'sys_registry',
84  [
85  'entry_namespace' => 'myExtension',
86  'entry_key' => 'myKey',
87  'entry_value' => serialize('myValue'),
88  ]
89  );
90  (new Registry())->set('myExtension', 'myKey', 'myNewValue');
91  $valueInDatabase = (new ConnectionPool())->getConnectionForTable('sys_registry')
92  ->select(
93  ['entry_value'],
94  'sys_registry',
95  ['entry_namespace' => 'myExtension', 'entry_key' => 'myKey']
96  )
97  ->fetch();
98  $this->assertSame('myNewValue', unserialize($valueInDatabase['entry_value']));
99  }
100 
105  {
106  $connection = (new ConnectionPool())->getConnectionForTable('sys_registry');
107  $connection->bulkInsert(
108  'sys_registry',
109  [
110  ['ns1', 'k1', serialize('v1')],
111  ['ns1', 'k2', serialize('v2')],
112  ['ns2', 'k1', serialize('v1')],
113  ],
114  ['entry_namespace', 'entry_key', 'entry_value']
115  );
116 
117  (new Registry())->remove('ns1', 'k1');
118 
119  $this->assertSame(0, $connection->count('*', 'sys_registry', ['entry_namespace' => 'ns1', 'entry_key' => 'k1']));
120  $this->assertSame(1, $connection->count('*', 'sys_registry', ['entry_namespace' => 'ns1', 'entry_key' => 'k2']));
121  $this->assertSame(1, $connection->count('*', 'sys_registry', ['entry_namespace' => 'ns2', 'entry_key' => 'k1']));
122  }
123 
128  {
129  $connection = (new ConnectionPool())->getConnectionForTable('sys_registry');
130  $connection->bulkInsert(
131  'sys_registry',
132  [
133  ['ns1', 'k1', serialize('v1')],
134  ['ns1', 'k2', serialize('v2')],
135  ['ns2', 'k1', serialize('v1')],
136  ],
137  ['entry_namespace', 'entry_key', 'entry_value']
138  );
139 
140  (new Registry())->removeAllByNamespace('ns1');
141 
142  $this->assertSame(0, $connection->count('*', 'sys_registry', ['entry_namespace' => 'ns1', 'entry_key' => 'k1']));
143  $this->assertSame(0, $connection->count('*', 'sys_registry', ['entry_namespace' => 'ns1', 'entry_key' => 'k2']));
144  $this->assertSame(1, $connection->count('*', 'sys_registry', ['entry_namespace' => 'ns2', 'entry_key' => 'k1']));
145  }
146 
150  public function canGetSetEntry()
151  {
152  $registry = new Registry();
153  $registry->set('ns1', 'key1', 'value1');
154  $this->assertSame('value1', $registry->get('ns1', 'key1'));
155  }
156 
161  {
162  $registry = new Registry();
163  $registry->set('ns1', 'key1', 'value1');
164  $registry->set('ns1', 'key1', 'value2');
165  $this->assertSame('value2', $registry->get('ns1', 'key1'));
166  }
167 
171  public function canNotGetRemovedEntry()
172  {
173  $registry = new Registry();
174  $registry->set('ns1', 'key1', 'value1');
175  $registry->remove('ns1', 'key1');
176  $this->assertNull($registry->get('ns1', 'key1'));
177  }
178 
183  {
184  $registry = new Registry();
185  $registry->set('ns1', 'key1', 'value1');
186  $registry->removeAllByNamespace('ns1');
187  $this->assertNull($registry->get('ns1', 'key1'));
188  }
189 }