comparison sites/all/modules/ctools/tests/context.test @ 0:ff03f76ab3fe

initial version
author danieleb <danielebarchiesi@me.com>
date Wed, 21 Aug 2013 18:51:11 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:ff03f76ab3fe
1 <?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 'group' => 'Chaos Tools Suite',
9 );
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 );
55 foreach ($checks as $string => $expectations) {
56 list($expected_result, $message) = $expectations;
57 $actual_result = ctools_context_keyword_substitute($string, array(), $contexts);
58 $this->assertEqual($actual_result, $expected_result, $message);
59 }
60 }
61
62 }