commit 2e98cb00a7bda936a51d4885aaea9c9ddb486134 Author: Lee Rowlands Date: Mon Jan 14 09:19:09 2013 +1000 Fixes test coverage diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php index 6ac4f16..0b6cc0e 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php @@ -106,20 +106,19 @@ public function testCustomBlock() { } } - // Add a new custom block by filling out the input form on the admin/structure/block/add page. + // Add a new custom block by filling out the input form on block/add/basic. $info = strtolower($this->randomName(8)); + $langcode = LANGUAGE_NOT_SPECIFIED; $values = array( - 'type' => 'basic', 'info' => $info, - 'machine_name' => $info + 'machine_name' => $info, + "block_body[$langcode][0][value]" => $this->randomName(8) ); - $block = entity_create('custom_block', $values)->save(); + $this->drupalPost('block/add/basic', $values, t('Save')); $custom_block['machine_name'] = $info; $custom_block['title'] = $this->randomName(8); - $langcode = LANGUAGE_NOT_SPECIFIED; - $custom_block["block_body[$langcode][0][value]"] = $this->randomName(32); $custom_block['region'] = $this->regions[0]; - $this->drupalPost("admin/structure/block/manage/custom_block:$info/add/custom_blocks", $custom_block, t('Save block')); + $this->drupalPost(NULL, $custom_block, t('Save block')); $plugin_id = "plugin.core.block.$default_theme.$info"; $block = $manager->getInstance(array('config' => $plugin_id)); $config = $block->getConfig(); @@ -127,9 +126,14 @@ public function testCustomBlock() { // Confirm that the custom block has been created, and then query the created bid. $this->assertText(t('The block configuration has been saved.'), 'Custom block instance successfully created.'); - // Check that block_block_view() returns the correct title and content. + // Check that block_block_view() returns the correct content. $data = $block->build(); - $this->assertRaw(check_markup($custom_block["block_body[$langcode][0][value]"], FILTER_DEFAULT), render($data), 'BlockInterface::build() provides correct block content.'); + $output = render($data); + + $this->drupalSetcontent($output); + $elements = $this->xpath('//div[@class=:class]', array(':class' => 'field-item even')); + + $this->assertEqual($values["block_body[$langcode][0][value]"], $elements[0], 'BlockInterface::build() provides correct block content.'); // Check whether the block can be moved to all available regions. $custom_block['module'] = 'block'; @@ -163,36 +167,41 @@ public function testCustomBlockFormat() { $default_theme = variable_get('theme_default', 'stark'); $this->removeDefaultBlocks(); - // Add a new custom block by filling out the input form on the admin/structure/block/add page. - $info = $this->randomName(8); + // Add a new custom block by filling out the input form on block/add/basic. + $info = strtolower($this->randomName(8)); + $langcode = LANGUAGE_NOT_SPECIFIED; + $values = array( + 'info' => $info, + 'machine_name' => $info, + "block_body[$langcode][0][value]" => '

Full HTML

', + "block_body[$langcode][0][format]" => 'full_html' + ); + $this->drupalPost('block/add/basic', $values, t('Save')); $custom_block['machine_name'] = $info; - $custom_block['info'] = $info; $custom_block['title'] = $this->randomName(8); - $custom_block['body[value]'] = '

Full HTML

'; - $full_html_format = filter_format_load('full_html'); - $custom_block['body[format]'] = $full_html_format->format; $custom_block['region'] = $this->regions[0]; - $this->drupalPost("admin/structure/block/list/block_plugin_ui:$default_theme/add/custom_blocks", $custom_block, t('Save block')); + $this->drupalPost(NULL, $custom_block, t('Save block')); // Set the created custom block to a specific region. $edit['blocks[0][region]'] = $this->regions[1]; $this->drupalPost('admin/structure/block', $edit, t('Save blocks')); - // Confirm that the custom block is being displayed using configured text format. + // Confirm that the custom block is being displayed using configured text + // format. $this->drupalGet(''); $this->assertRaw('

Full HTML

', 'Custom block successfully being displayed using Full HTML.'); - // Confirm that a user without access to Full HTML can not see the body field, - // but can still submit the form without errors. + // Confirm that a user without access to Full HTML can not see the body + // field, but can still submit the form without errors. $block_admin = $this->drupalCreateUser(array('administer blocks')); $config_block_id = "admin/structure/block/manage/plugin.core.block.$default_theme.$info/$default_theme"; $this->drupalLogin($block_admin); - $this->drupalGet("$config_block_id/configure"); - $this->assertFieldByXPath("//textarea[@name='body[value]' and @disabled='disabled']", t('This field has been disabled because you do not have sufficient permissions to edit it.'), 'Body field contains denied message'); - $this->drupalPost("$config_block_id/configure", array(), t('Save block')); + $this->drupalGet("block/$info/edit"); + $this->assertFieldByXPath("//textarea[@name='block_body[und][0][value]' and @disabled='disabled']", t('This field has been disabled because you do not have sufficient permissions to edit it.'), 'Body field contains denied message'); $this->assertNoText(t('Ensure that each block description is unique.')); - // Confirm that the custom block is still being displayed using configured text format. + // Confirm that the custom block is still being displayed using configured + // text format. $this->drupalGet(''); $this->assertRaw('

Full HTML

', 'Custom block successfully being displayed using Full HTML.'); } commit 8a9b66d1af0871d162c8a5ecad5183dfb50ff120 Author: Lee Rowlands Date: Mon Jan 14 09:18:35 2013 +1000 Provides upgrade path for schema changes diff --git a/core/modules/block/block.install b/core/modules/block/block.install index c16e50a..c024974 100644 --- a/core/modules/block/block.install +++ b/core/modules/block/block.install @@ -194,6 +194,220 @@ function block_update_8006() { } /** + * Make changes required to {block_custom}. + * + * Note this table now resides in custom_block_schema() but for 7.x to 8.x + * upgrades, changes must be made from block module as custom_block module is + * only enabled during upgrade process. + */ +function block_update_8007() { + // Add the {block_custom_revision} table. + db_create_table('block_custom_revision', array( + 'description' => 'Stores contents of custom-made blocks.', + 'fields' => array( + 'bid' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + 'description' => "The block's {block}.bid.", + ), + // Defaults to NULL in order to avoid a brief period of potential + // deadlocks on the index. + 'vid' => array( + 'description' => 'The current version identifier.', + 'type' => 'serial', + 'unsigned' => TRUE, + 'not null' => TRUE, + ), + 'log' => array( + 'description' => 'The log entry explaining the changes in this version.', + 'type' => 'text', + 'not null' => TRUE, + 'size' => 'big', + ), + ), + 'unique keys' => array( + 'vid' => array('vid'), + ), + 'primary key' => array('vid'), + )); + // Add the vid column to {block_custom}. + db_add_field('block_custom', 'vid', array( + 'description' => 'The current {block_custom_revision}.vid version identifier.', + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => FALSE, + 'default' => NULL, + ), array( + 'unique keys' => array( + 'vid' => array('vid'), + ), + )); + // Add the uuid column to {block_custom}. + db_add_field('block_custom', 'uuid', array( + 'description' => 'Unique Key: Universally unique identifier for this entity.', + 'type' => 'varchar', + 'length' => 128, + 'not null' => FALSE, + ), + array( + 'unique keys' => array( + 'uuid' => array('uuid'), + ), + )); + // Add the machine_name column to {block_custom}. + db_add_field('block_custom', 'machine_name', array( + 'type' => 'varchar', + 'length' => 128, + 'not null' => TRUE, + 'default' => '', + 'description' => 'Machine name of block.', + )); + // Add the type column to {block_custom}. + db_add_field('block_custom', 'type', array( + 'description' => 'The type of this custom block.', + 'type' => 'varchar', + 'length' => 32, + 'not null' => TRUE, + 'default' => '', + )); + // Add the langcode column to {block_custom}. + db_add_field('block_custom', 'langcode', array( + 'description' => 'The {language}.langcode of this node.', + 'type' => 'varchar', + 'length' => 12, + 'not null' => TRUE, + 'default' => '', + )); + // Populate the {custom_block_revision} table. + $results = db_select('block_custom', 'bc')->fields('bc')->execute(); + foreach ($results as $block) { + $revision = array( + 'bid' => $block->bid, + 'log' => 'Initial value from 7.x to 8.x upgrade' + ); + drupal_write_record('custom_block_revision', $revision); + db_update('block_custom')->values( + array( + 'vid' => $revision['vid'], + 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'type' => 'basic', + 'machine_name' => preg_replace('^([a-z|0-9|\_]', '', $block->info) + ) + )->condition('bid', $block->bid)->execute(); + } +} + +/** + * Generate a UUID for all comments. + */ +function comment_update_8008(&$sandbox) { + if (!isset($sandbox['progress'])) { + $sandbox['progress'] = 0; + $sandbox['last'] = 0; + $sandbox['max'] = db_query('SELECT COUNT(bid) FROM {block_custom} WHERE uuid IS NULL')->fetchField(); + } + + $bids = db_query_range('SELECT bid FROM {block_custom} WHERE bid > :bid AND uuid IS NULL ORDER BY bid ASC', 0, 10, array(':bid' => $sandbox['last']))->fetchCol(); + update_add_uuids($sandbox, 'block_custom', 'bid', $bids); + + $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']); +} + +/** + * Migrate {block_custom}.body and {block_custom}.format to block_body field. + */ +function block_update_8009() { + $sandbox['#finished'] = 0; + + if (!isset($sandbox['total'])) { + // Initial invocation. + + // First, create the body field. + $body_field = array( + 'field_name' => 'block_body', + 'type' => 'text_with_summary', + 'entity_types' => array('custom_block'), + 'module' => 'text', + 'cardinality' => 1, + ); + _update_7000_field_create_field($body_field); + + $instance = array( + 'field_name' => 'block_body', + 'entity_type' => 'custom_block', + 'bundle' => 'basic', + 'label' => 'Block body', + 'widget' => array('type' => 'text_textarea_with_summary'), + 'settings' => array('display_summary' => FALSE), + ); + _update_7000_field_create_instance($body_field, $instance); + + // Used below when updating the stored text format of each body. + $sandbox['existing_text_formats'] = db_query("SELECT format FROM {filter_format}")->fetchCol(); + + // Initialize state for future calls. + $sandbox['last'] = 0; + $sandbox['count'] = 0; + + $query = db_select('block_custom', 'bc'); + $sandbox['total'] = $query->countQuery()->execute()->fetchField(); + + $sandbox['body_field_id'] = $body_field['id']; + } + else { + // Subsequent invocations. + + $found = FALSE; + if ($sandbox['total']) { + // Operate on each block in turn. + $batch_size = 200; + $query = db_select('block_custom', 'bc'); + $query + ->fields('bc', array('bid', 'vid', 'body', 'format')) + ->condition('bc.bid', $sandbox['last'], '>') + ->orderBy('bc.bid', 'ASC') + ->range(0, $batch_size); + $blocks = $query->execute(); + + // Load the block, set up 'body' and save the field data. + foreach ($blocks as $block) { + $found = TRUE; + + $data = array( + LANGUAGE_NOT_SPECIFIED => array( + array( + 'format' => $block->format, + 'value' => $block->body + ) + ) + ); + // This is a core update and no contrib modules are enabled yet, so + // we can assume default field storage for a faster update. + _update_7000_field_sql_storage_write('custom_block', 'basic', $block->nid, $block->vid, 'block_body', $data); + + $sandbox['last'] = $block->bid; + $sandbox['count'] += 1; + } + + $sandbox['#finished'] = min(0.99, $sandbox['count'] / $sandbox['total']); + } + + if (!$found) { + // All blocks are processed. + + // Remove the now-obsolete body info from block_custom. + db_drop_field('block_custom', 'body'); + db_drop_field('block_custom', 'format'); + + // We're done. + $sandbox['#finished'] = 1; + } + } +} + +/** * @} End of "addtogroup updates-7.x-to-8.x". * The next series of updates should start at 9000. */