1
|
<?php
|
2
|
/**
|
3
|
* @file
|
4
|
* Tests for different parts of the ctools plugin system.
|
5
|
*/
|
6
|
|
7
|
/**
|
8
|
* Test menu links depending on user permissions.
|
9
|
*/
|
10
|
class CtoolsPluginsGetInfoTestCase extends DrupalWebTestCase {
|
11
|
public static function getInfo() {
|
12
|
return array(
|
13
|
'name' => 'Get plugin info',
|
14
|
'description' => 'Verify that plugin type definitions can properly set and overide values.',
|
15
|
'group' => 'Chaos Tools Suite',
|
16
|
);
|
17
|
}
|
18
|
|
19
|
function setUp() {
|
20
|
// Additionally enable contact module.
|
21
|
parent::setUp('ctools', 'ctools_plugin_test');
|
22
|
}
|
23
|
|
24
|
protected function assertPluginFunction($module, $type, $id, $function = 'function') {
|
25
|
$func = ctools_plugin_load_function($module, $type, $id, $function);
|
26
|
$this->assertTrue(function_exists($func), t('Plugin @plugin of plugin type @module:@type successfully retrieved @retrieved for @function.', array(
|
27
|
'@plugin' => $id,
|
28
|
'@module' => $module,
|
29
|
'@type' => $type,
|
30
|
'@function' => $function,
|
31
|
'@retrieved' => $func,
|
32
|
)));
|
33
|
}
|
34
|
|
35
|
protected function assertPluginMissingFunction($module, $type, $id, $function = 'function') {
|
36
|
$func = ctools_plugin_load_function($module, $type, $id, $function);
|
37
|
$this->assertEqual($func, NULL, t('Plugin @plugin of plugin type @module:@type for @function with missing function successfully failed.', array(
|
38
|
'@plugin' => $id,
|
39
|
'@module' => $module,
|
40
|
'@type' => $type,
|
41
|
'@function' => $func,
|
42
|
)));
|
43
|
}
|
44
|
|
45
|
protected function assertPluginClass($module, $type, $id, $class = 'handler') {
|
46
|
$class_name = ctools_plugin_load_class($module, $type, $id, $class);
|
47
|
$this->assertTrue(class_exists($class_name), t('Plugin @plugin of plugin type @module:@type successfully retrieved @retrieved for @class.', array(
|
48
|
'@plugin' => $id,
|
49
|
'@module' => $module,
|
50
|
'@type' => $type,
|
51
|
'@class' => $class,
|
52
|
'@retrieved' => $class_name,
|
53
|
)));
|
54
|
}
|
55
|
|
56
|
protected function assertPluginMissingClass($module, $type, $id, $class = 'handler') {
|
57
|
$class_name = ctools_plugin_load_class($module, $type, $id, $class);
|
58
|
$this->assertEqual($class_name, NULL, t('Plugin @plugin of plugin type @module:@type for @class with missing class successfully failed.', array(
|
59
|
'@plugin' => $id,
|
60
|
'@module' => $module,
|
61
|
'@type' => $type,
|
62
|
'@class' => $class,
|
63
|
)));
|
64
|
}
|
65
|
|
66
|
/**
|
67
|
* Test that plugins are loaded correctly.
|
68
|
*/
|
69
|
function testPluginLoading() {
|
70
|
ctools_include('plugins');
|
71
|
$module = 'ctools_plugin_test';
|
72
|
$type = 'not_cached';
|
73
|
|
74
|
// Test function retrieval for plugins using different definition methods.
|
75
|
$this->assertPluginFunction($module, $type, 'plugin_array', 'function');
|
76
|
$this->assertPluginFunction($module, $type, 'plugin_array2', 'function');
|
77
|
$this->assertPluginMissingFunction($module, $type, 'plugin_array_dne', 'function');
|
78
|
$this->assertPluginFunction($module, "big_hook_$type", 'test1', 'function');
|
79
|
|
80
|
// Test class retrieval for plugins using different definition methods.
|
81
|
$this->assertPluginClass($module, $type, 'plugin_array', 'handler');
|
82
|
$this->assertPluginClass($module, $type, 'plugin_array2', 'handler');
|
83
|
$this->assertPluginMissingClass($module, $type, 'plugin_array_dne', 'handler');
|
84
|
// TODO Test big hook plugins.
|
85
|
|
86
|
$type = 'cached';
|
87
|
|
88
|
// Test function retrieval for plugins using different definition methods.
|
89
|
$this->assertPluginFunction($module, $type, 'plugin_array', 'function');
|
90
|
$this->assertPluginFunction($module, $type, 'plugin_array2', 'function');
|
91
|
$this->assertPluginMissingFunction($module, $type, 'plugin_array_dne', 'function');
|
92
|
$this->assertPluginFunction($module, "big_hook_$type", 'test1', 'function');
|
93
|
|
94
|
// Test class retrieval for plugins using different definition methods.
|
95
|
$this->assertPluginClass($module, $type, 'plugin_array', 'handler');
|
96
|
$this->assertPluginClass($module, $type, 'plugin_array2', 'handler');
|
97
|
$this->assertPluginMissingClass($module, $type, 'plugin_array_dne', 'handler');
|
98
|
// TODO Test big hook plugins.
|
99
|
}
|
100
|
}
|