Commit 5f1812b9 authored by catch's avatar catch

Issue #1598614 by Rob Loach, aspilicious, Albert Volkman: Convert theme.test to PSR-0.

parent c1ecf4f6
<?php
/**
* @file
* Definition of Drupal\system\Tests\Theme\FastTest.
*/
namespace Drupal\system\Tests\Theme;
use Drupal\simpletest\WebTestBase;
/**
* Tests autocompletion not loading registry.
*/
class FastTest extends WebTestBase {
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'));
}
/**
* Tests access to user autocompletion and verify the correct results.
*/
function testUserAutocomplete() {
$this->drupalLogin($this->account);
$this->drupalGet('user/autocomplete/' . $this->account->name);
$this->assertText('registry not initialized', t('The registry was not initialized'));
}
}
<?php
/**
* @file
* Definition of Drupal\system\Tests\Theme\HookInitTest.
*/
namespace Drupal\system\Tests\Theme;
use Drupal\simpletest\WebTestBase;
/**
* Functional test for initialization of the theme system in hook_init().
*/
class HookInitTest extends WebTestBase {
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');
}
/**
* Test that the theme system can generate output when called by hook_init().
*/
function testThemeInitializationHookInit() {
$this->drupalGet('theme-test/hook-init');
// Verify that themed output generated in hook_init() appears.
$this->assertRaw('Themed output generated in hook_init()');
// Verify that the default theme's CSS still appears when the theme system
// is initialized in hook_init().
$this->assertRaw('stark/css/layout.css');
}
}
<?php
/**
* @file
* Definition of Drupal\system\Tests\Theme\HtmlTagUnitTest.
*/
namespace Drupal\system\Tests\Theme;
use Drupal\simpletest\UnitTestBase;
/**
* Unit tests for theme_html_tag().
*/
class HtmlTagUnitTest extends UnitTestBase {
public static function getInfo() {
return array(
'name' => 'Theme HTML Tag',
'description' => 'Tests theme_html_tag() built-in theme functions.',
'group' => 'Theme',
);
}
/**
* Test function theme_html_tag()
*/
function testThemeHtmlTag() {
// Test auto-closure meta tag generation
$tag['element'] = array('#tag' => 'meta', '#attributes' => array('name' => 'description', 'content' => 'Drupal test'));
$this->assertEqual('<meta name="description" content="Drupal test" />'."\n", theme_html_tag($tag), t('Test auto-closure meta tag generation.'));
// Test title tag generation
$tag['element'] = array('#tag' => 'title', '#value' => 'title test');
$this->assertEqual('<title>title test</title>'."\n", theme_html_tag($tag), t('Test title tag generation.'));
}
}
<?php
/**
* @file
* Definition of Drupal\system\Tests\Theme\HtmlTplPhpAttributesTest.
*/
namespace Drupal\system\Tests\Theme;
use Drupal\simpletest\WebTestBase;
/**
* Functional test for attributes of html.tpl.php.
*/
class HtmlTplPhpAttributesTest extends WebTestBase {
public static function getInfo() {
return array(
'name' => 'html.tpl.php html and body attributes',
'description' => 'Tests attributes inserted in the html and body elements of html.tpl.php.',
'group' => 'Theme',
);
}
function setUp() {
parent::setUp('theme_test');
}
/**
* Tests that modules and themes can alter variables in html.tpl.php.
*/
function testThemeHtmlTplPhpAttributes() {
$this->drupalGet('');
$attributes = $this->xpath('/html[@theme_test_html_attribute="theme test html attribute value"]');
$this->assertTrue(count($attributes) == 1, 'Attribute set in the html element via hook_preprocess_HOOK() for html.tpl.php found.');
$attributes = $this->xpath('/html/body[@theme_test_body_attribute="theme test body attribute value"]');
$this->assertTrue(count($attributes) == 1, 'Attribute set in the body element via hook_preprocess_HOOK() for html.tpl.php found.');
}
}
<?php
/**
* @file
* Definition of Drupal\system\Tests\Theme\RegistryTest.
*/
namespace Drupal\system\Tests\Theme;
use Drupal\simpletest\WebTestBase;
use ThemeRegistry;
/**
* Tests for the ThemeRegistry class.
*/
class RegistryTest extends WebTestBase {
protected $profile = 'testing';
public static function getInfo() {
return array(
'name' => 'ThemeRegistry',
'description' => 'Tests the behavior of the ThemeRegistry class',
'group' => 'Theme',
);
}
function setUp() {
parent::setUp('theme_test');
}
/**
* Tests the behavior of the theme registry class.
*/
function testRaceCondition() {
$_SERVER['REQUEST_METHOD'] = 'GET';
$cid = 'test_theme_registry';
// Directly instantiate the theme registry, this will cause a base cache
// entry to be written in __construct().
$registry = new ThemeRegistry($cid, 'cache');
$this->assertTrue(cache()->get($cid), 'Cache entry was created.');
// Trigger a cache miss for an offset.
$this->assertTrue($registry['theme_test_template_test'], 'Offset was returned correctly from the theme registry.');
// This will cause the ThemeRegistry class to write an updated version of
// the cache entry when it is destroyed, usually at the end of the request.
// Before that happens, manually delete the cache entry we created earlier
// so that the new entry is written from scratch.
cache()->delete($cid);
// Destroy the class so that it triggers a cache write for the offset.
unset($registry);
$this->assertTrue(cache()->get($cid), 'Cache entry was created.');
// Create a new instance of the class. Confirm that both the offset
// requested previously, and one that has not yet been requested are both
// available.
$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');
}
}
<?php
/**
* @file
* Definition of Drupal\system\Tests\Theme\TableTest.
*/
namespace Drupal\system\Tests\Theme;
use Drupal\simpletest\WebTestBase;
/**
* Unit tests for theme_table().
*/
class TableTest extends WebTestBase {
public static function getInfo() {
return array(
'name' => 'Theme Table',
'description' => 'Tests built-in theme functions.',
'group' => 'Theme',
);
}
/**
* 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 = drupal_add_js();
$this->assertTrue(isset($js['core/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();
$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['core/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');
}
/**
* 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>', t('Correct colspan was set on empty message.'));
$this->assertRaw('<thead><tr><th>Header 1</th>', t('Table header was printed.'));
}
}
<?php
/**
* @file
* Definition of Drupal\system\Tests\Theme\ThemeTest.
*/
namespace Drupal\system\Tests\Theme;
use Drupal\simpletest\WebTestBase;
/**
* Tests low-level theme functions.
*/
class ThemeTest extends WebTestBase {
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'));
}
/**
* Test function theme_get_suggestions() for SA-CORE-2009-003.
*/
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'), t('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'), t('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'), t('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'), t('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, t('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() {
// Test with both an unprimed and primed theme registry.
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.');
}
}
/**
* Ensure page-front template suggestion is added when on front page.
*/
function testFrontPageThemeSuggestion() {
$original_path = _current_path();
// Set the current path to node because theme_get_suggestions() will query
// it to see if we are on the front page.
variable_set('site_frontpage', 'node');
_current_path('node');
$suggestions = theme_get_suggestions(array('node'), 'page');
// Set it back to not annoy the batch runner.
_current_path($original_path);
$this->assertTrue(in_array('page__front', $suggestions), t('Front page template was suggested.'));
}
/**
* Ensures theme hook_*_alter() implementations can run before anything is rendered.
*/
function testAlter() {
$this->drupalGet('theme-test/alter');
$this->assertText('The altered data is test_theme_theme_test_alter_alter was invoked.', t('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() {
// Reuse the same page as in testPreprocessForSuggestions(). We're testing
// what is output to the HTML HEAD based on what is in a theme's .info file,
// so it doesn't matter what page we get, as long as it is themed with the
// test theme. First we test with CSS aggregation disabled.
$config = config('system.performance');
$config->set('preprocess_css', 0);
$config->save();
$this->drupalGet('theme-test/suggestion');
$this->assertNoText('system.base.css', t('The theme\'s .info file is able to override a module CSS file from being added to the page.'));
// Also test with aggregation enabled, simply ensuring no PHP errors are
// triggered during drupal_build_css_cache() when a source file doesn't
// exist. Then allow remaining tests to continue with aggregation disabled
// by default.
$config->set('preprocess_css', 1);
$config->save();
$this->drupalGet('theme-test/suggestion');
$config->set('preprocess_css', 0);
$config->save();
}
/**
* Ensures a themes template is overrideable based on the 'template' filename.
*/
function testTemplateOverride() {
variable_set('theme_default', 'test_theme');
$this->drupalGet('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();
// Check if drupal_theme_access() retrieves enabled themes properly from list_themes().
$this->assertTrue(drupal_theme_access('test_theme'), t('Enabled theme detected'));
// Check if list_themes() returns disabled themes.
$this->assertTrue(array_key_exists('test_basetheme', $themes), t('Disabled theme detected'));
// Check for base theme and subtheme lists.
$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, t('Base theme\'s object includes list of subthemes.'));
$this->assertIdentical($themes['test_subtheme']->base_themes, $base_theme_list, t('Subtheme\'s object includes list of base themes.'));
// Check for theme engine in subtheme.
$this->assertIdentical($themes['test_subtheme']->engine, 'phptemplate', t('Subtheme\'s object includes the theme engine.'));
// Check for theme engine prefix.
$this->assertIdentical($themes['test_basetheme']->prefix, 'phptemplate', t('Base theme\'s object includes the theme engine prefix.'));
$this->assertIdentical($themes['test_subtheme']->prefix, 'phptemplate', t('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', t('theme_get_setting() uses the default theme automatically.'));
$this->assertNotEqual(theme_get_setting('subtheme_override', 'test_basetheme'), theme_get_setting('subtheme_override', 'test_subtheme'), t('Base theme\'s default settings values can be overridden by subtheme.'));
$this->assertIdentical(theme_get_setting('basetheme_only', 'test_subtheme'), 'base theme value', t('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.');
}
}
......@@ -22,7 +22,6 @@ files[] = tests/registry.test
files[] = tests/schema.test
files[] = tests/symfony.test
files[] = tests/tablesort.test
files[] = tests/theme.test
files[] = tests/update.test
files[] = tests/uuid.test
files[] = tests/xmlrpc.test
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment