123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648 |
- <?php
- class ThemeTestCase extends DrupalWebTestCase {
- protected $profile = 'testing';
- public static function getInfo() {
- return array(
- 'name' => 'Theme API',
- 'description' => 'Test low-level theme functions.',
- 'group' => 'Theme',
- );
- }
- function setUp() {
- parent::setUp('theme_test');
- theme_enable(array('test_theme'));
- }
-
- function testThemeSuggestions() {
-
-
- 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');
-
- $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.');
- }
-
- function testPreprocessForSuggestions() {
-
- drupal_theme_rebuild();
- for ($i = 0; $i < 2; $i++) {
- $this->drupalGet('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.');
- }
- }
-
- function testFrontPageThemeSuggestion() {
- $q = $_GET['q'];
-
-
- $_GET['q'] = variable_get('site_frontpage', 'node');
- $suggestions = theme_get_suggestions(explode('/', $_GET['q']), 'page');
-
- $_GET['q'] = $q;
- $this->assertTrue(in_array('page__front', $suggestions), 'Front page template was suggested.');
- }
-
- function testAlter() {
- $this->drupalGet('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.');
- }
-
- function testCSSOverride() {
-
-
-
-
- variable_set('preprocess_css', 0);
- $this->drupalGet('theme-test/suggestion');
- $this->assertNoText('system.base.css', 'The theme\'s .info file is able to override a module CSS file from being added to the page.');
-
-
-
-
- variable_set('preprocess_css', 1);
- $this->drupalGet('theme-test/suggestion');
- variable_set('preprocess_css', 0);
- }
-
- 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.');
- }
-
- function testListThemes() {
- $themes = list_themes();
-
- $this->assertTrue(drupal_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.');
- }
-
- 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.');
- }
-
- function testDrupalAddRegionContent() {
- $this->drupalGet('theme-test/drupal-add-region-content');
- $this->assertText('Hello');
- $this->assertText('World');
- }
- }
- class ThemeTableTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Theme Table',
- 'description' => 'Tests built-in theme functions.',
- 'group' => 'Theme',
- );
- }
-
- 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 = drupal_add_js();
- $this->assertTrue(isset($js['misc/tableheader.js']), 'tableheader.js was included when $sticky = TRUE.');
- $this->assertRaw('sticky-enabled', 'Table has a class of sticky-enabled when $sticky = TRUE.');
- drupal_static_reset('drupal_add_js');
- }
-
- 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 = drupal_add_js();
- $this->assertFalse(isset($js['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.');
- drupal_static_reset('drupal_add_js');
- }
-
- 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.');
- }
-
- 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.');
- }
- }
- class ThemeItemListUnitTest extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Theme item list',
- 'description' => 'Test the theme_item_list() function.',
- 'group' => 'Theme',
- );
- }
-
- function testItemList() {
- $items = array('a', array('data' => 'b', 'children' => array('c' => 'c', 'd' => 'd', 'e' => 'e')), 'f');
- $expected = '<div class="item-list"><ul><li class="first">a</li>
- <li>b<div class="item-list"><ul><li class="first">c</li>
- <li>d</li>
- <li class="last">e</li>
- </ul></div></li>
- <li class="last">f</li>
- </ul></div>';
- $output = theme('item_list', array('items' => $items));
- $this->assertIdentical($expected, $output, 'Item list is rendered correctly.');
- }
- }
- class ThemeLinksTest extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Links',
- 'description' => 'Test the theme_links() function and rendering groups of links.',
- 'group' => 'Theme',
- );
- }
-
- function testDrupalPreRenderLinks() {
-
-
- $base_array = array(
- '#theme' => 'links',
- '#pre_render' => array('drupal_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 = drupal_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 = drupal_render($render_array['first_child']);
- $parent_html = drupal_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.');
- }
- }
- class ThemeHookInitTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Theme initialization in hook_init()',
- 'description' => 'Tests that the theme system can be correctly initialized in hook_init().',
- 'group' => 'Theme',
- );
- }
- function setUp() {
- parent::setUp('theme_test');
- }
-
- function testThemeInitializationHookInit() {
- $this->drupalGet('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('bartik/css/style.css', "The default theme's CSS appears on the page when the theme system is initialized in hook_init().");
- }
- }
- class ThemeFastTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Theme fast initialization',
- 'description' => 'Test that autocompletion does not load the registry.',
- 'group' => 'Theme'
- );
- }
- function setUp() {
- parent::setUp('theme_test');
- $this->account = $this->drupalCreateUser(array('access user profiles'));
- }
-
- function testUserAutocomplete() {
- $this->drupalLogin($this->account);
- $this->drupalGet('user/autocomplete/' . $this->account->name);
- $this->assertText('registry not initialized', 'The registry was not initialized');
- }
- }
- class RenderElementTypesTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Render element types',
- 'description' => 'Tests the markup of core render element types passed to drupal_render().',
- 'group' => 'Theme',
- );
- }
-
- function assertElements($elements) {
- foreach($elements as $element) {
- $this->assertIdentical(drupal_render($element['value']), $element['expected'], '"' . $element['name'] . '" input rendered correctly by drupal_render().');
- }
- }
-
- 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);
- }
-
- function testHtmlTag() {
- $elements = array(
-
- array(
- 'name' => "#type 'html_tag' auto-closure meta tag generation",
- 'value' => array(
- '#type' => 'html_tag',
- '#tag' => 'meta',
- '#attributes' => array(
- 'name' => 'description',
- 'content' => 'Drupal test',
- ),
- ),
- 'expected' => '<meta name="description" content="Drupal test" />' . "\n",
- ),
-
- array(
- 'name' => "#type 'html_tag' title tag generation",
- 'value' => array(
- '#type' => 'html_tag',
- '#tag' => 'title',
- '#value' => 'title test',
- ),
- 'expected' => '<title>title test</title>' . "\n",
- ),
- );
- $this->assertElements($elements);
- }
- }
- class ThemeRegistryTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'ThemeRegistry',
- 'description' => 'Tests the behavior of the ThemeRegistry class',
- 'group' => 'Theme',
- );
- }
- function setUp() {
- parent::setUp('theme_test');
- }
-
- 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_clear_all($cid, 'cache');
-
- 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');
- }
- }
- class ThemeDebugMarkupTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Theme debug markup',
- 'description' => 'Tests theme debug markup output.',
- 'group' => 'Theme',
- );
- }
- function setUp() {
- parent::setUp('theme_test', 'node');
- theme_enable(array('test_theme'));
- }
-
- function testDebugOutput() {
- variable_set('theme_default', 'test_theme');
-
- variable_set('theme_debug', TRUE);
- $registry = theme_get_registry();
- $extension = '.tpl.php';
-
- $templates = drupal_find_theme_templates($registry, $extension, drupal_get_path('theme', 'test_theme'));
- $templates += drupal_find_theme_templates($registry, $extension, drupal_get_path('module', 'node'));
-
- $node = $this->drupalCreateNode();
- $this->drupalGet('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.');
- $this->assertRaw('x node--1' . $extension . PHP_EOL . ' * node--page' . $extension . PHP_EOL . ' * node' . $extension, 'Suggested template files found in order and node ID specific template shown as current template.');
- $template_filename = $templates['node__1']['path'] . '/' . $templates['node__1']['template'] . $extension;
- $this->assertRaw("BEGIN OUTPUT from '$template_filename'", 'Full path to current template file found.');
-
-
- $node2 = $this->drupalCreateNode();
- $this->drupalGet('node/' . $node2->nid);
- $this->assertRaw('* node--2' . $extension . PHP_EOL . ' * node--page' . $extension . PHP_EOL . ' x node' . $extension, 'Suggested template files found in order and base template shown as current template.');
-
-
- $node3 = $this->drupalCreateNode();
- $build = array('#theme' => 'node__foo__bar');
- $build += node_view($node3);
- $output = drupal_render($build);
- $this->assertTrue(strpos($output, "CALL: theme('node__foo__bar')") !== FALSE, 'Theme call information found.');
- $this->assertTrue(strpos($output, '* node--foo--bar' . $extension . PHP_EOL . ' * node--foo' . $extension . PHP_EOL . ' * node--3' . $extension . PHP_EOL . ' * node--page' . $extension . PHP_EOL . ' x node' . $extension) !== FALSE, 'Suggested template files found in order and base template shown as current template.');
-
- variable_set('theme_debug', FALSE);
- $this->drupalGet('node/' . $node->nid);
- $this->assertNoRaw('<!-- THEME DEBUG -->', 'Theme debug markup not found in theme output when debug is disabled.');
- }
- }
|