forked from AmpersandHQ/magento-ce-ee-config-corruption-bug
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfigurationTest.php
121 lines (105 loc) · 3.48 KB
/
ConfigurationTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
class ConfigurationTest extends PHPUnit_Framework_TestCase
{
/**
*
* @author Luke Rodgers <[email protected]>
*/
public function setUp()
{
/**
* Enable config cache
*/
$caches = array();
foreach (Mage::app()->useCache() as $type => $status) {
if ($type == 'config') {
$status = 1;
}
$caches[$type] = $status;
}
Mage::app()->saveUseCache($caches);
/**
* Clear all cache entries
*/
Mage::app()->getCacheInstance()->clean();
Mage::app()->getCacheInstance()->flush();
Mage::app()->getCache()->clean();
Mage::reset();
}
/**
* @test
* @author Luke Rodgers <[email protected]>
*/
public function reinitWithAlternativeConfigModel()
{
/**
* Initialise Mage and warm the cache
*/
Mage::app();
Mage::reset();
/**
* Get a copy of the admin configuration from the warmed up cache
*/
$before = Mage::app()->getCacheInstance()->load('config_global_stores');
$before = new Varien_Simplexml_Element($before);
$before = $before->descend('admin')->asXML();
/**
* Initialise Mage with our custom config module which alternates between hitting a fake cache lock
*/
Mage::reset();
Mage::app(
Mage_Core_Model_App::ADMIN_STORE_ID,
'store',
array('config_model' => 'Convenient_Core_Model_Config')
);
/**
* Recall init, which calls Mage_Core_Model_Config:;init,
* useCache is still true, but we have the hit the fake cache lock on config_global.
*/
Mage::app()->init(Mage_Core_Model_App::ADMIN_STORE_ID, 'store');
/**
* Get a copy of the admin configuration from the corrupted cache
*/
Mage::reset();
$after = Mage::app()->getCacheInstance()->load('config_global_stores');
$after = new Varien_Simplexml_Element($after);
$after = $after->descend('admin')->asXML();
$this->assertEquals($before, $after);
}
/**
* @test
* @author Luke Rodgers <[email protected]>
*/
public function reinitMissingCacheEntry()
{
/**
* Initialise Mage and warm the cache
*/
Mage::app();
Mage::reset();
/**
* Get a copy of the admin configuration from the warmed up cache
*/
$before = Mage::app()->getCacheInstance()->load('config_global_stores');
$before = new Varien_Simplexml_Element($before);
$before = $before->descend('admin')->asXML();
/**
* Initialise Mage and remove config_global from the cache, to simulate hitting a fake cache lock
*/
Mage::reset();
Mage::app()->getCacheInstance()->remove('config_global');
/**
* Recall init, which calls Mage_Core_Model_Config:;init,
* useCache is still true, but we have the hit the fake cache lock on config_global.
*/
Mage::app()->init(Mage_Core_Model_App::ADMIN_STORE_ID, 'store');
/**
* Get a copy of the admin configuration from the corrupted cache
*/
Mage::reset();
$after = Mage::app()->getCacheInstance()->load('config_global_stores');
$after = new Varien_Simplexml_Element($after);
$after = $after->descend('admin')->asXML();
$this->assertEquals($before, $after);
}
}