summaryrefslogtreecommitdiff
path: root/kolab.org/www/drupal-7.15/sites/all/modules/ctools/tests/context.test
blob: b5f6fb10a16074c8a36e18c538eca29e0d71d9b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php

class CtoolsContextKeywordsSubstitutionTestCase extends DrupalWebTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Keywords substitution',
      'description' => 'Verify that keywords are properly replaced with data.',
      'group' => 'Chaos Tools Suite',
    );
  }

  public function setUp() {
    parent::setUp('ctools');

    ctools_include('context');
  }

  public function testKeywordsSubstitution() {
    // Create node context for substitution.
    $node = $this->drupalCreateNode();
    $context = ctools_context_create('node', $node);
    $contexts = array('argument_1' => $context);

    // Run tests on some edge cases.
    $checks = array(
      '%node:title' => array(
        "{$node->title}",
        t('Keyword and converter have been replaced.'),
      ),
      '%%node:title' => array(
        "%node:title",
        t('Keyword after escaped percent sign left untouched.'),
      ),
      '%node:title%node:nid' => array(
        "{$node->title}{$node->nid}",
        t('Multiple substitutions have been replaced.'),
      ),
      '%node:title:' => array(
        "{$node->title}:",
        t('Colon after keyword and converter left untouched.'),
      ),
      '%node:title%%' => array(
        "{$node->title}%",
        t('Escaped percent sign after keyword and converter left untouched.'),
      ),
      '%%%node:title' => array(
        "%{$node->title}",
        t('Keyword after escaped and unescaped percent sign has been replaced.'),
      ),
    );
    foreach ($checks as $string => $expectations) {
      list($expected_result, $message) = $expectations;
      $actual_result = ctools_context_keyword_substitute($string, array(), $contexts);
      $this->assertEqual($actual_result, $expected_result, $message);
    }
  }

}