1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* Test menu links depending on user permissions.
|
5 |
|
|
*/
|
6 |
|
|
class CtoolsPluginsGetInfoTestCase extends DrupalWebTestCase {
|
7 |
7e72b748
|
Assos Assos
|
|
8 |
|
|
/**
|
9 |
c304a780
|
Assos Assos
|
* {@inheritdoc}
|
10 |
7e72b748
|
Assos Assos
|
*/
|
11 |
85ad3d82
|
Assos Assos
|
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 |
1e39edcb
|
Assos Assos
|
'group' => 'ctools',
|
16 |
7e72b748
|
Assos Assos
|
'dependencies' => array('ctools'),
|
17 |
85ad3d82
|
Assos Assos
|
);
|
18 |
|
|
}
|
19 |
|
|
|
20 |
7e72b748
|
Assos Assos
|
/**
|
21 |
c304a780
|
Assos Assos
|
* {@inheritdoc}
|
22 |
7e72b748
|
Assos Assos
|
*/
|
23 |
c304a780
|
Assos Assos
|
public function setUp(array $modules = array()) {
|
24 |
7e72b748
|
Assos Assos
|
$modules[] = 'ctools';
|
25 |
|
|
$modules[] = 'ctools_plugin_test';
|
26 |
|
|
parent::setUp($modules);
|
27 |
85ad3d82
|
Assos Assos
|
}
|
28 |
|
|
|
29 |
7e72b748
|
Assos Assos
|
/**
|
30 |
|
|
* Assert helper to check that a specific plugin function exists.
|
31 |
|
|
*
|
32 |
|
|
* @param $module
|
33 |
|
|
* The module that owns the plugin.
|
34 |
|
|
* @param $type
|
35 |
|
|
* The type of plugin.
|
36 |
|
|
* @param $id
|
37 |
|
|
* The id of the specific plugin to load.
|
38 |
|
|
* @param $function
|
39 |
|
|
* The identifier of the function. For example, 'settings form'.
|
40 |
|
|
*/
|
41 |
85ad3d82
|
Assos Assos
|
protected function assertPluginFunction($module, $type, $id, $function = 'function') {
|
42 |
|
|
$func = ctools_plugin_load_function($module, $type, $id, $function);
|
43 |
|
|
$this->assertTrue(function_exists($func), t('Plugin @plugin of plugin type @module:@type successfully retrieved @retrieved for @function.', array(
|
44 |
|
|
'@plugin' => $id,
|
45 |
|
|
'@module' => $module,
|
46 |
|
|
'@type' => $type,
|
47 |
|
|
'@function' => $function,
|
48 |
|
|
'@retrieved' => $func,
|
49 |
|
|
)));
|
50 |
|
|
}
|
51 |
|
|
|
52 |
7e72b748
|
Assos Assos
|
/**
|
53 |
|
|
* Assert helper to check that a specific plugin function does NOT exist.
|
54 |
|
|
*
|
55 |
|
|
* @param $module
|
56 |
|
|
* The module that owns the plugin.
|
57 |
|
|
* @param $type
|
58 |
|
|
* The type of plugin.
|
59 |
|
|
* @param $id
|
60 |
|
|
* The id of the specific plugin to load.
|
61 |
|
|
* @param $function
|
62 |
|
|
* The identifier of the function. For example, 'settings form'.
|
63 |
|
|
*/
|
64 |
85ad3d82
|
Assos Assos
|
protected function assertPluginMissingFunction($module, $type, $id, $function = 'function') {
|
65 |
|
|
$func = ctools_plugin_load_function($module, $type, $id, $function);
|
66 |
|
|
$this->assertEqual($func, NULL, t('Plugin @plugin of plugin type @module:@type for @function with missing function successfully failed.', array(
|
67 |
|
|
'@plugin' => $id,
|
68 |
|
|
'@module' => $module,
|
69 |
|
|
'@type' => $type,
|
70 |
|
|
'@function' => $func,
|
71 |
|
|
)));
|
72 |
|
|
}
|
73 |
|
|
|
74 |
7e72b748
|
Assos Assos
|
/**
|
75 |
|
|
* Assert helper to check that a plugin can be loaded using a named class.
|
76 |
|
|
*
|
77 |
|
|
* @param $module
|
78 |
|
|
* The module that owns the plugin.
|
79 |
|
|
* @param $type
|
80 |
|
|
* The type of plugin.
|
81 |
|
|
* @param $id
|
82 |
|
|
* The id of the specific plugin to load.
|
83 |
|
|
* @param string $class
|
84 |
|
|
* The name of the PHP class to load.
|
85 |
|
|
*/
|
86 |
85ad3d82
|
Assos Assos
|
protected function assertPluginClass($module, $type, $id, $class = 'handler') {
|
87 |
|
|
$class_name = ctools_plugin_load_class($module, $type, $id, $class);
|
88 |
|
|
$this->assertTrue(class_exists($class_name), t('Plugin @plugin of plugin type @module:@type successfully retrieved @retrieved for @class.', array(
|
89 |
|
|
'@plugin' => $id,
|
90 |
|
|
'@module' => $module,
|
91 |
|
|
'@type' => $type,
|
92 |
|
|
'@class' => $class,
|
93 |
|
|
'@retrieved' => $class_name,
|
94 |
|
|
)));
|
95 |
|
|
}
|
96 |
|
|
|
97 |
7e72b748
|
Assos Assos
|
/**
|
98 |
|
|
* Assert helper to check that a plugin DOES NOT contain the named class.
|
99 |
|
|
*
|
100 |
|
|
* @param $module
|
101 |
|
|
* The module that owns the plugin.
|
102 |
|
|
* @param $type
|
103 |
|
|
* The type of plugin.
|
104 |
|
|
* @param $id
|
105 |
|
|
* The id of the specific plugin to load.
|
106 |
|
|
* @param string $class
|
107 |
|
|
* The name of the PHP class to load.
|
108 |
|
|
*/
|
109 |
85ad3d82
|
Assos Assos
|
protected function assertPluginMissingClass($module, $type, $id, $class = 'handler') {
|
110 |
|
|
$class_name = ctools_plugin_load_class($module, $type, $id, $class);
|
111 |
|
|
$this->assertEqual($class_name, NULL, t('Plugin @plugin of plugin type @module:@type for @class with missing class successfully failed.', array(
|
112 |
|
|
'@plugin' => $id,
|
113 |
|
|
'@module' => $module,
|
114 |
|
|
'@type' => $type,
|
115 |
|
|
'@class' => $class,
|
116 |
|
|
)));
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
/**
|
120 |
|
|
* Test that plugins are loaded correctly.
|
121 |
|
|
*/
|
122 |
c304a780
|
Assos Assos
|
public function testPluginLoading() {
|
123 |
85ad3d82
|
Assos Assos
|
ctools_include('plugins');
|
124 |
|
|
$module = 'ctools_plugin_test';
|
125 |
|
|
$type = 'not_cached';
|
126 |
|
|
|
127 |
|
|
// Test function retrieval for plugins using different definition methods.
|
128 |
|
|
$this->assertPluginFunction($module, $type, 'plugin_array', 'function');
|
129 |
|
|
$this->assertPluginFunction($module, $type, 'plugin_array2', 'function');
|
130 |
|
|
$this->assertPluginMissingFunction($module, $type, 'plugin_array_dne', 'function');
|
131 |
|
|
$this->assertPluginFunction($module, "big_hook_$type", 'test1', 'function');
|
132 |
|
|
|
133 |
|
|
// Test class retrieval for plugins using different definition methods.
|
134 |
|
|
$this->assertPluginClass($module, $type, 'plugin_array', 'handler');
|
135 |
|
|
$this->assertPluginClass($module, $type, 'plugin_array2', 'handler');
|
136 |
|
|
$this->assertPluginMissingClass($module, $type, 'plugin_array_dne', 'handler');
|
137 |
7e72b748
|
Assos Assos
|
// @todo Test big hook plugins.
|
138 |
85ad3d82
|
Assos Assos
|
|
139 |
|
|
$type = 'cached';
|
140 |
|
|
|
141 |
|
|
// Test function retrieval for plugins using different definition methods.
|
142 |
|
|
$this->assertPluginFunction($module, $type, 'plugin_array', 'function');
|
143 |
|
|
$this->assertPluginFunction($module, $type, 'plugin_array2', 'function');
|
144 |
|
|
$this->assertPluginMissingFunction($module, $type, 'plugin_array_dne', 'function');
|
145 |
|
|
$this->assertPluginFunction($module, "big_hook_$type", 'test1', 'function');
|
146 |
|
|
|
147 |
|
|
// Test class retrieval for plugins using different definition methods.
|
148 |
|
|
$this->assertPluginClass($module, $type, 'plugin_array', 'handler');
|
149 |
|
|
$this->assertPluginClass($module, $type, 'plugin_array2', 'handler');
|
150 |
|
|
$this->assertPluginMissingClass($module, $type, 'plugin_array_dne', 'handler');
|
151 |
7e72b748
|
Assos Assos
|
// @todo Test big hook plugins.
|
152 |
85ad3d82
|
Assos Assos
|
}
|
153 |
7e72b748
|
Assos Assos
|
|
154 |
85ad3d82
|
Assos Assos
|
} |