View source
<?php
class CtoolsUnitObjectCachePlugins extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Object cache storage (unit tests)',
'description' => 'Verify that objects are written, readable and lockable.',
'group' => 'ctools',
'dependencies' => array(
'ctools',
),
);
}
public function setUp(array $modules = array()) {
$modules[] = 'ctools';
parent::setUp($modules);
}
public function assertValidCachePlugin($p, $msg) {
$this
->assertTrue(is_array($p), $msg . ': plugin is an array');
$this
->assertEqual($p['plugin type'], 'cache', $msg . ': type is cache');
$this
->assertTrue(array_key_exists('title', $p), $msg . ': title element exists');
$this
->assertTrue(!empty($p['title']) && is_string($p['title']), $msg . ': title is a string');
$this
->assertTrue(array_key_exists('cache get', $p), $msg . ': has a get function');
$this
->assertTrue(!empty($p['cache get']) && is_callable($p['cache get']), $msg . ': get is executable');
$this
->assertTrue(array_key_exists('cache set', $p), $msg . ': has a set function');
$this
->assertTrue(!empty($p['cache set']) && is_callable($p['cache set']), $msg . ': set is executable');
$this
->assertTrue(!array_key_exists('cache break', $p) || is_callable($p['cache break']), $msg . ': break is executable');
$this
->assertTrue(!array_key_exists('cache finalize', $p) || is_callable($p['cache finalize']), $msg . ': finalize is executable');
}
public function assertPluginNotFound($p, $msg) {
$this
->assertTrue(is_array($p), $msg . ': is an array');
$plugin = array_shift($p);
$this
->assertNull($plugin, $msg . ': no plugin info');
$data = array_shift($p);
$this
->assertTrue(empty($data) || is_string($data), $msg . ': data string-like');
$this
->assertTrue(empty($p), $msg . ': just two elements');
}
public function assertPluginFound($p, $msg) {
$this
->assertTrue(is_array($p), $msg . ': is an array');
$plugin = array_shift($p);
$this
->assertTrue(is_array($plugin), $msg . ': has plugin data');
$data = array_shift($p);
$this
->assertTrue(empty($data) || is_string($data), $msg . ': data is string-like');
$this
->assertTrue(empty($p), $msg . ': just two elements');
}
public function testFindSimpleCachePlugin() {
ctools_include('cache');
$plugin = ctools_cache_find_plugin('simple');
$this
->assertPluginFound($plugin, 'The Simple Cache plugin is present');
$this
->assertValidCachePlugin($plugin[0], 'The Simple Cache plugin');
$plugin = ctools_cache_find_plugin('simple::data');
$this
->assertPluginFound($plugin, 'The Simple Cache plugin is present, with data');
}
public function testFindExportUICachePlugin() {
ctools_include('cache');
$plugin = ctools_cache_find_plugin('export_ui');
$this
->assertPluginFound($plugin, 'The Export UI Cache plugin is present');
$this
->assertValidCachePlugin($plugin[0], 'The Export Cache plugin');
$plugin = ctools_cache_find_plugin('export_ui::data');
$this
->assertTrue(is_array($plugin), 'The Export UI Cache plugin is present, with data');
}
public function testFindFoobarbazCachePlugin() {
ctools_include('cache');
$plugin = ctools_cache_find_plugin('foobarbaz');
$this
->assertPluginNotFound($plugin, 'The Foobarbaz Cache plugin is absent');
$plugin = ctools_cache_find_plugin('foobarbaz::data');
$this
->assertPluginNotFound($plugin, 'The Foobarbaz Cache plugin is absent, with data');
}
}