|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Mockery as m; |
|
4
|
|
|
use JsLocalization\Facades\ConfigCachingService; |
|
5
|
|
|
|
|
6
|
|
|
class ConfigCachingServiceTest extends TestCase { |
|
7
|
|
|
|
|
8
|
|
|
public function setUp() |
|
9
|
|
|
{ |
|
10
|
|
|
parent::setUp(); |
|
11
|
|
|
|
|
12
|
|
|
Cache::forget(JsLocalization\Caching\ConfigCachingService::CACHE_KEY); |
|
13
|
|
|
Cache::forget(JsLocalization\Caching\ConfigCachingService::CACHE_TIMESTAMP_KEY); |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
public function tearDown() |
|
17
|
|
|
{ |
|
18
|
|
|
m::close(); |
|
19
|
|
|
|
|
20
|
|
|
parent::tearDown(); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function testIsDisabled() |
|
24
|
|
|
{ |
|
25
|
|
|
Config::set('js-localization.disable_config_cache', false); |
|
26
|
|
|
$this->assertFalse(ConfigCachingService::isDisabled()); |
|
27
|
|
|
|
|
28
|
|
|
Config::set('js-localization.disable_config_cache', true); |
|
29
|
|
|
$this->assertTrue(ConfigCachingService::isDisabled()); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testGetConfigJson() |
|
33
|
|
|
{ |
|
34
|
|
|
$expectedJson = json_encode($this->testConfigExportFlat); |
|
35
|
|
|
$this->assertEquals($expectedJson, ConfigCachingService::getConfigJson()); |
|
36
|
|
|
|
|
37
|
|
|
// Test that getConfigJson() returns the old value after Config::set() |
|
38
|
|
|
Config::set('js-localization.test-config', 'new value'); |
|
39
|
|
|
$this->assertEquals($expectedJson, ConfigCachingService::getConfigJson()); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function testGetConfigJsonWithCacheDisabled() |
|
43
|
|
|
{ |
|
44
|
|
|
Config::set('js-localization.disable_config_cache', true); |
|
45
|
|
|
|
|
46
|
|
|
$expectedJson = json_encode($this->testConfigExportFlat); |
|
47
|
|
|
$this->assertEquals($expectedJson, ConfigCachingService::getConfigJson()); |
|
48
|
|
|
|
|
49
|
|
|
// Test that getConfigJson() returns the new value after Config::set() |
|
50
|
|
|
$this->testConfigExportFlat['js-localization.test-config'] = 'new value'; |
|
51
|
|
|
$expectedJson = json_encode($this->testConfigExportFlat); |
|
52
|
|
|
|
|
53
|
|
|
Config::set('js-localization.test-config', 'new value'); |
|
54
|
|
|
$this->assertEquals($expectedJson, ConfigCachingService::getConfigJson()); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
} |