From 3ca9ca5aa27c81613caccb7d53eb2ed33a1835fa Mon Sep 17 00:00:00 2001 From: Tor Arne Thune Date: Thu, 14 Jul 2011 14:47:36 +0200 Subject: [PATCH] Issue #1103590: Test for ensuring that blocks not inherited to hidden region when first enabling theme --- modules/block/block.module | 2 +- modules/block/block.test | 42 ++++++- .../tests/block_test_theme/block_test_theme.info | 12 ++ themes/tests/block_test_theme/page.tpl.php | 137 ++++++++++++++++++++ 4 files changed, 189 insertions(+), 4 deletions(-) create mode 100644 themes/tests/block_test_theme/block_test_theme.info create mode 100644 themes/tests/block_test_theme/page.tpl.php diff --git a/modules/block/block.module b/modules/block/block.module index e7a6ca9..7b42067 100644 --- a/modules/block/block.module +++ b/modules/block/block.module @@ -613,7 +613,7 @@ function block_theme_initialize($theme) { if (!$has_blocks) { $default_theme = variable_get('theme_default', 'bartik'); // Apply only to new theme's visible regions. - $regions = system_region_list($theme, REGIONS_VISIBLE); + $regions = system_region_list($theme); $result = db_query("SELECT * FROM {block} WHERE theme = :theme", array(':theme' => $default_theme), array('fetch' => PDO::FETCH_ASSOC)); foreach ($result as $block) { // If the region isn't supported by the theme, assign the block to the theme's default region. diff --git a/modules/block/block.test b/modules/block/block.test index 022bf38..aeda98b 100644 --- a/modules/block/block.test +++ b/modules/block/block.test @@ -83,7 +83,7 @@ class BlockTestCase extends DrupalWebTestCase { $this->assertTrue(array_key_exists('subject', $data) && empty($data['subject']), t('block_block_view() provides an empty block subject, since custom blocks do not have default titles.')); $this->assertEqual(check_markup($custom_block['body[value]'], $format), $data['content'], t('block_block_view() provides correct block content.')); - // Check if the block can be moved to all availble regions. + // Check if the block can be moved to all available regions. $custom_block['module'] = 'block'; $custom_block['delta'] = $bid; foreach ($this->regions as $region) { @@ -264,7 +264,7 @@ class BlockTestCase extends DrupalWebTestCase { // Check to see if the block was created by checking that it's in the database. $this->assertNotNull($bid, t('Block found in database')); - // Check if the block can be moved to all availble regions. + // Check if the block can be moved to all available regions. foreach ($this->regions as $region) { $this->moveBlockToRegion($block, $region); } @@ -278,7 +278,7 @@ class BlockTestCase extends DrupalWebTestCase { $this->assertText(t('The block settings have been updated.'), t('Block successfully move to disabled region.')); $this->assertNoText(t($block['title']), t('Block no longer appears on page.')); - // Confirm that the regions xpath is not availble + // Confirm that the regions xpath is not available $xpath = $this->buildXPathQuery('//div[@id=:id]/*', array(':id' => 'block-block-' . $bid)); $this->assertNoFieldByXPath($xpath, FALSE, t('Custom block found in no regions.')); @@ -708,3 +708,39 @@ class BlockTemplateSuggestionsUnitTest extends DrupalUnitTestCase { $this->assertEqual($variables2['theme_hook_suggestions'], array('block__footer', 'block__block', 'block__block__hyphen_test'), t('Hyphens (-) in block delta were replaced by underscore (_)')); } } + +/** + * Test blocks not inherited to hidden regions when enabling new theme. + */ +class BlockHiddenRegionTestCase extends DrupalWebTestCase { + public static function getInfo() { + return array( + 'name' => 'Blocks not in hidden region', + 'description' => 'Checks that a newly enabled theme does not inherit blocks to its hidden regions.', + 'group' => 'Block', + ); + } + + /** + * Checks that a block is not inherited to hidden region of newly enabled theme. + */ + function testBlockNotInHiddenRegion() { + // Create administrative user. + $admin_user = $this->drupalCreateUser(array('administer blocks', 'administer themes', 'search content')); + $this->drupalLogin($admin_user); + + // Enable "block_test_theme" and set it as the default theme. + $theme = 'block_test_theme'; + theme_enable(array($theme)); + variable_set('theme_default', $theme); + menu_rebuild(); + + // Ensure that "block_test_theme" is set as the default theme. + $this->drupalGet('admin/structure/block'); + $this->assertText('Block test theme(' . t('active tab') . ')', t('Default local task on blocks admin page is the block test theme.')); + + // Ensure that the search form block is displayed. + $this->drupalGet(''); + $this->assertText('Search form', t('Block was displayed on the front page.')); + } +} diff --git a/themes/tests/block_test_theme/block_test_theme.info b/themes/tests/block_test_theme/block_test_theme.info new file mode 100644 index 0000000..fb70cb3 --- /dev/null +++ b/themes/tests/block_test_theme/block_test_theme.info @@ -0,0 +1,12 @@ +name = Block test theme +description = Theme for testing the block system +core = 8.x +hidden = TRUE + +regions_hidden[sidebar_first] = Left sidebar +regions_hidden[sidebar_second] = Right sidebar +regions[content] = Content +regions[header] = Header +regions[footer] = Footer +regions[highlighted] = Highlighted +regions[help] = Help diff --git a/themes/tests/block_test_theme/page.tpl.php b/themes/tests/block_test_theme/page.tpl.php new file mode 100644 index 0000000..53c0b34 --- /dev/null +++ b/themes/tests/block_test_theme/page.tpl.php @@ -0,0 +1,137 @@ + + +
+ + + + + + + + + + + + + +
+ +
+
+ + +

+ +
+ + + + +
+
+ + + +
-- 1.7.4.1