From 1936dbc53de2440a0bcc35a6c64cab16327e2ffe Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Sat, 8 Jun 2013 18:24:06 +0100 Subject: [PATCH] Issue #1938898 followup by brantwynn, tim.plunkett, Cottser: Fixed Convert block theme tables to table #type. --- .../lib/Drupal/block/BlockListController.php | 11 ++-- .../lib/Drupal/block/Tests/BlockUiTest.php | 59 ++++++++++++++++++- 2 files changed, 63 insertions(+), 7 deletions(-) diff --git a/core/modules/block/lib/Drupal/block/BlockListController.php b/core/modules/block/lib/Drupal/block/BlockListController.php index 9b8be711fa0..69a18faf544 100644 --- a/core/modules/block/lib/Drupal/block/BlockListController.php +++ b/core/modules/block/lib/Drupal/block/BlockListController.php @@ -143,9 +143,12 @@ class BlockListController extends ConfigEntityListController implements FormInte // Build blocks first for each region. foreach ($entities as $entity_id => $entity) { - $info = $entity->getPlugin()->getDefinition(); - $info['entity_id'] = $entity_id; - $blocks[$entity->get('region')][] = $info; + $definition = $entity->getPlugin()->getDefinition(); + $blocks[$entity->get('region')][$entity_id] = array( + 'admin_label' => $definition['admin_label'], + 'entity_id' => $entity_id, + 'weight' => $entity->get('weight'), + ); } // Loop over each region and build blocks. @@ -229,7 +232,7 @@ class BlockListController extends ConfigEntityListController implements FormInte ); $form['blocks'][$entity_id]['weight'] = array( '#type' => 'weight', - '#default_value' => $entity->get('weight'), + '#default_value' => $info['weight'], '#delta' => $weight_delta, '#title_display' => 'invisible', '#title' => t('Weight for @block block', array('@block' => $info['admin_label'])), diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockUiTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockUiTest.php index f0b28a9c701..cd9d955682d 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockUiTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockUiTest.php @@ -31,7 +31,7 @@ class BlockUiTest extends WebTestBase { public static function getInfo() { return array( 'name' => 'Block UI', - 'description' => 'Checks that the block configuration UI stores data correctly.', + 'description' => 'Checks that the block configuration UI exists and stores data correctly.', 'group' => 'Block', ); } @@ -44,12 +44,65 @@ class BlockUiTest extends WebTestBase { 'access administration pages', )); $this->drupalLogin($this->adminUser); + + // Enable some test blocks. + $this->testBlocks = array( + array( + 'label' => 'Tools', + 'tr' => '5', + 'plugin_id' => 'system_menu_block:menu-tools', + 'settings' => array('region' => 'sidebar_second', 'machine_name' => 'tools'), + 'test_weight' => '-1', + ), + array( + 'label' => 'Powered by Drupal', + 'tr' => '12', + 'plugin_id' => 'system_powered_by_block', + 'settings' => array('region' => 'footer', 'machine_name' => 'powered'), + 'test_weight' => '0', + ), + ); + foreach ($this->testBlocks as $values) { + $this->drupalPlaceBlock($values['plugin_id'], $values['settings']); + } } /** - * Test block visibility. + * Test block admin page exists and functions correctly. */ - function testBlockVisibility() { + function testBlockAdminUiPage() { + // Visit the blocks admin ui. + $this->drupalGet('admin/structure/block'); + // Look for the blocks table. + $blocks_table = $this->xpath("//table[@id='blocks']"); + $this->assertTrue(!empty($blocks_table), 'The blocks table is being rendered.'); + // Look for test blocks in the table. + foreach ($this->testBlocks as $values) { + $element = $this->xpath('//*[@id="blocks"]/tbody/tr[' . $values['tr'] . ']/td[1]/text()'); + $this->assertTrue((string)$element[0] == $values['label'], 'The "' . $values['label'] . '" block title is set inside the ' . $values['settings']['region'] . ' region.'); + // Look for a test block region select form element. + $this->assertField('blocks[stark.' . $values['settings']['machine_name'] . '][region]', 'The block "' . $values['label'] . '" has a region assignment field.'); + // Move the test block to the header region. + $edit['blocks[stark.' . $values['settings']['machine_name'] . '][region]'] = 'header'; + // Look for a test block weight select form element. + $this->assertField('blocks[stark.' . $values['settings']['machine_name'] . '][weight]', 'The block "' . $values['label'] . '" has a weight assignment field.'); + // Change the test block's weight. + $edit['blocks[stark.' . $values['settings']['machine_name'] . '][weight]'] = $values['test_weight']; + } + $this->drupalPost('admin/structure/block', $edit, t('Save blocks')); + foreach ($this->testBlocks as $values) { + // Check if the region and weight settings changes have persisted. + $this->assertOptionSelected( + 'edit-blocks-stark' . $values['settings']['machine_name'] . '-region', + 'header', + 'The block "' . $values['label'] . '" has the correct region assignment (header).' + ); + $this->assertOptionSelected( + 'edit-blocks-stark' . $values['settings']['machine_name'] . '-weight', + $values['test_weight'], + 'The block "' . $values['label'] . '" has the correct weight assignment (' . $values['test_weight'] . ').' + ); + } } /**