summaryrefslogtreecommitdiff
path: root/modules/simpletest/tests/theme.test
blob: f63b51571bee75a59db9e2f5a8ace3e47814f4f0 (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
<?php
// $Id$

/**
 * @file
 * Tests for the theme API.
 */

/**
 * Unit tests for the theme API.
 */
class TemplateUnitTest extends DrupalWebTestCase {
  function getInfo() {
    return array(
      'name' => t('Theme API'),
      'description' => t('Test low-level theme template functions.'),
      'group' => t('Theme'),
    );
  }

  /**
   * Test function template_page_suggestions() for SA-CORE-2009-003.
   */
  function testTemplateSuggestions() {
    // Set the front page as something random otherwise the CLI
    // test runner fails.
    variable_set('site_frontpage', 'nobody-home');
    $args = array('node', '1', 'edit');
    $suggestions = template_page_suggestions($args);
    $this->assertEqual($suggestions, array('page-node', 'page-node-1', 'page-node-edit'), t('Found expected node edit page template suggestions'));
    // Check attack vectors.
    $args = array('node', '\\1');
    $suggestions = template_page_suggestions($args);
    $this->assertEqual($suggestions, array('page-node', 'page-node-1'), t('Removed invalid \\ from template suggestions'));
    $args = array('node', '1/');
    $suggestions = template_page_suggestions($args);
    $this->assertEqual($suggestions, array('page-node', 'page-node-1'), t('Removed invalid / from template suggestions'));
    $args = array('node', "1\0");
    $suggestions = template_page_suggestions($args);
    $this->assertEqual($suggestions, array('page-node', 'page-node-1'), t('Removed invalid \\0 from template suggestions'));
    // Tests for drupal_discover_template()
    $suggestions = array('page');
    $this->assertEqual(drupal_discover_template(array('themes/garland'), $suggestions), 'themes/garland/page.tpl.php', t('Safe template discovered'));
    $suggestions = array('page');
    $this->assertEqual(drupal_discover_template(array('themes/garland'), $suggestions, '\\.tpl.php'), 'themes/garland/page.tpl.php', t('Unsafe extension fixed'));
    $suggestions = array('page\\');
    $this->assertEqual(drupal_discover_template(array('themes/garland'), $suggestions), 'themes/garland/page.tpl.php', t('Unsafe template suggestion fixed'));
    $suggestions = array('page/');
    $this->assertEqual(drupal_discover_template(array('themes/garland'), $suggestions), 'themes/garland/page.tpl.php', t('Unsafe template suggestion fixed'));
    $suggestions = array("page\0");
    $this->assertEqual(drupal_discover_template(array('themes/garland'), $suggestions), 'themes/garland/page.tpl.php', t('Unsafe template suggestion fixed'));
  }

}