CacheManagerTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 90
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 3 1
A tearDown() 0 4 1
A cacheManagerIsSingleton() 0 7 1
A canFlushCache() 0 15 1
A canCacheBeDisabled() 0 9 1
A disabledCacheReturnsNoData() 0 16 1
1
<?php
2
3
namespace AOE\Languagevisibility\Tests\Unit;
4
5
/***************************************************************
6
 * Copyright notice
7
 *
8
 * (c) 2016 AOE GmbH <[email protected]>
9
 * All rights reserved
10
 *
11
 * This script is part of the TYPO3 project. The TYPO3 project is
12
 * free software; you can redistribute it and/or modify
13
 * it under the terms of the GNU General Public License as published by
14
 * the Free Software Foundation; either version 2 of the License, or
15
 * (at your option) any later version.
16
 *
17
 * The GNU General Public License can be found at
18
 * http://www.gnu.org/copyleft/gpl.html.
19
 *
20
 * This script is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 * GNU General Public License for more details.
24
 *
25
 * This copyright notice MUST APPEAR in all copies of the script!
26
 ***************************************************************/
27
28
use AOE\Languagevisibility\CacheManager;
29
30
class CacheManagerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
31
32
	/**
33
	 * Force the enable state of the cache and flush it.
34
	 */
35
	public function setUp() {
36
		$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['languagevisibility'] = serialize(array('useCache' => 1));
37
	}
38
39
	public function tearDown() {
40
		parent::tearDown();
41
		CacheManager::getInstance()->flushAllCaches();
42
	}
43
44
	/**
45
	 * This method should be used to test that the cacheManager is a
46
	 * singleton.
47
	 *
48
	 * @test
49
	 * @return void
50
	 */
51
	public function cacheManagerIsSingleton() {
52
		$one 	= CacheManager::getInstance();
53
		$two	= CacheManager::getInstance();
54
55
		$one->set('test', '12345');
56
		$this->assertEquals($two->get('test'), '12345');
57
	}
58
59
	/**
60
	 * This method is used to check if the cache can be flushed.
61
	 *
62
	 * @test
63
	 * @return void
64
	 */
65
	public function canFlushCache() {
66
		$cache 	= CacheManager::getInstance();
67
		$cache->flushAllCaches();
68
69
		$cache->set('test', array('one' => 'blabla'));
70
71
		$resultA = $cache->get('test');
72
		$this->assertTrue(is_array($resultA));
73
		$this->assertEquals($resultA['one'], 'blabla');
74
75
		$cache->flushAllCaches();
76
		$resultB = $cache->get('test');
77
78
		$this->assertTrue(empty($resultB));
79
	}
80
81
	/**
82
	 * This method is used to test if the cache can be disabled global.
83
	 *
84
	 * @test
85
	 * @return void
86
	 */
87
	public function canCacheBeDisabled() {
88
		$cache = CacheManager::getInstance();
89
90
		$cache->enableCache();
91
		$this->assertTrue($cache->isCacheEnabled());
92
		$cache->disableCache();
93
94
		$this->assertFalse($cache->isCacheEnabled());
95
	}
96
97
	/**
98
	 * This method is used to test if a disabled cache returns cache hits.
99
	 *
100
	 * @test
101
	 * @return void
102
	 */
103
	public function disabledCacheReturnsNoData() {
104
		$cache = CacheManager::getInstance();
105
		$cache->enableCache();
106
107
		$cache->flushAllCaches();
108
109
		$cache->set('aaaa', 12);
110
		$this->assertEquals(12, $cache->get('aaaa'));
111
112
		$cache->disableCache();
113
114
		$this->assertEquals(array(), $cache->get('aaaa'));
115
116
		$cache->enableCache();
117
		$this->assertEquals(12, $cache->get('aaaa'));
118
	}
119
}
120