function ThemeTestCase::testThemeSuggestions
Test function theme_get_suggestions() for SA-CORE-2009-003.
File
-
modules/
simpletest/ tests/ theme.test, line 30
Class
- ThemeTestCase
- Unit tests for the Theme API.
Code
function testThemeSuggestions() {
// 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 = theme_get_suggestions($args, 'page');
$this->assertEqual($suggestions, array(
'page__node',
'page__node__%',
'page__node__1',
'page__node__edit',
), 'Found expected node edit page suggestions');
// Check attack vectors.
$args = array(
'node',
'\\1',
);
$suggestions = theme_get_suggestions($args, 'page');
$this->assertEqual($suggestions, array(
'page__node',
'page__node__%',
'page__node__1',
), 'Removed invalid \\ from suggestions');
$args = array(
'node',
'1/',
);
$suggestions = theme_get_suggestions($args, 'page');
$this->assertEqual($suggestions, array(
'page__node',
'page__node__%',
'page__node__1',
), 'Removed invalid / from suggestions');
$args = array(
'node',
"1\x00",
);
$suggestions = theme_get_suggestions($args, 'page');
$this->assertEqual($suggestions, array(
'page__node',
'page__node__%',
'page__node__1',
), 'Removed invalid \\0 from suggestions');
// Define path with hyphens to be used to generate suggestions.
$args = array(
'node',
'1',
'hyphen-path',
);
$result = array(
'page__node',
'page__node__%',
'page__node__1',
'page__node__hyphen_path',
);
$suggestions = theme_get_suggestions($args, 'page');
$this->assertEqual($suggestions, $result, 'Found expected page suggestions for paths containing hyphens.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.