Newer
Older
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
122
123
<?php
/**
* @file
* Contains \Drupal\Tests\Core\Cache\CacheFactoryTest.
*/
namespace Drupal\Tests\Core\Cache;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Component\Utility\Settings;
use Drupal\Core\Cache\CacheFactory;
use Drupal\Tests\UnitTestCase;
/**
* Tests the cache CacheFactory.
*
* @group Cache
*
* @coversDefaultClass \Drupal\Core\Cache\CacheFactory
*/
class CacheFactoryTest extends UnitTestCase {
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'Cache factory test',
'description' => 'Tests the cache CacheFactory.',
'group' => 'Cache',
);
}
/**
* Test that the cache factory falls back to the built-in default service.
*
* @covers ::__construct
* @covers ::get
*/
public function testCacheFactoryWithDefaultSettings() {
$settings = new Settings(array());
$cache_factory = new CacheFactory($settings);
$container = new ContainerBuilder();
$cache_factory->setContainer($container);
$builtin_default_backend_factory = $this->getMock('\Drupal\Core\Cache\CacheFactoryInterface');
$container->set('cache.backend.database', $builtin_default_backend_factory);
$render_bin = $this->getMock('\Drupal\Core\Cache\CacheBackendInterface');
$builtin_default_backend_factory->expects($this->once())
->method('get')
->with('render')
->will($this->returnValue($render_bin));
$actual_bin = $cache_factory->get('render');
$this->assertSame($render_bin, $actual_bin);
}
/**
* Test that the cache factory falls back to customized default service.
*
* @covers ::__construct
* @covers ::get
*/
public function testCacheFactoryWithCustomizedDefaultBackend() {
$settings = new Settings(array(
'cache' => array(
'default' => 'cache.backend.custom',
),
));
$cache_factory = new CacheFactory($settings);
$container = new ContainerBuilder();
$cache_factory->setContainer($container);
$custom_default_backend_factory = $this->getMock('\Drupal\Core\Cache\CacheFactoryInterface');
$container->set('cache.backend.custom', $custom_default_backend_factory);
$render_bin = $this->getMock('\Drupal\Core\Cache\CacheBackendInterface');
$custom_default_backend_factory->expects($this->once())
->method('get')
->with('render')
->will($this->returnValue($render_bin));
$actual_bin = $cache_factory->get('render');
$this->assertSame($render_bin, $actual_bin);
}
/**
* Test that the cache factory picks the correct per-bin service.
*
* @covers ::__construct
* @covers ::get
*/
public function testCacheFactoryWithSpecifiedPerBinBackend() {
$settings = new Settings(array(
'cache' => array(
'bins' => array(
'render' => 'cache.backend.custom',
),
),
));
$cache_factory = new CacheFactory($settings);
$container = new ContainerBuilder();
$cache_factory->setContainer($container);
$custom_render_backend_factory = $this->getMock('\Drupal\Core\Cache\CacheFactoryInterface');
$container->set('cache.backend.custom', $custom_render_backend_factory);
$render_bin = $this->getMock('\Drupal\Core\Cache\CacheBackendInterface');
$custom_render_backend_factory->expects($this->once())
->method('get')
->with('render')
->will($this->returnValue($render_bin));
$actual_bin = $cache_factory->get('render');
$this->assertSame($render_bin, $actual_bin);
}
}