1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file Test classes for code in the CTools module file.
|
5
|
*/
|
6
|
|
7
|
/**
|
8
|
* Test menu links depending on user permissions.
|
9
|
*/
|
10
|
class CtoolsModuleTestCase extends DrupalWebTestCase {
|
11
|
|
12
|
/**
|
13
|
* {@inheritdoc}
|
14
|
*/
|
15
|
public static function getInfo() {
|
16
|
return array(
|
17
|
'name' => 'Ctools module functions tests',
|
18
|
'description' => 'Check functions in the ctools.module not otherwise tested.',
|
19
|
'group' => 'ctools',
|
20
|
'dependencies' => array('ctools'),
|
21
|
);
|
22
|
}
|
23
|
|
24
|
/**
|
25
|
* {@inheritdoc}
|
26
|
*/
|
27
|
public function setUp(array $modules = array()) {
|
28
|
$modules[] = 'ctools';
|
29
|
parent::setUp($modules);
|
30
|
}
|
31
|
|
32
|
/**
|
33
|
* Test that the break phrase function behaves as expected.
|
34
|
*/
|
35
|
public function testBreakPhrase() {
|
36
|
$tests = array(
|
37
|
NULL => array('value' => array()),
|
38
|
'' => array('value' => array()),
|
39
|
'1' => array('operator' => 'and', 'value' => array(1)),
|
40
|
'99' => array('operator' => 'and', 'value' => array(99)),
|
41
|
'+1' => array('invalid_input' => TRUE, 'value' => array(-1)),
|
42
|
' 1' => array('invalid_input' => TRUE, 'value' => array(-1)),
|
43
|
'1 ' => array('invalid_input' => TRUE, 'value' => array(-1)),
|
44
|
'-1' => array('invalid_input' => TRUE, 'value' => array(-1)),
|
45
|
'-99' => array('invalid_input' => TRUE, 'value' => array(-1)),
|
46
|
'1,2' => array('operator' => 'and', 'value' => array(1, 2)),
|
47
|
'1 2' => array('operator' => 'or', 'value' => array(1, 2)),
|
48
|
'1+2' => array('operator' => 'or', 'value' => array(1, 2)),
|
49
|
'1,2,3' => array('operator' => 'and', 'value' => array(1, 2, 3)),
|
50
|
'1 2 3' => array('operator' => 'or', 'value' => array(1, 2, 3)),
|
51
|
'1+2+3' => array('operator' => 'or', 'value' => array(1, 2, 3)),
|
52
|
'1 , 2 , 3' => array('invalid_input' => TRUE, 'value' => array(-1)),
|
53
|
'1 + 2 + 3' => array('invalid_input' => TRUE, 'value' => array(-1)),
|
54
|
'1,2,3,4,5,6,7,8,9' => array(
|
55
|
'operator' => 'and',
|
56
|
'value' => array(1, 2, 3, 4, 5, 6, 7, 8, 9),
|
57
|
),
|
58
|
'1 2,3,4 5 6 7 8 9' => array('invalid_input' => TRUE, 'value' => array(-1)),
|
59
|
);
|
60
|
|
61
|
foreach ($tests as $string => $expected) {
|
62
|
$result = ctools_break_phrase($string);
|
63
|
$expected = (object) $expected;
|
64
|
$this->assertEqual($result, $expected, 'Break Phrase test patterns: ' . $string);
|
65
|
}
|
66
|
}
|
67
|
|
68
|
/**
|
69
|
* Test that the (deprecated) getuserroles returns expected array.
|
70
|
*/
|
71
|
public function testGetUserRoles() {
|
72
|
$result = ctools_get_roles();
|
73
|
$this->assertTrue(is_array($result), 'get_roles returns an array');
|
74
|
|
75
|
// A key-value array of integers.
|
76
|
foreach ($result as $k => $v) {
|
77
|
$this->assertTrue(is_numeric($k), 'Role key is numeric; ' . $k);
|
78
|
$this->assertTrue(is_string($v), 'Role id is string; ' . $v);
|
79
|
}
|
80
|
}
|
81
|
|
82
|
/**
|
83
|
* Test the ctools_attach_js function returns the expected paths.
|
84
|
*/
|
85
|
public function testAttachJs() {
|
86
|
$taxonomy_path = drupal_get_path('module', 'taxonomy');
|
87
|
$ctools_path = drupal_get_path('module', 'ctools');
|
88
|
|
89
|
// Func should probably do a different thing but this is current behaviour.
|
90
|
$path = ctools_attach_js('');
|
91
|
$this->assertEqual($path, $ctools_path . '/js/.js', 'Attach an empty string');
|
92
|
|
93
|
$path = ctools_attach_js('foo');
|
94
|
$this->assertEqual($path, $ctools_path . '/js/foo.js', 'Attach simple string');
|
95
|
|
96
|
$path = ctools_attach_js('foo', 'ctools', '');
|
97
|
$this->assertEqual($path, $ctools_path . '//foo.js', 'Attach string with empty subdir');
|
98
|
|
99
|
$path = ctools_attach_js('foo', 'ctools', 'javascript');
|
100
|
$this->assertEqual($path, $ctools_path . '/javascript/foo.js', 'Attach string with alternate subdir');
|
101
|
|
102
|
$path = ctools_attach_js('foo', 'taxonomy', 'javascript');
|
103
|
$this->assertEqual($path, $taxonomy_path . '/javascript/foo.js', 'Attach string from different module');
|
104
|
}
|
105
|
|
106
|
/**
|
107
|
* Test the ctools_attach_css function returns the expected paths.
|
108
|
*/
|
109
|
public function testAttachCss() {
|
110
|
$taxonomy_path = drupal_get_path('module', 'taxonomy');
|
111
|
$ctools_path = drupal_get_path('module', 'ctools');
|
112
|
|
113
|
// Func should probably do a different thing but this is current behaviour.
|
114
|
$path = ctools_attach_css('');
|
115
|
$this->assertEqual($path, $ctools_path . '/css/.css', 'Attach empty string');
|
116
|
|
117
|
$path = ctools_attach_css('foo');
|
118
|
$this->assertEqual($path, $ctools_path . '/css/foo.css', 'Attach simple string');
|
119
|
|
120
|
$path = ctools_attach_css('foo', 'ctools', '');
|
121
|
$this->assertEqual($path, $ctools_path . '//foo.css', 'Attach string with empty subdir');
|
122
|
|
123
|
$path = ctools_attach_css('foo', 'ctools', 'theme');
|
124
|
$this->assertEqual($path, $ctools_path . '/theme/foo.css', 'Attach string with alternate subdir');
|
125
|
|
126
|
$path = ctools_attach_css('foo', 'taxonomy', 'theme');
|
127
|
$this->assertEqual($path, $taxonomy_path . '/theme/foo.css', 'Attach string from different module');
|
128
|
}
|
129
|
|
130
|
/**
|
131
|
* Test the ctools version compare function.
|
132
|
*/
|
133
|
public function testApiVersionCompare() {
|
134
|
// We're beyond version 1.
|
135
|
$ok = ctools_api_version('1.0');
|
136
|
$this->assertTrue($ok, 'Check API version 1.0 is ok');
|
137
|
|
138
|
// We're beyond version 1.0.1 too.
|
139
|
$ok = ctools_api_version('1.0.1');
|
140
|
$this->assertTrue($ok, 'Check API version 1.0.1 is ok');
|
141
|
|
142
|
// Not (yet) on api version 10.
|
143
|
$ok = ctools_api_version('10.0');
|
144
|
$this->assertFalse($ok, 'Check API version 10.0 is not ok');
|
145
|
|
146
|
// We are (currently) between version 1.1 and version 4.0.
|
147
|
$ok = ctools_api_version('1.1', '4.0');
|
148
|
$this->assertTrue($ok, 'Check API is between 1 and 4');
|
149
|
}
|
150
|
|
151
|
/**
|
152
|
* Test that the ctools_classs_add works.
|
153
|
*/
|
154
|
public function testClassesAdd() {
|
155
|
ctools_class_reset();
|
156
|
|
157
|
ctools_class_add('testclass');
|
158
|
|
159
|
$classes = ctools_get_classes();
|
160
|
$this->assertEqual(is_array($classes), 1, 'Classes should be an array');
|
161
|
$this->assertEqual(count($classes), 1, 'Classes array has one element');
|
162
|
$this->assertEqual(count($classes['html']), 1, 'Classes array has element: html');
|
163
|
$this->assertTrue(isset($classes['html']['add']), 'Classes array has element: html/add');
|
164
|
$this->assertEqual($classes['html']['add'], array('testclass'), 'Classes array has expected value');
|
165
|
|
166
|
ctools_class_add('class2 class3');
|
167
|
|
168
|
$classes = ctools_get_classes();
|
169
|
$this->assertEqual(is_array($classes), 1, 'Classes should be an array');
|
170
|
$this->assertEqual(count($classes['html']), 1, 'Classes array has element: html');
|
171
|
// TODO: An undesirable result: array('testclass', 'class2', 'class3') is better.
|
172
|
$this->assertEqual($classes['html']['add'], array(
|
173
|
'testclass',
|
174
|
'class2 class3',
|
175
|
), 'Classes array has expected value');
|
176
|
}
|
177
|
|
178
|
/**
|
179
|
* Test that the ctools_classs_remove works.
|
180
|
*/
|
181
|
public function testClassesRemove() {
|
182
|
ctools_class_reset();
|
183
|
|
184
|
ctools_class_remove('testclass');
|
185
|
|
186
|
$classes = ctools_get_classes();
|
187
|
$this->assertEqual(is_array($classes), 1, 'Classes should be an array');
|
188
|
$this->assertEqual(count($classes), 1, 'Classes array has one element');
|
189
|
$this->assertEqual(count($classes['html']), 1, 'Classes array has element: html');
|
190
|
$this->assertTrue(isset($classes['html']['remove']), 'Classes array has element: html/remove');
|
191
|
$this->assertEqual($classes['html']['remove'], array('testclass'), 'Classes array has expected value');
|
192
|
|
193
|
ctools_class_remove('class2 class3');
|
194
|
|
195
|
$classes = ctools_get_classes();
|
196
|
$this->assertEqual(count($classes), 1, 'Classes array has one element');
|
197
|
$this->assertEqual(count($classes['html']), 1, 'Classes array has element: html');
|
198
|
// This is an undesirable result, is array('testclass', 'class2', 'class3') better.
|
199
|
$this->assertEqual($classes['html']['remove'], array(
|
200
|
'testclass',
|
201
|
'class2 class3',
|
202
|
), 'Classes array has expected value');
|
203
|
}
|
204
|
|
205
|
/**
|
206
|
* Test that the ctools_classs_add and ctools_classs_remove interact well.
|
207
|
*/
|
208
|
public function testClassesAddRemove() {
|
209
|
ctools_class_reset();
|
210
|
|
211
|
ctools_class_add('testclass');
|
212
|
ctools_class_remove('testclass');
|
213
|
|
214
|
$classes = ctools_get_classes();
|
215
|
$this->assertTrue(isset($classes['html']['add']), 'Classes array has an add set');
|
216
|
$this->assertEqual($classes['html']['add'], array('testclass'), 'testclass is in the add set');
|
217
|
$this->assertTrue(isset($classes['html']['remove']), 'Classes array has a remove set');
|
218
|
// TODO: Is it really good to let this happen?
|
219
|
$this->assertEqual($classes['html']['remove'], array('testclass'), 'testclass is in the remove set');
|
220
|
}
|
221
|
|
222
|
/**
|
223
|
* Test that the ctools_classs_add and ctools_classs_remove interact well .. 2.
|
224
|
*/
|
225
|
public function testClassesAddRemove2() {
|
226
|
ctools_class_reset();
|
227
|
|
228
|
ctools_class_add('class2 class3');
|
229
|
ctools_class_remove('class3');
|
230
|
|
231
|
$classes = ctools_get_classes();
|
232
|
$this->assertTrue(isset($classes['html']['add']), 'Classes array has an add set');
|
233
|
$this->assertEqual($classes['html']['add'], array('class2 class3'), 'Added class2 class3 is in add set');
|
234
|
$this->assertTrue(isset($classes['html']['remove']), 'Classes array has a remove set');
|
235
|
// TODO: Is it really good to let this happen?
|
236
|
$this->assertEqual($classes['html']['remove'], array('class3'), 'class3 in remove set');
|
237
|
}
|
238
|
|
239
|
}
|