- <?php
- * @file
- * Tests for the theme API.
- */
-
- * Unit tests for the Theme API.
- */
- class ThemeUnitTest extends BackdropWebTestCase {
- protected $profile = 'testing';
-
- function setUp() {
- parent::setUp('theme_test');
- theme_enable(array('test_theme'));
- }
-
-
- * Test function theme_get_suggestions() for SA-CORE-2009-003.
- */
- function testThemeSuggestions() {
-
-
- config_set('system.core', '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');
-
- $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\0");
- $suggestions = theme_get_suggestions($args, 'page');
- $this->assertEqual($suggestions, array('page__node', 'page__node__%', 'page__node__1'), 'Removed invalid \\0 from 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.');
- }
-
-
- * Ensures preprocess functions run even for suggestion implementations.
- *
- * The theme hook used by this test has its base preprocess function in a
- * separate file, so this test also ensures that that file is correctly loaded
- * when needed.
- */
- function testPreprocessForSuggestions() {
-
- backdrop_theme_rebuild();
- for ($i = 0; $i < 2; $i++) {
- $this->backdropGet('theme-test/suggestion');
- $this->assertText('Theme hook implementor=test_theme_theme_test__suggestion(). Foo=template_preprocess_theme_test', 'Theme hook suggestion ran with data available from a preprocess function for the base hook.');
- }
- }
-
-
- * Ensure page-front template suggestion is added when on home page.
- */
- function testFrontPageThemeSuggestion() {
- $q = $_GET['q'];
-
-
- config_set('system.core', 'site_frontpage', 'node');
- $_GET['q'] = 'node';
- $suggestions = theme_get_suggestions(explode('/', $_GET['q']), 'page');
-
- $_GET['q'] = $q;
- $this->assertTrue(in_array('page__front', $suggestions), 'Home page template was suggested.');
- }
-
-
- * Ensures theme hook_*_alter() implementations can run before anything is rendered.
- */
- function testAlter() {
- $this->backdropGet('theme-test/alter');
- $this->assertText('The altered data is test_theme_theme_test_alter_alter was invoked.', 'The theme was able to implement an alter hook during page building before anything was rendered.');
- }
-
-
- * Ensures a theme's .info file is able to override a module CSS file from being added to the page.
- *
- * @see test_theme.info
- */
- function testCSSOverride() {
-
-
-
-
- config_set('system.core', 'preprocess_css', 0);
- $this->backdropGet('theme-test/suggestion');
- $this->assertNoText('modules/system/css/system.css', "The theme's .info file is able to override a module CSS file from being added to the page.");
-
-
-
-
- config_set('system.core', 'preprocess_css', 1);
- $this->backdropGet('theme-test/suggestion');
- config_set('system.core', 'preprocess_css', 0);
- }
-
-
- * Ensures a themes template is overrideable based on the 'template' filename.
- */
- function testTemplateOverride() {
- config_set('system.core', 'theme_default', 'test_theme');
- $this->backdropGet('theme-test/template-test');
- $this->assertText('Success: Template overridden.', t('Template overridden by defined \'template\' filename.'));
- }
-
-
- * Test the list_themes() function.
- */
- function testListThemes() {
- $themes = list_themes();
-
- $this->assertTrue(backdrop_theme_access('test_theme'), 'Enabled theme detected');
-
- $this->assertTrue(array_key_exists('test_basetheme', $themes), 'Disabled theme detected');
-
- $base_theme_list = array('test_basetheme' => 'Theme test base theme');
- $sub_theme_list = array('test_subtheme' => 'Theme test subtheme');
- $this->assertIdentical($themes['test_basetheme']->sub_themes, $sub_theme_list, 'Base theme\'s object includes list of subthemes.');
- $this->assertIdentical($themes['test_subtheme']->base_themes, $base_theme_list, 'Subtheme\'s object includes list of base themes.');
-
- $this->assertIdentical($themes['test_subtheme']->engine, 'phptemplate', 'Subtheme\'s object includes the theme engine.');
-
- $this->assertIdentical($themes['test_basetheme']->prefix, 'phptemplate', 'Base theme\'s object includes the theme engine prefix.');
- $this->assertIdentical($themes['test_subtheme']->prefix, 'phptemplate', 'Subtheme\'s object includes the theme engine prefix.');
- }
-
-
- * Test the theme_get_setting() function.
- */
- function testThemeGetSetting() {
- $GLOBALS['theme_key'] = 'test_theme';
- $this->assertIdentical(theme_get_setting('theme_test_setting'), 'default value', 'theme_get_setting() uses the default theme automatically.');
- $this->assertNotEqual(theme_get_setting('subtheme_override', 'test_basetheme'), theme_get_setting('subtheme_override', 'test_subtheme'), 'Base theme\'s default settings values can be overridden by subtheme.');
- $this->assertIdentical(theme_get_setting('basetheme_only', 'test_subtheme'), 'base theme value', 'Base theme\'s default settings values are inherited by subtheme.');
- }
-
-
- * Ensures the theme registry is rebuilt when modules are disabled/enabled.
- */
- function testRegistryRebuild() {
- $this->assertIdentical(theme('theme_test_foo', array('foo' => 'a')), 'a', 'The theme registry contains theme_test_foo.');
-
- module_disable(array('theme_test'), FALSE);
- $this->assertIdentical(theme('theme_test_foo', array('foo' => 'b')), '', 'The theme registry does not contain theme_test_foo, because the module is disabled.');
-
- module_enable(array('theme_test'), FALSE);
- $this->assertIdentical(theme('theme_test_foo', array('foo' => 'c')), 'c', 'The theme registry contains theme_test_foo again after re-enabling the module.');
- }
- }
-
- * Unit tests for theme_table().
- */
- class ThemeTableUnitTest extends BackdropWebTestCase {
-
- * 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));
- $this->content = theme('table', array('header' => $header, 'rows' => $rows));
- $js = backdrop_add_js();
- $this->assertTrue(isset($js['core/misc/tableheader.js']), 'tableheader.js was included when $sticky = TRUE.');
- $this->assertRaw('sticky-enabled', 'Table has a class of sticky-enabled when $sticky = TRUE.');
- backdrop_static_reset('backdrop_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();
- $this->content = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => $attributes, 'caption' => $caption, 'colgroups' => $colgroups, 'sticky' => FALSE));
- $js = backdrop_add_js();
- $this->assertFalse(isset($js['core/misc/tableheader.js']), 'tableheader.js was not included because $sticky = FALSE.');
- $this->assertNoRaw('sticky-enabled', 'Table does not have a class of sticky-enabled because $sticky = FALSE.');
- backdrop_static_reset('backdrop_add_js');
- }
-
-
- * Tests that the table header is printed correctly even if there are no rows,
- * and that the empty text is displayed correctly.
- */
- function testThemeTableWithEmptyMessage() {
- $header = array(
- t('Header 1'),
- array(
- 'data' => t('Header 2'),
- 'colspan' => 2,
- ),
- );
- $this->content = theme('table', array('header' => $header, 'rows' => array(), 'empty' => t('No strings available.')));
- $this->assertRaw('<tr class="odd"><td colspan="3" class="empty message">No strings available.</td>', 'Correct colspan was set on empty message.');
- $this->assertRaw('<thead><tr><th>Header 1</th>', 'Table header was printed.');
- }
-
-
- * Tests that the 'no_striping' option works correctly.
- */
- function testThemeTableWithNoStriping() {
- $rows = array(
- array(
- 'data' => array(1),
- 'no_striping' => TRUE,
- ),
- );
- $this->content = theme('table', array('rows' => $rows));
- $this->assertNoRaw('class="odd"', 'Odd/even classes were not added because $no_striping = TRUE.');
- $this->assertNoRaw('no_striping', 'No invalid no_striping HTML attribute was printed.');
- }
-
-
- * Tests that the 'footer' option works correctly.
- */
- protected function testThemeTableFooter() {
- $footer = array(
- array(
- 'data' => array(1),
- ),
- array('Foo'),
- );
-
- $table = array(
- 'rows' => array(),
- 'footer' => $footer,
- );
-
- $this->content = theme('table', $table);
- $this->content = preg_replace('@>\s+<@', '><', $this->content);
- $this->assertRaw('<tfoot><tr><td>1</td></tr><tr><td>Foo</td></tr></tfoot>', 'Table footer found.');
- }
-
- }
-
- * Tests for common theme functions.
- */
- class ThemeFunctionsTestCase extends BackdropWebTestCase {
- protected $profile = 'testing';
-
-
- * Tests theme_item_list().
- */
- function testItemList() {
-
- $variables = array();
- $expected = '';
- $this->assertThemeOutput('item_list', $variables, $expected, 'Empty %callback generates no output.');
-
- $variables = array();
- $variables['title'] = 'Some title';
- $expected = '';
- $this->assertThemeOutput('item_list', $variables, $expected, 'Empty %callback with title generates no output.');
-
-
- $variables = array();
- $variables['empty'] = 'No items found.';
- $expected = '<div class="item-list">No items found.</div>';
- $this->assertThemeOutput('item_list', $variables, $expected, 'Empty %callback generates empty string.');
-
- $variables = array();
- $variables['title'] = 'Some title';
- $variables['empty'] = 'No items found.';
- $expected = '<div class="item-list"><h3>Some title</h3>No items found.</div>';
- $this->assertThemeOutput('item_list', $variables, $expected, 'Empty %callback generates empty string with title.');
-
-
- $attribute_name = $this->randomName();
- $attribute_value = $this->randomName();
- $another_css_class = $this->randomName();
- $variables = array();
- $variables['empty'] = 'No items found.';
- $variables['wrapper_attributes'] = array(
- $attribute_name => $attribute_value,
- 'class' => array($another_css_class),
- );
- $expected = '<div ' . $attribute_name . '="' . $attribute_value . '" class="' . $another_css_class . ' item-list">No items found.</div>';
- $this->assertThemeOutput('item_list', $variables, $expected, 'Additional attributes added to the wrapper div.');
-
-
- $variables = array();
- $variables['title'] = 'Some title';
- $variables['attributes'] = array(
- 'id' => 'parent-list',
- );
- $variables['items'] = array(
- 'a',
- array(
- 'data' => 'b',
- 'children' => array(
- 'c',
-
- array(
- 'data' => 'd',
- 'class' => array('dee'),
- ),
-
- 'id' => 'child-list',
- ),
-
- 'id' => 'bee',
- ),
- array(
- 'data' => 'e',
- 'id' => 'E',
- ),
- );
- $inner = '<div class="item-list"><ul id="child-list">';
- $inner .= '<li class="odd first">c</li>';
- $inner .= '<li class="dee even last">d</li>';
- $inner .= '</ul></div>';
-
- $expected = '<div class="item-list">';
- $expected .= '<h3>Some title</h3>';
- $expected .= '<ul id="parent-list">';
- $expected .= '<li class="odd first">a</li>';
- $expected .= '<li id="bee" class="even">b' . $inner . '</li>';
- $expected .= '<li id="E" class="odd last">e</li>';
- $expected .= '</ul></div>';
-
- $this->assertThemeOutput('item_list', $variables, $expected);
- }
-
-
- * Tests theme_links().
- */
- function testLinks() {
-
- $variables = array();
- $expected = '';
- $this->assertThemeOutput('links', $variables, $expected, 'Empty %callback generates no output.');
-
- $variables = array();
- $variables['heading'] = 'Some title';
- $expected = '';
- $this->assertThemeOutput('links', $variables, $expected, 'Empty %callback with heading generates no output.');
-
-
-
-
-
- $_GET['q'] = config_get('system.core', 'site_frontpage');
-
-
- $variables = array();
- $variables['attributes'] = array('id' => 'some-links');
- $variables['links'] = array(
- 'a link' => array(
- 'title' => 'A <link>',
- 'href' => 'a/link',
- ),
- 'plain text' => array(
- 'title' => 'Plain "text"',
- ),
- 'front page' => array(
- 'title' => 'Home page',
- 'href' => '<front>',
- ),
- );
-
- $expected_links = '';
- $expected_links .= '<ul id="some-links">';
- $expected_links .= '<li class="a-link odd first"><a href="' . url('a/link') . '">' . check_plain('A <link>') . '</a></li>';
- $expected_links .= '<li class="plain-text even"><span>' . check_plain('Plain "text"') . '</span></li>';
- $expected_links .= '<li class="front-page odd last active"><a href="' . url('<front>') . '" class="active" aria-current="page">' . check_plain('Home page') . '</a></li>';
- $expected_links .= '</ul>';
-
-
- $variables['heading'] = 'Links heading';
- $expected_heading = '<h2>Links heading</h2>';
- $expected = $expected_heading . $expected_links;
- $this->assertThemeOutput('links', $variables, $expected);
-
-
- $variables['heading'] = array('text' => 'Links heading', 'level' => 'h3', 'class' => 'heading');
- $expected_heading = '<h3 class="heading">Links heading</h3>';
- $expected = $expected_heading . $expected_links;
- $this->assertThemeOutput('links', $variables, $expected);
-
-
- $variables['heading'] = array('text' => 'Links heading', 'level' => 'h3', 'attributes' => array('id' => 'heading'));
- $expected_heading = '<h3 id="heading">Links heading</h3>';
- $expected = $expected_heading . $expected_links;
- $this->assertThemeOutput('links', $variables, $expected);
- }
-
-
- * Asserts themed output.
- *
- * @param $callback
- * The name of the theme function to invoke; e.g. 'links' for theme_links().
- * @param $variables
- * An array of variables to pass to the theme function.
- * @param $expected
- * The expected themed output string.
- * @param $message
- * (optional) An assertion message.
- */
- protected function assertThemeOutput($callback, array $variables = array(), $expected = '', $message = '', $group = 'Other') {
- $output = theme($callback, $variables);
- $this->verbose('Variables:<pre>' . check_plain(var_export($variables, TRUE)) . '</pre>'
- . '<hr />Result:<pre>' . check_plain(var_export($output, TRUE)) . '</pre>'
- . '<hr />Expected:<pre>' . check_plain(var_export($expected, TRUE)) . '</pre>'
- . '<hr />' . $output
- );
- if (!$message) {
- $message = '%callback rendered correctly.';
- }
- $message = t($message, array('%callback' => 'theme_' . $callback . '()'));
- $this->assertIdentical($output, $expected, $message);
- }
-
-
- * Test the use of backdrop_pre_render_links() on a nested array of links.
- */
- function testBackdropPreRenderLinks() {
-
-
- $base_array = array(
- '#theme' => 'links',
- '#pre_render' => array('backdrop_pre_render_links'),
- '#links' => array(
- 'parent_link' => array(
- 'title' => 'Parent link original',
- 'href' => 'parent-link-original',
- ),
- ),
- 'first_child' => array(
- '#theme' => 'links',
- '#links' => array(
-
-
-
- 'parent_link' => array(
- 'title' => 'Parent link copy',
- 'href' => 'parent-link-copy',
- ),
-
- 'first_child_link' => array(
- 'title' => 'First child link',
- 'href' => 'first-child-link',
- ),
- ),
- ),
-
- 'second_child' => array(
- '#theme' => 'links',
- '#links' => array(
- 'second_child_link' => array(
- 'title' => 'Second child link',
- 'href' => 'second-child-link',
- ),
- ),
- ),
-
-
- 'third_child' => array(
- '#theme' => 'links',
- '#links' => array(
- 'third_child_link' => array(
- 'title' => 'Third child link',
- 'href' => 'third-child-link',
- ),
- ),
- '#access' => FALSE,
- ),
- );
-
-
-
-
- $render_array = $base_array;
- $html = backdrop_render($render_array);
- $dom = new DOMDocument();
- $dom->loadHTML($html);
- $this->assertEqual($dom->getElementsByTagName('ul')->length, 1, 'One "ul" tag found in the rendered HTML.');
- $list_elements = $dom->getElementsByTagName('li');
- $this->assertEqual($list_elements->length, 3, 'Three "li" tags found in the rendered HTML.');
- $this->assertEqual($list_elements->item(0)->nodeValue, 'Parent link original', 'First expected link found.');
- $this->assertEqual($list_elements->item(1)->nodeValue, 'First child link', 'Second expected link found.');
- $this->assertEqual($list_elements->item(2)->nodeValue, 'Second child link', 'Third expected link found.');
- $this->assertIdentical(strpos($html, 'Parent link copy'), FALSE, '"Parent link copy" link not found.');
- $this->assertIdentical(strpos($html, 'Third child link'), FALSE, '"Third child link" link not found.');
-
-
-
-
- $render_array = $base_array;
- $child_html = backdrop_render($render_array['first_child']);
- $parent_html = backdrop_render($render_array);
-
- $dom = new DOMDocument();
- $dom->loadHTML($child_html);
- $this->assertEqual($dom->getElementsByTagName('ul')->length, 1, 'One "ul" tag found in the rendered child HTML.');
- $list_elements = $dom->getElementsByTagName('li');
- $this->assertEqual($list_elements->length, 2, 'Two "li" tags found in the rendered child HTML.');
- $this->assertEqual($list_elements->item(0)->nodeValue, 'Parent link copy', 'First expected link found.');
- $this->assertEqual($list_elements->item(1)->nodeValue, 'First child link', 'Second expected link found.');
-
- $dom = new DOMDocument();
- $dom->loadHTML($parent_html);
- $this->assertEqual($dom->getElementsByTagName('ul')->length, 1, 'One "ul" tag found in the rendered parent HTML.');
- $list_elements = $dom->getElementsByTagName('li');
- $this->assertEqual($list_elements->length, 2, 'Two "li" tags found in the rendered parent HTML.');
- $this->assertEqual($list_elements->item(0)->nodeValue, 'Parent link original', 'First expected link found.');
- $this->assertEqual($list_elements->item(1)->nodeValue, 'Second child link', 'Second expected link found.');
- $this->assertIdentical(strpos($parent_html, 'First child link'), FALSE, '"First child link" link not found.');
- $this->assertIdentical(strpos($parent_html, 'Third child link'), FALSE, '"Third child link" link not found.');
- }
- }
-
- * Functional test for initialization of the theme system in hook_init().
- */
- class ThemeHookInitUnitTest extends BackdropWebTestCase {
- protected $profile = 'testing';
-
- function setUp() {
- parent::setUp('theme_test');
- }
-
-
- * Test that the theme system can generate output when called by hook_init().
- */
- function testThemeInitializationHookInit() {
- $this->backdropGet('theme-test/hook-init');
- $this->assertRaw('Themed output generated in hook_init()', 'Themed output generated in hook_init() correctly appears on the page.');
- $this->assertRaw('stark/layout.css', "The default theme's CSS appears on the page when the theme system is initialized in hook_init().");
- }
- }
-
- * Tests autocompletion not loading registry.
- */
- class ThemeFastTestCase extends BackdropWebTestCase {
-
-
- * @var User
- */
- protected $account;
-
- function setUp() {
- parent::setUp('theme_test');
- $this->account = $this->backdropCreateUser(array('access user profiles'));
- }
-
-
- * Tests access to user autocompletion and verify the correct results.
- */
- function testUserAutocomplete() {
- $this->backdropLogin($this->account);
- $this->backdropGet('user/autocomplete/' . $this->account->name);
- $this->assertText('registry not initialized', 'The registry was not initialized');
- }
- }
-
- * Unit tests for meta tags.
- */
- class ThemeHeadTag extends BackdropUnitTestCase {
-
- * Test function theme_head_tag()
- */
- function testThemeHeadTag() {
-
- $tag['element'] = array('#tag' => 'meta', '#attributes' => array('name' => 'description', 'content' => 'Backdrop test'));
- $this->assertEqual('<meta name="description" content="Backdrop test" />'."\n", theme_head_tag($tag), 'Test auto-closure meta tag generation.');
-
-
- $tag['element'] = array('#tag' => 'title', '#value' => 'title test');
- $this->assertEqual('<title>title test</title>'."\n", theme_head_tag($tag), 'Test title tag generation.');
- }
- }
-
- * Tests the markup of core render element types passed to backdrop_render().
- */
- class RenderElementTypesTestCase extends BackdropWebTestCase {
-
- * Asserts that an array of elements is rendered properly.
- *
- * @param array $elements
- * An array of associative arrays describing render elements and their
- * expected markup. Each item in $elements must contain the following:
- * - 'name': This human readable description will be displayed on the test
- * results page.
- * - 'value': This is the render element to test.
- * - 'expected': This is the expected markup for the element in 'value'.
- */
- function assertElements($elements) {
- foreach($elements as $element) {
- $this->assertIdentical(backdrop_render($element['value']), $element['expected'], '"' . $element['name'] . '" input rendered correctly by backdrop_render().');
- }
- }
-
-
- * Tests Form API #type 'container'.
- */
- function testContainer() {
- $elements = array(
-
- array(
- 'name' => "#type 'container' with no HTML attributes",
- 'value' => array(
- '#type' => 'container',
- 'child' => array(
- '#markup' => 'foo',
- ),
- ),
- 'expected' => '<div>foo</div>',
- ),
-
- array(
- 'name' => "#type 'container' with a class HTML attribute",
- 'value' => array(
- '#type' => 'container',
- 'child' => array(
- '#markup' => 'foo',
- ),
- '#attributes' => array(
- 'class' => 'bar',
- ),
- ),
- 'expected' => '<div class="bar">foo</div>',
- ),
- );
-
- $this->assertElements($elements);
- }
-
-
- * Tests Form API #type 'details'.
- */
- public function testDetails() {
- $elements = array(
-
- array(
- 'name' => "Basic 'details'",
- 'value' => array(
- '#type' => 'details',
- '#summary' => t('The summary'),
- '#details' => t('Detailed content'),
- ),
- 'expected' => '<details><summary><span>The summary</span></summary><div class="details-content-wrapper">Detailed content</div></details>',
- ),
-
- array(
- 'name' => "Basic 'details' with custom attributes",
- 'value' => array(
- '#type' => 'details',
- '#summary' => t('The summary'),
- '#details' => t('Detailed content'),
- '#attributes' => array(
- 'id' => 'foobar-id',
- 'class' => array('fooclass'),
- ),
- ),
- 'expected' => '<details id="foobar-id" class="fooclass"><summary><span>The summary</span></summary><div class="details-content-wrapper">Detailed content</div></details>',
- ),
-
- array(
- 'name' => "Details with child",
- 'value' => array(
- '#type' => 'details',
- '#summary' => t('The summary'),
- '#open' => TRUE,
- 'child' => array(
- '#markup' => 'foobar',
- ),
- ),
- 'expected' => '<details open="open"><summary><span>The summary</span></summary><div class="details-child-wrapper">foobar</div></details>',
- ),
- );
-
- $this->assertElements($elements);
- }
-
-
- * Tests system #type 'head_tag'.
- */
- function testHeadTag() {
- $elements = array(
-
- array(
- 'name' => "#type 'head_tag' auto-closure meta tag generation",
- 'value' => array(
- '#type' => 'head_tag',
- '#tag' => 'meta',
- '#attributes' => array(
- 'name' => 'description',
- 'content' => 'Backdrop test',
- ),
- ),
- 'expected' => '<meta name="description" content="Backdrop test" />' . "\n",
- ),
-
- array(
- 'name' => "#type 'head_tag' title tag generation",
- 'value' => array(
- '#type' => 'head_tag',
- '#tag' => 'title',
- '#value' => 'title test',
- ),
- 'expected' => '<title>title test</title>' . "\n",
- ),
- );
-
- $this->assertElements($elements);
- }
- }
-
- * Functional test for attributes of html.tpl.php.
- */
- class ThemeHtmlTplPhpAttributesTestCase extends BackdropWebTestCase {
- function setUp() {
- parent::setUp('theme_test');
- }
-
-
- * Tests that modules and themes can alter variables in html.tpl.php.
- */
- function testThemeHtmlTplPhpAttributes() {
- $this->backdropGet('');
- $attributes = $this->xpath('/html[@theme_test_html_attribute="theme test html attribute value"]');
- $this->assertTrue(count($attributes) == 1, t('Attribute set in the html element via hook_preprocess_html() found.'));
- $attributes = $this->xpath('/html/body[@theme_test_body_attribute="theme test body attribute value"]');
- $this->assertTrue(count($attributes) == 1, t('Attribute set in the body element via hook_preprocess_html() found.'));
- }
- }
-
- * Tests for the ThemeRegistry class.
- */
- class ThemeRegistryTestCase extends BackdropWebTestCase {
- protected $profile = 'testing';
- function setUp() {
- parent::setUp('theme_test');
- }
-
-
- * Tests the behavior of the theme registry class.
- */
- function testRaceCondition() {
- $_SERVER['REQUEST_METHOD'] = 'GET';
- $cid = 'test_theme_registry';
-
-
-
- $registry = new ThemeRegistry($cid, 'cache');
-
- $this->assertTrue(cache()->get($cid), 'Cache entry was created.');
-
-
- $this->assertTrue($registry['theme_test_template_test'], 'Offset was returned correctly from the theme registry.');
-
-
-
-
- cache()->delete($cid);
-
-
- unset($registry);
-
- $this->assertTrue(cache()->get($cid), 'Cache entry was created.');
-
-
-
-
- $registry = new ThemeRegistry($cid, 'cache');
- $this->assertTrue($registry['theme_test_template_test'], 'Offset was returned correctly from the theme registry');
- $this->assertTrue($registry['theme_test_template_test_2'], 'Offset was returned correctly from the theme registry');
- }
- }
-
- * Tests for theme_datetime().
- */
- class ThemeDatetime extends BackdropWebTestCase {
- protected $profile = 'testing';
-
-
- * Test function theme_datetime().
- */
- function testThemeDatetime() {
-
- $timestamp = 1421394600;
- $date = format_date($timestamp);
-
-
- $variables = array(
- 'timestamp' => $timestamp,
- );
- $this->assertEqual('<time datetime="2015-01-16T07:50:00+0000">' . $date . '</time>', theme('datetime', $variables));
-
-
- $variables = array(
- 'timestamp' => $timestamp,
- 'text' => "Backdrop's birthday",
- );
- $this->assertEqual('<time datetime="2015-01-16T07:50:00+0000">Backdrop's birthday</time>', theme('datetime', $variables));
-
-
- $variables = array(
- 'attributes' => array(
- 'datetime' => '2015-01-16',
- ),
- );
- $this->assertEqual('<time datetime="2015-01-16">2015-01-16</time>', theme('datetime', $variables));
-
-
- $variables = array(
- 'text' => "Backdrop's birthday",
- 'attributes' => array(
- 'datetime' => '2015-01-16',
- ),
- );
- $this->assertEqual('<time datetime="2015-01-16">Backdrop's birthday</time>', theme('datetime', $variables));
-
-
- $variables = array(
- 'timestamp' => $timestamp,
- 'text' => "<span>Backdrop's birthday</span>",
- 'html' => TRUE,
- );
- $this->assertEqual('<time datetime="2015-01-16T07:50:00+0000"><span>Backdrop\'s birthday</span></time>', theme('datetime', $variables));
- }
- }
-
- * Tests for theme debug markup.
- */
- class ThemeDebugMarkupTestCase extends BackdropWebTestCase {
- protected $profile = 'testing';
- protected $admin_user;
-
- function setUp() {
- parent::setUp('theme_test', 'node', 'taxonomy');
- theme_enable(array('test_theme'));
-
-
- $this->admin_user = $this->backdropCreateUser(array(
- 'access content',
- 'administer nodes',
- 'access user profiles',
- 'administer taxonomy',
- ));
- $this->backdropLogin($this->admin_user);
-
-
- $this->backdropCreateContentType(array('type' => 'page', 'name' => 'Page', 'node_submitted' => TRUE));
- $this->backdropCreateContentType(array('type' => 'post', 'name' => 'Post', 'node_submitted' => TRUE));
-
-
- config_set('system.core', 'cache', '0');
- }
-
-
- * Tests debug node markup added to template output.
- */
- function testDebugNodeOutput() {
- config_set('system.core', 'theme_default', 'test_theme');
-
- config_set('system.core', 'theme_debug', TRUE);
-
- $registry = theme_get_registry();
- $extension = '.tpl.php';
-
- $templates = backdrop_find_theme_templates($registry, $extension, backdrop_get_path('theme', 'test_theme'));
- $templates += backdrop_find_theme_templates($registry, $extension, backdrop_get_path('module', 'node'));
-
-
- $node = $this->backdropCreateNode();
- $this->backdropGet("node/$node->nid");
- $this->assertRaw('<!-- THEME DEBUG -->', 'Theme debug markup found in theme output when debug is enabled.');
- $this->assertRaw("CALL: theme('node')", 'Theme call information found.');
- $debug_output = <<<EOL
- * node--{$node->nid}--full.tpl.php
- x node--{$node->nid}.tpl.php
- * node--page--full.tpl.php
- * node--page.tpl.php
- * node.tpl.php
- EOL;
- $this->assertRaw($debug_output, 'Suggested template files found in order and node ID specific template shown as current template.');
- $template_filename = $templates['node__' . $node->nid]['path'] . '/' . $templates['node__' . $node->nid]['template'] . $extension;
- $this->assertRaw("BEGIN OUTPUT from '$template_filename'", 'Full path to current template file found.');
-
-
-
- $node2 = $this->backdropCreateNode();
- $this->backdropGet("node/$node2->nid");
- $debug_output = <<<EOL
- * node--{$node2->nid}--full.tpl.php
- * node--{$node2->nid}.tpl.php
- * node--page--full.tpl.php
- * node--page.tpl.php
- x node.tpl.php
- EOL;
- $this->assertRaw($debug_output, 'Suggested template files found in order and base template shown as current template.');
-
-
-
- $node3 = $this->backdropCreateNode();
- $build = array('#theme' => 'node__foo__bar');
- $build += node_view($node3);
- $output = backdrop_render($build);
- $this->assertTrue(strpos($output, "CALL: theme('node__foo__bar')") !== FALSE, 'Theme call information found.');
- $debug_output = <<<EOL
- * node--foo--bar.tpl.php
- * node--foo.tpl.php
- * node--{$node3->nid}--full.tpl.php
- * node--{$node3->nid}.tpl.php
- * node--page--full.tpl.php
- * node--page.tpl.php
- x node.tpl.php
- EOL;
- $this->assertTrue(strpos($output, $debug_output) !== FALSE, 'Suggested template files found in order and base template shown as current template.');
-
-
- config_set('system.core', 'theme_debug', FALSE);
-
- $this->backdropGet('node/' . $node->nid);
- $this->assertNoRaw('<!-- THEME DEBUG -->', 'Theme debug markup not found in theme output when debug is disabled.');
- }
-
-
- * Tests debug user markup added to template output.
- */
- function testDebugUserOutput() {
- config_set('system.core', 'theme_default', 'test_theme');
-
- config_set('system.core', 'theme_debug', TRUE);
-
- $registry = theme_get_registry();
- $extension = '.tpl.php';
-
- $templates = backdrop_find_theme_templates($registry, $extension, backdrop_get_path('theme', 'test_theme'));
- $templates += backdrop_find_theme_templates($registry, $extension, backdrop_get_path('module', 'user'));
-
-
- $admin_user = $this->admin_user;
- $this->backdropGet("user/$admin_user->uid");
- $this->assertRaw('<!-- THEME DEBUG -->', 'Theme debug markup found in theme output when debug is enabled.');
- $this->assertRaw("CALL: theme('user_profile')", 'Theme call information found.');
- $debug_output = <<<EOL
- * user-profile--{$admin_user->uid}--full.tpl.php
- x user-profile--{$admin_user->uid}.tpl.php
- * user-profile--full.tpl.php
- * user-profile.tpl.php
- EOL;
- $this->assertRaw($debug_output, 'Suggested template files found in order and user ID specific template shown as current template.');
- $template_filename = $templates['user_profile__' . $admin_user->uid]['path'] . '/' . $templates['user_profile__' . $admin_user->uid]['template'] . $extension;
- $this->assertRaw("BEGIN OUTPUT from '$template_filename'", 'Full path to current template file found.');
-
-
-
- $user2 = $this->backdropCreateUser();
- $this->backdropGet("user/$user2->uid");
- $debug_output = <<<EOL
- * user-profile--{$user2->uid}--full.tpl.php
- * user-profile--{$user2->uid}.tpl.php
- * user-profile--full.tpl.php
- x user-profile.tpl.php
- EOL;
- $this->assertRaw($debug_output, 'Suggested template files found in order and base template shown as current template.');
-
-
-
- $user3 = $this->backdropCreateUser();
- $build = array('#theme' => 'user_profile__foo__bar');
- $build += user_view($user3);
- $output = backdrop_render($build);
- $this->assertTrue(strpos($output, "CALL: theme('user_profile__foo__bar')") !== FALSE, 'Theme call information found.');
- $debug_output = <<<EOL
- * user-profile--foo--bar.tpl.php
- * user-profile--foo.tpl.php
- * user-profile--{$user3->uid}--full.tpl.php
- * user-profile--{$user3->uid}.tpl.php
- * user-profile--full.tpl.php
- x user-profile.tpl.php
- EOL;
- $this->assertTrue(strpos($output, $debug_output) !== FALSE, 'Suggested template files found in order and base template shown as current template.');
-
-
- config_set('system.core', 'theme_debug', FALSE);
-
- $this->backdropGet('user/' . $admin_user->uid);
- $this->assertNoRaw('<!-- THEME DEBUG -->', 'Theme debug markup not found in theme output when debug is disabled.');
- }
-
-
- * Tests debug taxonomy markup added to template output.
- */
- function testDebugTaxonomyOutput() {
- config_set('system.core', 'theme_default', 'test_theme');
-
- config_set('system.core', 'theme_debug', TRUE);
-
- $vocabulary = new TaxonomyVocabulary(array(
- 'name' => $this->randomName(),
- 'description' => $this->randomName(),
- 'machine_name' => backdrop_strtolower($this->randomName()),
- 'weight' => mt_rand(0, 10),
- ));
- taxonomy_vocabulary_save($vocabulary);
-
- $registry = theme_get_registry();
- $extension = '.tpl.php';
-
- $templates = backdrop_find_theme_templates($registry, $extension, backdrop_get_path('theme', 'test_theme'));
- $templates += backdrop_find_theme_templates($registry, $extension, backdrop_get_path('module', 'taxonomy'));
-
-
- $term = entity_create('taxonomy_term', array(
- 'name' => $this->randomName(),
- 'description' => $this->randomName(),
- 'format' => filter_default_format(),
- 'vocabulary' => $vocabulary->machine_name,
- 'langcode' => LANGUAGE_NONE,
- ));
- taxonomy_term_save($term);
-
- $this->backdropGet("taxonomy/term/$term->tid");
- $this->assertRaw('<!-- THEME DEBUG -->', 'Theme debug markup found in theme output when debug is enabled.');
- $this->assertRaw("CALL: theme('taxonomy_term')", 'Theme call information found.');
- $debug_output = <<<EOL
- * taxonomy-term--{$term->tid}--full.tpl.php
- x taxonomy-term--{$term->tid}.tpl.php
- * taxonomy-term--{$vocabulary->machine_name}--full.tpl.php
- * taxonomy-term--{$vocabulary->machine_name}.tpl.php
- * taxonomy-term.tpl.php
- EOL;
-
- $this->assertRaw($debug_output, 'Suggested template files found in order and term ID specific template shown as current template.');
- $template_filename = $templates['taxonomy_term__' . $term->tid]['path'] . '/' . $templates['taxonomy_term__' . $term->tid]['template'] . $extension;
- $this->assertRaw("BEGIN OUTPUT from '$template_filename'", 'Full path to current template file found.');
-
-
-
- $term2 = entity_create('taxonomy_term', array(
- 'name' => $this->randomName(),
- 'description' => $this->randomName(),
- 'format' => filter_default_format(),
- 'vocabulary' => $vocabulary->machine_name,
- 'langcode' => LANGUAGE_NONE,
- ));
- taxonomy_term_save($term2);
-
- $this->backdropGet("taxonomy/term/$term2->tid");
- $debug_output = <<<EOL
- * taxonomy-term--{$term2->tid}--full.tpl.php
- * taxonomy-term--{$term2->tid}.tpl.php
- * taxonomy-term--{$vocabulary->machine_name}--full.tpl.php
- * taxonomy-term--{$vocabulary->machine_name}.tpl.php
- x taxonomy-term.tpl.php
- EOL;
- $this->assertRaw($debug_output, 'Suggested template files found in order and base template shown as current template.');
-
-
-
- $term3 = entity_create('taxonomy_term', array(
- 'name' => $this->randomName(),
- 'description' => $this->randomName(),
- 'format' => filter_default_format(),
- 'vocabulary' => $vocabulary->machine_name,
- 'langcode' => LANGUAGE_NONE,
- ));
- taxonomy_term_save($term3);
-
- $build = array('#theme' => 'taxonomy_term__foo__bar');
- $build += taxonomy_term_view($term3);
- $output = backdrop_render($build);
- $this->assertTrue(strpos($output, "CALL: theme('taxonomy_term__foo__bar')") !== FALSE, 'Theme call information found.');
- $debug_output = <<<EOL
- * taxonomy-term--foo--bar.tpl.php
- * taxonomy-term--foo.tpl.php
- * taxonomy-term--{$term3->tid}--full.tpl.php
- * taxonomy-term--{$term3->tid}.tpl.php
- * taxonomy-term--{$vocabulary->machine_name}--full.tpl.php
- * taxonomy-term--{$vocabulary->machine_name}.tpl.php
- x taxonomy-term.tpl.php
- EOL;
- $this->assertTrue(strpos($output, $debug_output) !== FALSE, 'Suggested template files found in order and base template shown as current template.');
-
-
- config_set('system.core', 'theme_debug', FALSE);
-
- $this->backdropGet("taxonomy/term/$term3->tid");
- $this->assertNoRaw('<!-- THEME DEBUG -->', 'Theme debug markup not found in theme output when debug is disabled.');
- }
-
- }