2009-04-15 20:45:46 +00:00
|
|
|
<?php
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Tests for the theme API.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2009-06-09 21:53:26 +00:00
|
|
|
* Unit tests for the Theme API.
|
2009-04-15 20:45:46 +00:00
|
|
|
*/
|
|
|
|
class TemplateUnitTest extends DrupalWebTestCase {
|
2009-05-06 19:56:21 +00:00
|
|
|
public static function getInfo() {
|
2009-04-15 20:45:46 +00:00
|
|
|
return array(
|
2009-07-13 21:51:42 +00:00
|
|
|
'name' => 'Theme API',
|
|
|
|
'description' => 'Test low-level theme template functions.',
|
|
|
|
'group' => 'Theme',
|
2009-04-15 20:45:46 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-01-13 05:40:03 +00:00
|
|
|
* Test function theme_get_suggestions() for SA-CORE-2009-003.
|
2009-04-15 20:45:46 +00:00
|
|
|
*/
|
2010-01-13 05:40:03 +00:00
|
|
|
function testThemeSuggestions() {
|
2009-04-15 20:45:46 +00:00
|
|
|
// Set the front page as something random otherwise the CLI
|
|
|
|
// test runner fails.
|
|
|
|
variable_set('site_frontpage', 'nobody-home');
|
|
|
|
$args = array('node', '1', 'edit');
|
2010-01-13 05:40:03 +00:00
|
|
|
$suggestions = theme_get_suggestions($args, 'page');
|
|
|
|
$this->assertEqual($suggestions, array('page__node', 'page__node__%', 'page__node__1', 'page__node__edit'), t('Found expected node edit page suggestions'));
|
2009-04-15 20:45:46 +00:00
|
|
|
// Check attack vectors.
|
|
|
|
$args = array('node', '\\1');
|
2010-01-13 05:40:03 +00:00
|
|
|
$suggestions = theme_get_suggestions($args, 'page');
|
|
|
|
$this->assertEqual($suggestions, array('page__node', 'page__node__%', 'page__node__1'), t('Removed invalid \\ from suggestions'));
|
2009-04-15 20:45:46 +00:00
|
|
|
$args = array('node', '1/');
|
2010-01-13 05:40:03 +00:00
|
|
|
$suggestions = theme_get_suggestions($args, 'page');
|
|
|
|
$this->assertEqual($suggestions, array('page__node', 'page__node__%', 'page__node__1'), t('Removed invalid / from suggestions'));
|
2009-04-15 20:45:46 +00:00
|
|
|
$args = array('node', "1\0");
|
2010-01-13 05:40:03 +00:00
|
|
|
$suggestions = theme_get_suggestions($args, 'page');
|
|
|
|
$this->assertEqual($suggestions, array('page__node', 'page__node__%', 'page__node__1'), t('Removed invalid \\0 from suggestions'));
|
2009-04-15 20:45:46 +00:00
|
|
|
}
|
2010-02-23 18:32:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensure page-front template suggestion is added when on front page.
|
|
|
|
*/
|
|
|
|
function testFrontPageThemeSuggestion() {
|
|
|
|
$q = $_GET['q'];
|
|
|
|
// Set $_GET['q'] to node because theme_get_suggestions() will query it to
|
|
|
|
// see if we are on the front page.
|
|
|
|
$_GET['q'] = variable_get('site_frontpage', 'node');
|
|
|
|
$suggestions = theme_get_suggestions(explode('/', $_GET['q']), 'page');
|
|
|
|
// Set it back to not annoy the batch runner.
|
|
|
|
$_GET['q'] = $q;
|
|
|
|
$this->assertTrue(in_array('page__front', $suggestions), t('Front page template was suggested.'));
|
|
|
|
}
|
2009-06-09 21:53:26 +00:00
|
|
|
}
|
2009-04-15 20:45:46 +00:00
|
|
|
|
2009-06-09 21:53:26 +00:00
|
|
|
/**
|
|
|
|
* Unit tests for theme_table().
|
|
|
|
*/
|
|
|
|
class ThemeTableUnitTest extends DrupalWebTestCase {
|
|
|
|
public static function getInfo() {
|
|
|
|
return array(
|
2009-07-13 21:51:42 +00:00
|
|
|
'name' => 'Theme Table',
|
|
|
|
'description' => 'Tests built-in theme functions.',
|
|
|
|
'group' => 'Theme',
|
2009-06-09 21:53:26 +00:00
|
|
|
);
|
|
|
|
}
|
2009-10-15 12:27:34 +00:00
|
|
|
|
2009-06-09 21:53:26 +00:00
|
|
|
/**
|
|
|
|
* Tableheader.js provides 'sticky' table headers, and is included by default.
|
|
|
|
*/
|
|
|
|
function testThemeTableStickyHeaders() {
|
|
|
|
$header = array('one', 'two', 'three');
|
|
|
|
$rows = array(array(1,2,3), array(4,5,6), array(7,8,9));
|
2009-10-09 01:00:08 +00:00
|
|
|
$this->content = theme('table', array('header' => $header, 'rows' => $rows));
|
2009-06-09 21:53:26 +00:00
|
|
|
$js = drupal_add_js();
|
|
|
|
$this->assertTrue(isset($js['misc/tableheader.js']), t('tableheader.js was included when $sticky = TRUE.'));
|
|
|
|
$this->assertRaw('sticky-enabled', t('Table has a class of sticky-enabled when $sticky = TRUE.'));
|
|
|
|
drupal_static_reset('drupal_add_js');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If $sticky is FALSE, no tableheader.js should be included.
|
|
|
|
*/
|
|
|
|
function testThemeTableNoStickyHeaders() {
|
|
|
|
$header = array('one', 'two', 'three');
|
|
|
|
$rows = array(array(1,2,3), array(4,5,6), array(7,8,9));
|
|
|
|
$attributes = array();
|
|
|
|
$caption = NULL;
|
|
|
|
$colgroups = array();
|
2009-10-09 01:00:08 +00:00
|
|
|
$this->content = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => $attributes, 'caption' => $caption, 'colgroups' => $colgroups, 'sticky' => FALSE));
|
2009-06-09 21:53:26 +00:00
|
|
|
$js = drupal_add_js();
|
|
|
|
$this->assertFalse(isset($js['misc/tableheader.js']), t('tableheader.js was not included because $sticky = FALSE.'));
|
|
|
|
$this->assertNoRaw('sticky-enabled', t('Table does not have a class of sticky-enabled because $sticky = FALSE.'));
|
|
|
|
drupal_static_reset('drupal_add_js');
|
|
|
|
}
|
2009-04-15 20:45:46 +00:00
|
|
|
}
|
2009-12-28 20:58:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Unit tests for theme_item_list().
|
|
|
|
*/
|
|
|
|
class ThemeItemListUnitTest extends DrupalWebTestCase {
|
|
|
|
public static function getInfo() {
|
|
|
|
return array(
|
|
|
|
'name' => 'Theme item list',
|
|
|
|
'description' => 'Test the theme_item_list() function.',
|
|
|
|
'group' => 'Theme',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test nested list rendering.
|
|
|
|
*/
|
|
|
|
function testNestedList() {
|
|
|
|
$items = array('a', array('data' => 'b', 'children' => array('c', 'd')), 'e');
|
|
|
|
$expected = '<div class="item-list"><ul><li class="first">a</li>
|
|
|
|
<li>b<div class="item-list"><ul><li class="first">c</li>
|
|
|
|
<li class="last">d</li>
|
|
|
|
</ul></div></li>
|
|
|
|
<li class="last">e</li>
|
|
|
|
</ul></div>';
|
|
|
|
$output = theme('item_list', array('items' => $items, 'type' => 'ul', 'title' => NULL, 'attributes' => array()));
|
|
|
|
$this->assertIdentical($expected, $output, 'Nested list is rendered correctly.');
|
|
|
|
}
|
|
|
|
}
|