5
5
*/
6
6
namespace Magento \Config \App \Config \Type ;
7
7
8
- use Magento \Config \Model \Config \Factory ;
9
- use Magento \Framework \Lock \Backend \Cache ;
10
- use Magento \Framework \App \Cache \Type \Config ;
11
- use Magento \Framework \Cache \FrontendInterface ;
12
- use Magento \Framework \Lock \LockManagerInterface ;
13
8
use Magento \Framework \ObjectManagerInterface ;
14
- use Magento \Store \Model \ScopeInterface ;
15
9
use Magento \TestFramework \Helper \Bootstrap ;
16
10
17
11
/**
18
12
* @magentoDataFixture Magento/Config/_files/config_data.php
19
13
* @magentoAppIsolation enabled
20
- * @magentoCache config enabled
21
14
*/
22
15
class SystemTest extends \PHPUnit \Framework \TestCase
23
16
{
@@ -34,145 +27,24 @@ class SystemTest extends \PHPUnit\Framework\TestCase
34
27
protected function setUp (): void
35
28
{
36
29
$ this ->objectManager = Bootstrap::getObjectManager ();
37
- $ this ->system = $ this ->createSystemConfig ( );
30
+ $ this ->system = $ this ->objectManager -> create (System::class );
38
31
}
39
32
40
- public function testGetValueForDefaultScope ()
33
+ public function testGetValueDefaultScope ()
41
34
{
42
35
$ this ->assertEquals (
43
36
'value1.db.default.test ' ,
44
37
$ this ->system ->get ('default/web/test/test_value_1 ' )
45
38
);
46
- }
47
39
48
- public function testGetValueForWebsiteScope ()
49
- {
50
40
$ this ->assertEquals (
51
41
'value1.db.website_base.test ' ,
52
42
$ this ->system ->get ('websites/base/web/test/test_value_1 ' )
53
43
);
54
- }
55
44
56
- public function testGetValueForStoreScope ()
57
- {
58
45
$ this ->assertEquals (
59
46
'value1.db.store_default.test ' ,
60
47
$ this ->system ->get ('stores/default/web/test/test_value_1 ' )
61
48
);
62
49
}
63
-
64
- public function testCachingDoesNotBreakValueRetrievalForStoreScope ()
65
- {
66
- // First uncached call to configuration
67
- $ this ->createSystemConfig ()->get ('stores/default/web/test/test_value_1 ' );
68
-
69
- // Second call after cache data is stored
70
- $ this ->assertEquals (
71
- 'value1.db.store_default.test ' ,
72
- $ this ->createSystemConfig ()->get ('stores/default/web/test/test_value_1 ' )
73
- );
74
- }
75
-
76
- public function testCachingDoesNotBreakValueRetrievalForWebsiteScope ()
77
- {
78
- // First uncached call to configuration
79
- $ this ->createSystemConfig ()->get ('websites/base/web/test/test_value_1 ' );
80
-
81
- // Second call after cache data is stored
82
- $ this ->assertEquals (
83
- 'value1.db.website_base.test ' ,
84
- $ this ->createSystemConfig ()->get ('websites/base/web/test/test_value_1 ' )
85
- );
86
- }
87
-
88
- public function testCachingDoesNotBreakValueRetrievalForDefaultScope ()
89
- {
90
- // First uncached call to configuration
91
- $ this ->createSystemConfig ()->get ('default/web/test/test_value_1 ' );
92
-
93
- // Second call after cache data is stored
94
- $ this ->assertEquals (
95
- 'value1.db.default.test ' ,
96
- $ this ->createSystemConfig ()->get ('default/web/test/test_value_1 ' )
97
- );
98
- }
99
-
100
- public function testClearingCachePrefixAndLockingItReturnsStaleCachedValue ()
101
- {
102
- // First uncached call to configuration
103
- $ this ->createSystemConfig ()->get ('default/web/test/test_value_1 ' );
104
-
105
- $ this ->clearConfigCachePrefix ();
106
- $ this ->accessLock ()->lock ('SYSTEM_CONFIG ' );
107
- // Second call after cache data is stored
108
- $ configValue = $ this ->createSystemConfig ()->get ('default/web/test/test_value_1 ' );
109
- $ this ->accessLock ()->unlock ('SYSTEM_CONFIG ' );
110
-
111
- $ this ->assertEquals (
112
- 'value1.db.default.test ' ,
113
- $ configValue
114
- );
115
- }
116
-
117
- public function testClearingConfigurationCacheAndLockingFallsBackToStaleCache ()
118
- {
119
- // First uncached call to configuration
120
- $ this ->createSystemConfig ()->get ('stores/default/web/test/test_value_1 ' );
121
-
122
- $ this ->accessCacheFrontend ()->clean (\Zend_Cache::CLEANING_MODE_MATCHING_TAG , [System::CACHE_TAG ]);
123
-
124
- $ this ->accessLock ()->lock ('SYSTEM_CONFIG ' );
125
- // Second call after cache data is stored
126
- $ configValue = $ this ->createSystemConfig ()->get ('stores/default/web/test/test_value_1 ' );
127
- $ this ->accessLock ()->unlock ('SYSTEM_CONFIG ' );
128
-
129
- $ this ->assertEquals (
130
- 'value1.db.store_default.test ' ,
131
- $ configValue
132
- );
133
- }
134
-
135
- public function testChangingConfigurationValueRefreshesACache ()
136
- {
137
- $ systemConfig = $ this ->objectManager ->get (System::class);
138
-
139
- // First uncached call to configuration
140
- $ systemConfig ->get ('stores/default/web/test/test_value_1 ' );
141
-
142
- /** @var Factory $configFactory */
143
- $ configFactory = $ this ->objectManager ->create (Factory::class);
144
- $ config = $ configFactory ->create ();
145
- $ config ->setScope (ScopeInterface::SCOPE_STORES );
146
- $ config ->setStore ('default ' );
147
-
148
- $ config ->setDataByPath ('web/test/test_value_1 ' , 'new_uncached_value ' );
149
- $ config ->save ();
150
-
151
- $ this ->assertEquals (
152
- 'new_uncached_value ' ,
153
- $ systemConfig ->get ('stores/default/web/test/test_value_1 ' )
154
- );
155
- }
156
-
157
- private function clearConfigCachePrefix ()
158
- {
159
- $ cache = $ this ->accessCacheFrontend ();
160
-
161
- $ cache ->remove (System::STALE_CACHE_KEY_FOR_PREFIX );
162
- }
163
-
164
- private function accessCacheFrontend (): FrontendInterface
165
- {
166
- return $ this ->objectManager ->get (Config::class);
167
- }
168
-
169
- private function createSystemConfig (): System
170
- {
171
- return $ this ->objectManager ->create (System::class);
172
- }
173
-
174
- private function accessLock (): LockManagerInterface
175
- {
176
- return $ this ->objectManager ->get (Cache::class);
177
- }
178
50
}
0 commit comments