1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LeKoala\DebugBar\Test\Collector; |
4
|
|
|
|
5
|
|
|
use LeKoala\DebugBar\Collector\PartialCacheCollector; |
6
|
|
|
use SilverStripe\Dev\SapphireTest; |
7
|
|
|
|
8
|
|
|
class PartialCacheCollectorTest extends SapphireTest |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var PartialCacheCollector |
12
|
|
|
*/ |
13
|
|
|
private $collector; |
14
|
|
|
|
15
|
|
|
protected function setUp() |
16
|
|
|
{ |
17
|
|
|
parent::setUp(); |
18
|
|
|
$this->collector = new PartialCacheCollector(); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function testGetName() |
22
|
|
|
{ |
23
|
|
|
$this->assertNotEmpty($this->collector->getName()); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Tests that the tab is returned and that the badge is optional |
28
|
|
|
*/ |
29
|
|
|
public function testGetWidgets() |
30
|
|
|
{ |
31
|
|
|
PartialCacheCollector::setTemplateCache(array()); |
32
|
|
|
$widgets = $this->collector->getWidgets(); |
33
|
|
|
$this->assertArrayHasKey('Partial Cache', $widgets); |
34
|
|
|
$this->assertArrayNotHasKey('Partial Cache:badge', $widgets); |
35
|
|
|
|
36
|
|
|
PartialCacheCollector::addTemplateCache('test', array('test')); |
37
|
|
|
$this->assertArrayHasKey('Partial Cache:badge', $this->collector->getWidgets()); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Tests that an array is returned with specific indexes set |
42
|
|
|
*/ |
43
|
|
|
public function testCollect() |
44
|
|
|
{ |
45
|
|
|
$result = $this->collector->collect(); |
46
|
|
|
$this->assertArrayHasKey('count', $result); |
47
|
|
|
$this->assertArrayHasKey('calls', $result); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Tests that adding an item to the cache increases its count |
52
|
|
|
*/ |
53
|
|
|
public function testAddTemplateCache() |
54
|
|
|
{ |
55
|
|
|
$count = count(PartialCacheCollector::getTemplateCache()); |
56
|
|
|
PartialCacheCollector::addTemplateCache('test1234', array('test')); |
57
|
|
|
$this->assertCount($count + 1, PartialCacheCollector::getTemplateCache()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Tests that the setter works |
62
|
|
|
*/ |
63
|
|
|
public function testSetTemplateCache() |
64
|
|
|
{ |
65
|
|
|
PartialCacheCollector::setTemplateCache(array()); |
66
|
|
|
$this->assertCount(0, PartialCacheCollector::getTemplateCache()); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|