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