1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* Test ctools_cache_find_plugin and the structure of the default cache plugins.
|
5
|
*/
|
6
|
class CtoolsUnitObjectCachePlugins extends DrupalWebTestCase {
|
7
|
|
8
|
/**
|
9
|
* {@inheritdoc}
|
10
|
*/
|
11
|
public static function getInfo() {
|
12
|
return array(
|
13
|
'name' => 'Object cache storage (unit tests)',
|
14
|
'description' => 'Verify that objects are written, readable and lockable.',
|
15
|
'group' => 'ctools',
|
16
|
'dependencies' => array('ctools'),
|
17
|
);
|
18
|
}
|
19
|
|
20
|
/**
|
21
|
* {@inheritdoc}
|
22
|
*/
|
23
|
public function setUp(array $modules = array()) {
|
24
|
$modules[] = 'ctools';
|
25
|
parent::setUp($modules);
|
26
|
}
|
27
|
|
28
|
/**
|
29
|
* Check that the supplied array looks like a ctools cache plugin.
|
30
|
*
|
31
|
* @param mixed $p
|
32
|
* The value to check.
|
33
|
* @param string $msg
|
34
|
* Prefix of the assertion message.
|
35
|
*/
|
36
|
public function assertValidCachePlugin($p, $msg) {
|
37
|
$this->assertTrue(is_array($p), $msg . ': plugin is an array');
|
38
|
|
39
|
$this->assertEqual($p['plugin type'], 'cache', $msg . ': type is cache');
|
40
|
|
41
|
$this->assertTrue(array_key_exists('title', $p), $msg . ': title element exists');
|
42
|
$this->assertTrue(!empty($p['title']) && is_string($p['title']), $msg . ': title is a string');
|
43
|
|
44
|
$this->assertTrue(array_key_exists('cache get', $p), $msg . ': has a get function');
|
45
|
$this->assertTrue(!empty($p['cache get']) && is_callable($p['cache get']), $msg . ': get is executable');
|
46
|
|
47
|
$this->assertTrue(array_key_exists('cache set', $p), $msg . ': has a set function');
|
48
|
$this->assertTrue(!empty($p['cache set']) && is_callable($p['cache set']), $msg . ': set is executable');
|
49
|
|
50
|
// @todo Clear is required by the spec (cache.inc:40..48): but export_ui
|
51
|
// cache doesn't implement it. Enable the assertions when that problem is
|
52
|
// solved.
|
53
|
// $this->assertTrue(array_key_exists('cache clear', $p), $msg . ': has a clear function');
|
54
|
// $this->assertTrue(is_callable($p['cache clear']), $msg . ': clear is executable');
|
55
|
// @todo Break is optional acc'd to spec but does anything implement it?
|
56
|
$this->assertTrue(!array_key_exists('cache break', $p) || is_callable($p['cache break']), $msg . ': break is executable');
|
57
|
|
58
|
// @todo Finalize is optional so don't fail if not there??
|
59
|
$this->assertTrue(!array_key_exists('cache finalize', $p) || is_callable($p['cache finalize']), $msg . ': finalize is executable');
|
60
|
}
|
61
|
|
62
|
/**
|
63
|
* Check the return value of the ctools_cache_find_plugin function.
|
64
|
*
|
65
|
* @param mixed $p
|
66
|
* The value to check.
|
67
|
* @param string $msg
|
68
|
* Prefix of the assertion message.
|
69
|
*/
|
70
|
public function assertPluginNotFound($p, $msg) {
|
71
|
$this->assertTrue(is_array($p), $msg . ': is an array');
|
72
|
$plugin = array_shift($p);
|
73
|
$this->assertNull($plugin, $msg . ': no plugin info');
|
74
|
$data = array_shift($p);
|
75
|
$this->assertTrue(empty($data) || is_string($data), $msg . ': data string-like');
|
76
|
$this->assertTrue(empty($p), $msg . ': just two elements');
|
77
|
}
|
78
|
|
79
|
/**
|
80
|
* Check the return value of the ctools_cache_find_plugin function.
|
81
|
*
|
82
|
* @param mixed $p
|
83
|
* The value to check.
|
84
|
* @param string $msg
|
85
|
* Prefix of the assertion message.
|
86
|
*/
|
87
|
public function assertPluginFound($p, $msg) {
|
88
|
$this->assertTrue(is_array($p), $msg . ': is an array');
|
89
|
$plugin = array_shift($p);
|
90
|
$this->assertTrue(is_array($plugin), $msg . ': has plugin data');
|
91
|
$data = array_shift($p);
|
92
|
$this->assertTrue(empty($data) || is_string($data), $msg . ': data is string-like');
|
93
|
$this->assertTrue(empty($p), $msg . ': just two elements');
|
94
|
}
|
95
|
|
96
|
/**
|
97
|
* Test to see that we can find the standard simple plugin.
|
98
|
*/
|
99
|
public function testFindSimpleCachePlugin() {
|
100
|
ctools_include('cache');
|
101
|
|
102
|
// The simple plugin.
|
103
|
$plugin = ctools_cache_find_plugin('simple');
|
104
|
$this->assertPluginFound($plugin, 'The Simple Cache plugin is present');
|
105
|
$this->assertValidCachePlugin($plugin[0], 'The Simple Cache plugin');
|
106
|
|
107
|
// The simple plugin, with ::.
|
108
|
$plugin = ctools_cache_find_plugin('simple::data');
|
109
|
$this->assertPluginFound($plugin, 'The Simple Cache plugin is present, with data');
|
110
|
}
|
111
|
|
112
|
/**
|
113
|
* Test to see that we can find the standard export_ui plugin.
|
114
|
*/
|
115
|
public function testFindExportUICachePlugin() {
|
116
|
ctools_include('cache');
|
117
|
|
118
|
// The export plugin.
|
119
|
$plugin = ctools_cache_find_plugin('export_ui');
|
120
|
$this->assertPluginFound($plugin, 'The Export UI Cache plugin is present');
|
121
|
$this->assertValidCachePlugin($plugin[0], 'The Export Cache plugin');
|
122
|
|
123
|
// The export plugin, with ::.
|
124
|
$plugin = ctools_cache_find_plugin('export_ui::data');
|
125
|
$this->assertTrue(is_array($plugin), 'The Export UI Cache plugin is present, with data');
|
126
|
}
|
127
|
|
128
|
/**
|
129
|
* Test to see that we don't find plugins that aren't there.
|
130
|
*/
|
131
|
public function testFindFoobarbazCachePlugin() {
|
132
|
ctools_include('cache');
|
133
|
|
134
|
// An imaginary foobarbaz plugin.
|
135
|
$plugin = ctools_cache_find_plugin('foobarbaz');
|
136
|
$this->assertPluginNotFound($plugin, 'The Foobarbaz Cache plugin is absent');
|
137
|
$plugin = ctools_cache_find_plugin('foobarbaz::data');
|
138
|
$this->assertPluginNotFound($plugin, 'The Foobarbaz Cache plugin is absent, with data');
|
139
|
}
|
140
|
|
141
|
}
|