diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php index 40f1d12..c607973 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php @@ -391,21 +391,20 @@ function testBlockModuleDisable() { $manager = $this->container->get('plugin.manager.block'); $manager->clearCachedDefinitions(); - // Add a test block. - $plugin = $manager->getDefinition('test_cache'); - $block = array(); - $block['id'] = 'test_cache'; - $block['machine_name'] = $this->randomName(8); - $block['theme'] = variable_get('theme_default', 'stark'); - $block['region'] = 'header'; - $this->drupalPost('admin/structure/block/manage/' . $block['id'] . '/' . $block['theme'], array('machine_name' => $block['machine_name'], 'region' => $block['region']), t('Save block')); - - // Confirm that the block is displayed on the front page. + // Add test blocks in different regions and confirm they are displayed. + $blocks = array(); + $regions = array('sidebar_first', 'content', 'footer'); + foreach ($regions as $region) { + $blocks[$region] = $this->drupalPlaceBlock('test_cache', array('region' => $region)); + } $this->drupalGet(''); - $this->assertText('Test block caching'); + foreach ($regions as $region) { + $this->assertText($blocks[$region]['subject']); + } // Disable the block test module and refresh the definitions cache. module_disable(array('block_test'), FALSE); + $this->assertFalse(module_exists('block_test'), 'Test block module disabled.'); $manager->clearCachedDefinitions(); // Ensure that the block administration page still functions as expected. @@ -415,7 +414,9 @@ function testBlockModuleDisable() { $this->assertTitle(t('Blocks | Drupal')); // Ensure that the disabled module's block instance is not listed. - $this->assertNoText(t('Test block caching')); + foreach ($regions as $region) { + $this->assertNoText($blocks[$region]['subject']); + } // Ensure that the disabled module's block plugin is no longer available. $this->drupalGet('admin/structure/block/list/block_plugin_ui:' . variable_get('theme_default', 'stark') . '/add'); @@ -424,17 +425,22 @@ function testBlockModuleDisable() { // Confirm that the block is no longer displayed on the front page. $this->drupalGet(''); $this->assertResponse(200); - $this->assertNoText('Test block caching'); + foreach ($regions as $region) { + $this->assertNoText($blocks[$region]['subject']); + } - // Confirm that a different block instance can still be enabled. - $block_id = 'system_powered_by_block'; + // Confirm that a different block instance can still be enabled by + // submitting the block library form. + // Emulate a POST submission rather than using drupalPlaceBlock() to ensure + // that the form still functions as expected. $edit = array( 'title' => $this->randomName(8), 'machine_name' => $this->randomName(8), 'region' => 'sidebar_first', ); - $this->drupalPost('admin/structure/block/manage/' . $block_id . '/stark', $edit, t('Save block')); + $this->drupalPost('admin/structure/block/manage/system_powered_by_block/stark', $edit, t('Save block')); $this->assertText(t('The block configuration has been saved.')); + $this->assertText($edit['title']); // Update the weight of a block. $edit = array('blocks[0][weight]' => -1); @@ -443,15 +449,31 @@ function testBlockModuleDisable() { // Re-enable the module and refresh the definitions cache. module_enable(array('block_test'), FALSE); + $this->assertTrue(module_exists('block_test'), 'Test block module re-enabled.'); $manager->clearCachedDefinitions(); // Reload the admin page and confirm the block can again be configured. $this->drupalGet('admin/structure/block'); - $this->assertLinkByHref(url('admin/structure/block/manage/plugin.core.block.stark.' . $block['machine_name'] . '/stark/config')); + foreach ($regions as $region) { + $this->assertLinkByHref(url('admin/structure/block/manage/' . $blocks[$region]['config_id'] . '/stark/config')); + } - // Confirm that the block is again displayed on the front page. + // Confirm that the blocks are again displayed on the front page in the + // correct regions. $this->drupalGet(''); - $this->assertText('Test block caching'); + foreach ($regions as $region) { + // @todo Use a proper method for this. + $name_pieces = explode('.', $blocks[$region]['config_id']); + $machine_name = array_pop($name_pieces); + $xpath = $this->buildXPathQuery('//div[@class=:region-class]//div[@id=:block-id]/*', array( + ':region-class' => 'region region-' . drupal_html_class($region), + ':block-id' => 'block-' . strtr(strtolower($machine_name), '-', '_'), + )); + $this->assertFieldByXPath($xpath, NULL, format_string('Block %name found in the %region region.', array( + '%name' => $blocks[$region]['subject'], + '%region' => $region, + ))); + } } }