1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
class CtoolsContextKeywordsSubstitutionTestCase extends DrupalWebTestCase {
|
4 |
|
|
public static function getInfo() {
|
5 |
|
|
return array(
|
6 |
|
|
'name' => 'Keywords substitution',
|
7 |
|
|
'description' => 'Verify that keywords are properly replaced with data.',
|
8 |
1e39edcb
|
Assos Assos
|
'group' => 'ctools',
|
9 |
85ad3d82
|
Assos Assos
|
);
|
10 |
|
|
}
|
11 |
|
|
|
12 |
|
|
public function setUp() {
|
13 |
|
|
parent::setUp('ctools');
|
14 |
|
|
|
15 |
|
|
ctools_include('context');
|
16 |
|
|
}
|
17 |
|
|
|
18 |
|
|
public function testKeywordsSubstitution() {
|
19 |
|
|
// Create node context for substitution.
|
20 |
|
|
$node = $this->drupalCreateNode();
|
21 |
|
|
$context = ctools_context_create('node', $node);
|
22 |
|
|
$contexts = array('argument_1' => $context);
|
23 |
|
|
|
24 |
|
|
// Run tests on some edge cases.
|
25 |
|
|
$checks = array(
|
26 |
|
|
'%node:changed:raw:' => array(
|
27 |
|
|
"{$node->changed}:",
|
28 |
|
|
t('Multi-level token has been replaced. Colon left untouched.'),
|
29 |
|
|
),
|
30 |
|
|
'%node:title' => array(
|
31 |
|
|
"{$node->title}",
|
32 |
|
|
t('Keyword and converter have been replaced.'),
|
33 |
|
|
),
|
34 |
|
|
'%%node:title' => array(
|
35 |
|
|
"%node:title",
|
36 |
|
|
t('Keyword after escaped percent sign left untouched.'),
|
37 |
|
|
),
|
38 |
|
|
'%node:title%node:nid' => array(
|
39 |
|
|
"{$node->title}{$node->nid}",
|
40 |
|
|
t('Multiple substitutions have been replaced.'),
|
41 |
|
|
),
|
42 |
|
|
'%node:title:' => array(
|
43 |
|
|
"{$node->title}:",
|
44 |
|
|
t('Colon after keyword and converter left untouched.'),
|
45 |
|
|
),
|
46 |
|
|
'%node:title%%' => array(
|
47 |
|
|
"{$node->title}%",
|
48 |
|
|
t('Escaped percent sign after keyword and converter left untouched.'),
|
49 |
|
|
),
|
50 |
|
|
'%%%node:title' => array(
|
51 |
|
|
"%{$node->title}",
|
52 |
|
|
t('Keyword after escaped and unescaped percent sign has been replaced.'),
|
53 |
|
|
),
|
54 |
1e39edcb
|
Assos Assos
|
'%%foo:bar' => array(
|
55 |
|
|
"%foo:bar",
|
56 |
|
|
t('Non-existant context ignored.'),
|
57 |
|
|
),
|
58 |
|
|
'There was about 20%-30% difference in price.' => array(
|
59 |
|
|
'There was about 20%-30% difference in price.',
|
60 |
|
|
t('Non-keyword percent sign left untouched.'),
|
61 |
|
|
),
|
62 |
|
|
'href="my%20file%2dname.pdf"' => array(
|
63 |
|
|
'href="my%20file%2dname.pdf"',
|
64 |
|
|
t('HTTP URL escape left untouched.'),
|
65 |
|
|
),
|
66 |
|
|
'href="my%a0file%fdname.pdf"' => array(
|
67 |
|
|
'href="my%a0file%fdname.pdf"',
|
68 |
|
|
t('HTTP URL escape (high-chars) left untouched.'),
|
69 |
|
|
),
|
70 |
|
|
'<a href="http://www.example.com/here%20is%20a%20pdf.pdf">Click here!</a>' => array(
|
71 |
|
|
'<a href="http://www.example.com/here%20is%20a%20pdf.pdf">Click here!</a>',
|
72 |
|
|
t('HTTP URL escape percent sign left untouched in HTML.'),
|
73 |
|
|
),
|
74 |
|
|
'SELECT * FROM {table} WHERE field = "%s"' => array(
|
75 |
|
|
'SELECT * FROM {table} WHERE field = "%s"',
|
76 |
|
|
t('SQL percent sign left untouched.'),
|
77 |
|
|
),
|
78 |
85ad3d82
|
Assos Assos
|
);
|
79 |
|
|
foreach ($checks as $string => $expectations) {
|
80 |
|
|
list($expected_result, $message) = $expectations;
|
81 |
|
|
$actual_result = ctools_context_keyword_substitute($string, array(), $contexts);
|
82 |
|
|
$this->assertEqual($actual_result, $expected_result, $message);
|
83 |
|
|
}
|
84 |
|
|
}
|
85 |
|
|
|
86 |
|
|
} |