diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Derivative/CategoryBlock.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Derivative/CategoryBlock.php index 1bd3af8..1a128c9 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Derivative/CategoryBlock.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Derivative/CategoryBlock.php @@ -11,6 +11,11 @@ class CategoryBlock implements DerivativeInterface { * Implements DerivativeInterface::getDerivativeDefinition(). */ public function getDerivativeDefinition($derivative_id, array $base_plugin_definition) { + // TODO. This check is here for simpletest. See + // http://drupal.org/node/1821658 + if (!module_exists('aggregator')) { + return array(); + } if (!empty($this->derivatives) && !empty($this->derivatives[$derivative_id])) { return $this->derivatives[$derivative_id]; } @@ -25,9 +30,14 @@ public function getDerivativeDefinition($derivative_id, array $base_plugin_defin * Implements DerivativeInterface::getDerivativeDefinitions(). */ public function getDerivativeDefinitions(array $base_plugin_definition) { + // TODO. This check is here for simpletest. See + // http://drupal.org/node/1821658 + if (!module_exists('aggregator')) { + return array(); + } $result = db_query('SELECT cid, title FROM {aggregator_category} ORDER BY title'); foreach ($result as $category) { - $this->derivatives[$category->cid] = $this->config; + $this->derivatives[$category->cid] = $base_plugin_definition; $this->derivatives[$category->cid]['delta'] = $category->cid; $this->derivatives[$category->cid]['subject'] = t('@title category latest items', array('@title' => $category->title)); } diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Derivative/FeedBlock.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Derivative/FeedBlock.php index 3daf44e..23fa03e 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Derivative/FeedBlock.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Derivative/FeedBlock.php @@ -11,6 +11,11 @@ class FeedBlock implements DerivativeInterface { * Implements DerivativeInterface::getDerivativeDefinition(). */ public function getDerivativeDefinition($derivative_id, array $base_plugin_definition) { + // TODO. This check is here for simpletest. See + // http://drupal.org/node/1821658 + if (!module_exists('aggregator')) { + return array(); + } if (!empty($this->derivatives) && !empty($this->derivatives[$derivative_id])) { return $this->derivatives[$derivative_id]; } @@ -25,9 +30,14 @@ public function getDerivativeDefinition($derivative_id, array $base_plugin_defin * Implements DerivativeInterface::getDerivativeDefinitions(). */ public function getDerivativeDefinitions(array $base_plugin_definition) { + // TODO. This check is here for simpletest. See + // http://drupal.org/node/1821658 + if (!module_exists('aggregator')) { + return array(); + } $result = db_query('SELECT fid, title FROM {aggregator_feed} WHERE block <> 0 ORDER BY fid'); foreach ($result as $feed) { - $this->derivatives[$feed->fid] = $this->config; + $this->derivatives[$feed->fid] = $base_plugin_definition; $this->derivatives[$feed->fid]['delta'] = $feed->fid; $this->derivatives[$feed->fid]['subject'] = t('@title feed latest items', array('@title' => $feed->title)); } diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/block/block/CategoryBlock.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/block/block/CategoryBlock.php index e65ad2a..c7cd27e 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/block/block/CategoryBlock.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/block/block/CategoryBlock.php @@ -39,7 +39,7 @@ public function configure($form, &$form_state) { $form['block_count'] = array( '#type' => 'select', '#title' => t('Number of news items in block'), - '#default_value' => $this->config['settings']['block_count'], + '#default_value' => $this->configuration['block_count'], '#options' => drupal_map_assoc(range(2, 20)), ); return $form; @@ -49,7 +49,7 @@ public function configure($form, &$form_state) { * Implements BlockInterface::configureSubmit(). */ public function configureSubmit($form, &$form_state) { - $this->config['settings']['block_count'] = $form_state['values']['block_count']; + $this->configuration['block_count'] = $form_state['values']['block_count']; } /** @@ -58,7 +58,7 @@ public function configureSubmit($form, &$form_state) { public function build() { $id = $this->getPluginId(); if ($category = db_query('SELECT cid, title, block FROM {aggregator_category} WHERE cid = :cid', array(':cid' => $id))->fetchObject()) { - $result = db_query_range('SELECT i.* FROM {aggregator_category_item} ci LEFT JOIN {aggregator_item} i ON ci.iid = i.iid WHERE ci.cid = :cid ORDER BY i.timestamp DESC, i.iid DESC', 0, $this->config['settings']['block_count'], array(':cid' => $category->cid)); + $result = db_query_range('SELECT i.* FROM {aggregator_category_item} ci LEFT JOIN {aggregator_item} i ON ci.iid = i.iid WHERE ci.cid = :cid ORDER BY i.timestamp DESC, i.iid DESC', 0, $this->configuration['block_count'], array(':cid' => $category->cid)); $read_more = theme('more_link', array('url' => 'aggregator/categories/' . $category->cid, 'title' => t("View this category's recent news."))); $items = array(); diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/block/block/FeedBlock.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/block/block/FeedBlock.php index db418ec..a2a0742 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/block/block/FeedBlock.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/block/block/FeedBlock.php @@ -39,7 +39,7 @@ public function configure($form, &$form_state) { $form['block_count'] = array( '#type' => 'select', '#title' => t('Number of news items in block'), - '#default_value' => $this->config['block_count'], + '#default_value' => $this->configuration['block_count'], '#options' => drupal_map_assoc(range(2, 20)), ); return $form; @@ -49,23 +49,23 @@ public function configure($form, &$form_state) { * Implements BlockInterface::configureSubmit(). */ public function configureSubmit($form, &$form_state) { - $this->config['block_count'] = $form_state['values']['block_count']; + $this->configuration['block_count'] = $form_state['values']['block_count']; } /** * Implements BlockInterface::build(). */ public function build() { - $id = $this->getPluginId(); + // Plugin ids look something like this: aggregator_feed_block:1. + $id = substr($this->getPluginId(), 22); if ($feed = db_query('SELECT fid, title, block FROM {aggregator_feed} WHERE block <> 0 AND fid = :fid', array(':fid' => $id))->fetchObject()) { - $result = db_query_range("SELECT * FROM {aggregator_item} WHERE fid = :fid ORDER BY timestamp DESC, iid DESC", 0, $this->config['block_count'], array(':fid' => $id)); + $result = db_query_range("SELECT * FROM {aggregator_item} WHERE fid = :fid ORDER BY timestamp DESC, iid DESC", 0, $this->configuration['block_count'], array(':fid' => $id)); $read_more = theme('more_link', array('url' => 'aggregator/sources/' . $feed->fid, 'title' => t("View this feed's recent news."))); $items = array(); foreach ($result as $item) { $items[] = theme('aggregator_block_item', array('item' => $item)); } - // Only display the block if there are items to show. if (count($items) > 0) { return array( diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorRenderingTest.php b/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorRenderingTest.php index 7f09317..60e999e 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorRenderingTest.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorRenderingTest.php @@ -27,7 +27,6 @@ public function testBlockLinks() { $feed = $this->createFeed(); $this->updateFeedItems($feed, $this->getDefaultFeedItemCount()); - // Place block on page (@see block.test:moveBlockToRegion()) // Need admin user to be able to access block admin. $this->admin_user = $this->drupalCreateUser(array( 'administer blocks', @@ -37,21 +36,17 @@ public function testBlockLinks() { )); $this->drupalLogin($this->admin_user); - // Prepare to use the block admin form. + $current_theme = variable_get('default_theme', 'stark'); + $machine_name = 'test_aggregator_feed_block'; $block = array( - 'module' => 'aggregator', - 'delta' => 'feed-' . $feed->fid, - 'title' => $feed->title, + 'machine_name' => $machine_name, + 'region' => 'footer', + 'title' => 'feed-' . $feed->title, + 'block_count' => 2, ); - $region = 'footer'; - $edit = array(); - $edit['blocks[' . $block['module'] . '_' . $block['delta'] . '][region]'] = $region; - // Check the feed block is available in the block list form. - $this->drupalGet('admin/structure/block'); - $this->assertFieldByName('blocks[' . $block['module'] . '_' . $block['delta'] . '][region]', '', 'Aggregator feed block is available for positioning.'); - // Position it. - $this->drupalPost('admin/structure/block', $edit, t('Save blocks')); - $this->assertText(t('The block settings have been updated.'), format_string('Block successfully moved to %region_name region.', array( '%region_name' => $region))); + $this->drupalPost("admin/structure/block/manage/aggregator_feed_block:{$feed->fid}/$current_theme", $block, t('Save block')); + $this->assertText(t('The block configuration has been saved.'), 'Block was saved.'); + // Confirm that the block is now being displayed on pages. $this->drupalGet('node'); $this->assertText(t($block['title']), 'Feed block is displayed on the page.'); diff --git a/core/modules/block/block.install b/core/modules/block/block.install index da301c1..520689b 100644 --- a/core/modules/block/block.install +++ b/core/modules/block/block.install @@ -75,7 +75,6 @@ function block_schema() { 'pages' => array( 'type' => 'text', 'not null' => TRUE, - 'default' => '', 'description' => 'Contents of the "Pages" block; contains either a list of paths on which to include/exclude the block or PHP code, depending on "visibility" setting.', ), 'title' => array( diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Derivative/CustomBlock.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Derivative/CustomBlock.php index 258a46c..f8d9d64 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Derivative/CustomBlock.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Derivative/CustomBlock.php @@ -11,6 +11,11 @@ class CustomBlock implements DerivativeInterface { * Implements DerivativeInterface::getDerivativeDefinition(). */ public function getDerivativeDefinition($derivative_id, array $base_plugin_definition) { + // TODO. This check is here for simpletest. See + // http://drupal.org/node/1821658 + if (!module_exists('custom_block')) { + return array(); + } if (!empty($this->derivatives) && !empty($this->derivatives[$derivative_id])) { return $this->derivatives[$derivative_id]; } @@ -22,6 +27,11 @@ public function getDerivativeDefinition($derivative_id, array $base_plugin_defin * Implements DerivativeInterface::getDerivativeDefinitions(). */ public function getDerivativeDefinitions(array $base_plugin_definition) { + // TODO. This check is here for simpletest. See + // http://drupal.org/node/1821658 + if (!module_exists('custom_block')) { + return array(); + } $results = db_select('block_custom', 'b') ->fields('b') ->execute(); @@ -40,4 +50,4 @@ public function getDerivativeDefinitions(array $base_plugin_definition) { $this->derivatives['custom_block'] = $base_plugin_definition; return $this->derivatives; } -} \ No newline at end of file +} diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockTest.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockTest.php new file mode 100644 index 0000000..8f0560f --- /dev/null +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockTest.php @@ -0,0 +1,427 @@ + 'Block functionality', + 'description' => 'Custom block functionality.', + 'group' => 'Block', + ); + } + + function setUp() { + parent::setUp(); + + // Use the test page as the front page. + config('system.site')->set('page.front', 'test-page')->save(); + + // Create Full HTML text format. + $full_html_format = array( + 'format' => 'full_html', + 'name' => 'Full HTML', + ); + $full_html_format = (object) $full_html_format; + filter_format_save($full_html_format); + $this->checkPermissions(array(), TRUE); + + // Create and log in an administrative user having access to the Full HTML + // text format. + $this->admin_user = $this->drupalCreateUser(array( + 'administer blocks', + filter_permission_name($full_html_format), + 'access administration pages', + )); + $this->drupalLogin($this->admin_user); + + // Define the existing regions + $this->regions = array(); + $this->regions[] = 'header'; + $this->regions[] = 'sidebar_first'; + $this->regions[] = 'content'; + $this->regions[] = 'sidebar_second'; + $this->regions[] = 'footer'; + } + + /** + * Test creating custom block, moving it to a specific region and then deleting it. + */ + function testCustomBlock() { + // Enable a second theme. + theme_enable(array('seven')); + + // Confirm that the add block link appears on block overview pages. + $this->drupalGet('admin/structure/block'); + $this->assertRaw(l('Add block', 'admin/structure/block/add'), 'Add block link is present on block overview page for default theme.'); + $this->drupalGet('admin/structure/block/list/seven'); + $this->assertRaw(l('Add block', 'admin/structure/block/list/seven/add'), 'Add block link is present on block overview page for non-default theme.'); + + // Confirm that hidden regions are not shown as options for block placement + // when adding a new block. + theme_enable(array('bartik')); + $themes = list_themes(); + $this->drupalGet('admin/structure/block/add'); + foreach ($themes as $key => $theme) { + if ($theme->status) { + foreach ($theme->info['regions_hidden'] as $hidden_region) { + $elements = $this->xpath('//select[@id=:id]//option[@value=:value]', array(':id' => 'edit-regions-' . $key, ':value' => $hidden_region)); + $this->assertFalse(isset($elements[0]), format_string('The hidden region @region is not available for @theme.', array('@region' => $hidden_region, '@theme' => $key))); + } + } + } + + // Add a new custom block by filling out the input form on the admin/structure/block/add page. + $custom_block = array(); + $custom_block['info'] = $this->randomName(8); + $custom_block['title'] = $this->randomName(8); + $custom_block['body[value]'] = $this->randomName(32); + $this->drupalPost('admin/structure/block/add', $custom_block, t('Save block')); + + // Confirm that the custom block has been created, and then query the created bid. + $this->assertText(t('The block has been created.'), 'Custom block successfully created.'); + $bid = db_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchField(); + + // Check to see if the custom block was created by checking that it's in the database. + $this->assertNotNull($bid, 'Custom block found in database'); + + // Check that block_block_view() returns the correct title and content. + $data = block_block_view($bid); + $format = db_query("SELECT format FROM {block_custom} WHERE bid = :bid", array(':bid' => $bid))->fetchField(); + $this->assertTrue(array_key_exists('subject', $data) && empty($data['subject']), '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'], 'block_block_view() provides correct block content.'); + + // Check whether the block can be moved to all available regions. + $custom_block['module'] = 'block'; + $custom_block['delta'] = $bid; + foreach ($this->regions as $region) { + $this->moveBlockToRegion($custom_block, $region); + } + + // Verify presence of configure and delete links for custom block. + $this->drupalGet('admin/structure/block'); + $this->assertLinkByHref('admin/structure/block/manage/block/' . $bid . '/configure', 0, 'Custom block configure link found.'); + $this->assertLinkByHref('admin/structure/block/manage/block/' . $bid . '/delete', 0, 'Custom block delete link found.'); + + // Set visibility only for authenticated users, to verify delete functionality. + $edit = array(); + $edit['roles[' . DRUPAL_AUTHENTICATED_RID . ']'] = TRUE; + $this->drupalPost('admin/structure/block/manage/block/' . $bid . '/configure', $edit, t('Save block')); + + // Delete the created custom block & verify that it's been deleted and no longer appearing on the page. + $this->clickLink(t('delete')); + $this->drupalPost('admin/structure/block/manage/block/' . $bid . '/delete', array(), t('Delete')); + $this->assertRaw(t('The block %title has been removed.', array('%title' => $custom_block['info'])), 'Custom block successfully deleted.'); + $this->assertNoText(t($custom_block['title']), 'Custom block no longer appears on page.'); + $count = db_query("SELECT 1 FROM {block_role} WHERE module = :module AND delta = :delta", array(':module' => $custom_block['module'], ':delta' => $custom_block['delta']))->fetchField(); + $this->assertFalse($count, 'Table block_role being cleaned.'); + } + + /** + * Test creating custom block using Full HTML. + */ + function testCustomBlockFormat() { + // Add a new custom block by filling out the input form on the admin/structure/block/add page. + $custom_block = array(); + $custom_block['info'] = $this->randomName(8); + $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; + $this->drupalPost('admin/structure/block/add', $custom_block, t('Save block')); + + // Set the created custom block to a specific region. + $bid = db_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchField(); + $edit = array(); + $edit['blocks[block_' . $bid . '][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. + $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. + $block_admin = $this->drupalCreateUser(array('administer blocks')); + $this->drupalLogin($block_admin); + $this->drupalGet('admin/structure/block/manage/block/' . $bid . '/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('admin/structure/block/manage/block/' . $bid . '/configure', array(), t('Save block')); + $this->assertNoText(t('Ensure that each block description is unique.')); + + // 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.'); + } + + /** + * Test block visibility. + */ + function testBlockVisibility() { + $block = array(); + + // Create a random title for the block + $title = $this->randomName(8); + + // Create the custom block + $custom_block = array(); + $custom_block['info'] = $this->randomName(8); + $custom_block['title'] = $title; + $custom_block['body[value]'] = $this->randomName(32); + $this->drupalPost('admin/structure/block/add', $custom_block, t('Save block')); + + $bid = db_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchField(); + $block['module'] = 'block'; + $block['delta'] = $bid; + $block['title'] = $title; + + // Set the block to be hidden on any user path, and to be shown only to + // authenticated users. + $edit = array(); + $edit['pages'] = 'user*'; + $edit['roles[' . DRUPAL_AUTHENTICATED_RID . ']'] = TRUE; + $this->drupalPost('admin/structure/block/manage/' . $block['module'] . '/' . $block['delta'] . '/configure', $edit, t('Save block')); + + // Move block to the first sidebar. + $this->moveBlockToRegion($block, $this->regions[1]); + + $this->drupalGet(''); + $this->assertText($title, 'Block was displayed on the front page.'); + + $this->drupalGet('user'); + $this->assertNoText($title, 'Block was not displayed according to block visibility rules.'); + + $this->drupalGet('USER/' . $this->admin_user->uid); + $this->assertNoText($title, 'Block was not displayed according to block visibility rules regardless of path case.'); + + // Confirm that the block is not displayed to anonymous users. + $this->drupalLogout(); + $this->drupalGet(''); + $this->assertNoText($title, 'Block was not displayed to anonymous users.'); + + // Confirm that an empty block is not displayed. + $this->assertNoRaw('block-system-help', 'Empty block not displayed.'); + } + + /** + * Test block visibility when using "pages" restriction but leaving + * "pages" textarea empty + */ + function testBlockVisibilityListedEmpty() { + $block = array(); + + // Create a random title for the block + $title = $this->randomName(8); + + // Create the custom block + $custom_block = array(); + $custom_block['info'] = $this->randomName(8); + $custom_block['title'] = $title; + $custom_block['body[value]'] = $this->randomName(32); + $this->drupalPost('admin/structure/block/add', $custom_block, t('Save block')); + + $bid = db_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchField(); + $block['module'] = 'block'; + $block['delta'] = $bid; + $block['title'] = $title; + + // Move block to the first sidebar. + $this->moveBlockToRegion($block, $this->regions[1]); + + // Set the block to be hidden on any user path, and to be shown only to + // authenticated users. + $edit = array(); + $edit['visibility'] = BLOCK_VISIBILITY_LISTED; + $this->drupalPost('admin/structure/block/manage/' . $block['module'] . '/' . $block['delta'] . '/configure', $edit, t('Save block')); + + $this->drupalGet('user'); + $this->assertNoText($title, 'Block was not displayed according to block visibility rules.'); + + $this->drupalGet('USER'); + $this->assertNoText($title, 'Block was not displayed according to block visibility rules regardless of path case.'); + + // Confirm that the block is not displayed to anonymous users. + $this->drupalLogout(); + $this->drupalGet(''); + $this->assertNoText($title, 'Block was not displayed to anonymous users on the front page.'); + } + + /** + * Test user customization of block visibility. + */ + function testBlockVisibilityPerUser() { + $block = array(); + + // Create a random title for the block. + $title = $this->randomName(8); + + // Create our custom test block. + $custom_block = array(); + $custom_block['info'] = $this->randomName(8); + $custom_block['title'] = $title; + $custom_block['body[value]'] = $this->randomName(32); + $this->drupalPost('admin/structure/block/add', $custom_block, t('Save block')); + + $bid = db_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchField(); + $block['module'] = 'block'; + $block['delta'] = $bid; + $block['title'] = $title; + + // Move block to the first sidebar. + $this->moveBlockToRegion($block, $this->regions[1]); + + // Set the block to be customizable per user, visible by default. + $edit = array(); + $edit['custom'] = BLOCK_CUSTOM_ENABLED; + $this->drupalPost('admin/structure/block/manage/' . $block['module'] . '/' . $block['delta'] . '/configure', $edit, t('Save block')); + + // Disable block visibility for the admin user. + $edit = array(); + $edit['block[' . $block['module'] . '][' . $block['delta'] . ']'] = FALSE; + $this->drupalPost('user/' . $this->admin_user->uid . '/edit', $edit, t('Save')); + + $this->drupalGet('user'); + $this->assertNoText($block['title'], 'Block was not displayed according to per user block visibility setting.'); + + // Set the block to be customizable per user, hidden by default. + $edit = array(); + $edit['custom'] = BLOCK_CUSTOM_DISABLED; + $this->drupalPost('admin/structure/block/manage/' . $block['module'] . '/' . $block['delta'] . '/configure', $edit, t('Save block')); + + // Enable block visibility for the admin user. + $edit = array(); + $edit['block[' . $block['module'] . '][' . $block['delta'] . ']'] = TRUE; + $this->drupalPost('user/' . $this->admin_user->uid . '/edit', $edit, t('Save')); + + $this->drupalGet('user'); + $this->assertText($block['title'], 'Block was displayed according to per user block visibility setting.'); + } + + /** + * Test configuring and moving a module-define block to specific regions. + */ + function testBlock() { + // Select the 'Powered by Drupal' block to be configured and moved. + $block = array(); + $block['id'] = 'system_powered_by_block'; + $block['title'] = $this->randomName(8); + $block['machine_name'] = $this->randomName(8); + $block['theme'] = variable_get('theme_default', 'stark'); + $block['region'] = 'header'; + + // Set block title to confirm that interface works and override any custom titles. + $this->drupalPost('admin/structure/block/manage/' . $block['id'] . '/' . $block['theme'], array('title' => $block['title'], 'machine_name' => $block['machine_name'], 'region' => $block['region']), t('Save block')); + $this->assertText(t('The block configuration has been saved.'), 'Block title set.'); + // Check to see if the block was created by checking its configuration. + $block['config_id'] = 'plugin.core.block.' . $block['theme'] . '.' . $block['machine_name']; + $instance = block_load($block['config_id']); + $config = $instance->getConfig(); + + $this->assertEqual($config['subject'], $block['title'], t('Stored block title found.')); + + // Check whether the block can be moved to all available regions. + foreach ($this->regions as $region) { + $this->moveBlockToRegion($block, $region); + } + + // Set the block to the disabled region. + $edit = array(); + $edit['blocks[0][region]'] = -1; + $this->drupalPost('admin/structure/block', $edit, t('Save blocks')); + + // Confirm that the block was moved to the proper region. + $this->assertText(t('The block settings have been updated.'), 'Block successfully move to disabled region.'); + $this->drupalGet('node'); + $this->assertNoText(t($block['title']), 'Block no longer appears on page.'); + + // Confirm that the region's xpath is not available. + $xpath = $this->buildXPathQuery('//div[@id=:id]/*', array(':id' => 'block-' . strtr(strtolower($block['machine_name']), '-', '_'))); + $this->assertNoFieldByXPath($xpath, FALSE, t('Block found in no regions.')); + } + + /** + * Moves a block to a given region via the UI and confirms the result. + * + * @param array $block + * An array of information about the block, including the following keys: + * - module: The module providing the block. + * - title: The title of the block. + * - delta: The block's delta key. + * @param string $region + * The machine name of the theme region to move the block to, for example + * 'header' or 'sidebar_first'. + */ + function moveBlockToRegion(array $block, $region) { + // Set the created block to a specific region. + $edit = array(); + $edit['blocks[0][region]'] = $region; + $this->drupalPost('admin/structure/block', $edit, t('Save blocks')); + + // Confirm that the block was moved to the proper region. + $this->assertText(t('The block settings have been updated.'), format_string('Block successfully moved to %region_name region.', array( '%region_name' => $region))); + + // Confirm that the block is being displayed. + $this->drupalGet(''); + $this->assertText(t($block['title']), 'Block successfully being displayed on the page.'); + + // Confirm that the custom block was found at the proper region. + $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($block['machine_name']), '-', '_'), + )); + $this->assertFieldByXPath($xpath, NULL, t('Block found in %region_name region.', array('%region_name' => drupal_html_class($region)))); + } + + /** + * Test _block_rehash(). + */ + function testBlockRehash() { + module_enable(array('block_test')); + $this->assertTrue(module_exists('block_test'), 'Test block module enabled.'); + + // Add a test block. + $plugin = block_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')); + + // Our test block's caching should default to DRUPAL_CACHE_PER_ROLE. + $block['config_id'] = 'plugin.core.block.' . $block['theme'] . '.' . $block['machine_name']; + $instance = block_load($block['config_id']); + $config = $instance->getConfig(); + $this->assertEqual($config['cache'], DRUPAL_CACHE_PER_ROLE, t('Test block cache mode defaults to DRUPAL_CACHE_PER_ROLE.')); + + // Disable caching for this block. + $block_config = config($block['config_id']); + $block_config->set('cache', DRUPAL_NO_CACHE); + $block_config->save(); + // Flushing all caches should call _block_rehash(). + $this->resetAll(); + // Verify that block is updated with the new caching mode. + $instance = block_load($block['config_id']); + $config = $instance->getConfig(); + $this->assertEqual($config['cache'], DRUPAL_NO_CACHE, t("Test block's database entry updated to DRUPAL_NO_CACHE.")); + } +} diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockCacheTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockCacheTest.php index ebaa4c0..6bbccdf 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockCacheTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockCacheTest.php @@ -49,13 +49,12 @@ function setUp() { $this->normal_user_alt->save(); // Enable our test block. + $this->theme = variable_get('theme_default', 'stark'); $block = array(); - $block['id'] = 'test_cache'; $block['machine_name'] = $this->randomName(8); - $block['theme'] = variable_get('theme_default', 'stark'); $block['region'] = 'sidebar_first'; $this->block = $block; - $this->drupalPost('admin/structure/block/manage/' . $block['id'] . '/' . $block['theme'], array('machine_name' => $block['machine_name'], 'region' => $block['region']), t('Save block')); + $this->drupalPost('admin/structure/block/manage/test_cache/' . $this->theme, $block, t('Save block')); } /** @@ -198,7 +197,7 @@ function testCachePerPage() { */ private function setCacheMode($cache_mode) { $block = $this->block; - $block['config_id'] = 'plugin.core.block.' . $block['theme'] . '.' . $block['machine_name']; + $block['config_id'] = 'plugin.core.block.' . $this->theme . '.' . $block['machine_name']; $block_config = config($block['config_id']); $block_config->set('cache', $cache_mode); $block_config->save(); diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockHiddenRegionTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockHiddenRegionTest.php index af5acb9..ecfade3 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockHiddenRegionTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockHiddenRegionTest.php @@ -14,6 +14,7 @@ */ class BlockHiddenRegionTest extends WebTestBase { + protected $admin_user; /** * Modules to enable. * @@ -32,30 +33,31 @@ public static function getInfo() { function setUp() { parent::setUp(); - // Enable Search block in default theme. - db_merge('block') - ->key(array( - 'module' => 'search', - 'delta' => 'form', - 'theme' => variable_get('theme_default', 'stark'), - )) - ->fields(array( - 'status' => 1, - 'weight' => -1, - 'region' => 'sidebar_first', - 'pages' => '', - 'cache' => -1, - )) - ->execute(); + // Create administrative user. + $this->admin_user = $this->drupalCreateUser(array( + 'administer blocks', + 'administer themes', + 'search content', + ) + ); + + $this->drupalLogin($this->admin_user); + + $default_theme = variable_get('theme_default', 'stark'); + + $block['machine_name'] = $this->randomName(); + $block['region'] = 'sidebar_first'; + $block['title'] = $this->randomName(); + $this->drupalPost('admin/structure/block/manage/search_form_block/' . $default_theme, $block, t('Save block')); + $this->assertText('The block configuration has been saved.', 'Block was saved'); } /** * Tests that hidden regions do not inherit blocks when a theme is enabled. */ - function testBlockNotInHiddenRegion() { - // Create administrative user. - $admin_user = $this->drupalCreateUser(array('administer blocks', 'administer themes', 'search content')); - $this->drupalLogin($admin_user); + public function testBlockNotInHiddenRegion() { + + $this->drupalLogin($this->admin_user); // Ensure that the search form block is displayed. $this->drupalGet(''); diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockHtmlIdTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockHtmlIdTest.php index c537eec..91cc7c1 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockHtmlIdTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockHtmlIdTest.php @@ -14,6 +14,8 @@ */ class BlockHtmlIdTest extends WebTestBase { + protected $adminUser; + /** * Modules to enable. * @@ -33,23 +35,19 @@ function setUp() { parent::setUp(); // Create an admin user, log in and enable test blocks. - $this->admin_user = $this->drupalCreateUser(array('administer blocks', 'access administration pages')); - $this->drupalLogin($this->admin_user); + $this->adminUser = $this->drupalCreateUser(array('administer blocks', 'access administration pages')); + $this->drupalLogin($this->adminUser); + + // Make sure the block has some content so it will appear. + $current_content = $this->randomName(); + variable_set('block_test_content', $current_content); // Enable our test block. + $default_theme = variable_get('theme_default', 'stark'); $block = array(); - $block['id'] = 'test_html_id'; - $block['machine_name'] = $this->randomName(8); - $block['theme'] = variable_get('theme_default', 'stark'); + $block['machine_name'] = 'test_id_block'; $block['region'] = 'sidebar_first'; - $this->block = $block; - $this->drupalPost('admin/structure/block/manage/' . $block['id'] . '/' . $block['theme'], array('machine_name' => $block['machine_name'], 'region' => $block['region']), t('Save block')); - - // Make sure the block has some content so it will appear - $current_content = $this->randomName(); - variable_set('block_test_content', $current_content); - // TODO: This block is being cached. Should it be? - $this->resetAll(); + $this->drupalPost('admin/structure/block/manage/test_html_id' . '/' . $default_theme, array('machine_name' => $block['machine_name'], 'region' => $block['region']), t('Save block')); } /** @@ -57,6 +55,6 @@ function setUp() { */ function testHtmlId() { $this->drupalGet(''); - $this->assertRaw('block-block-test-test-html-id', 'HTML id for test block is valid.'); + $this->assertRaw('id="block-test-id-block"', 'HTML id for test block is valid.'); } } diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockLanguageTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockLanguageTest.php index 6d0c6bc..927d217 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockLanguageTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockLanguageTest.php @@ -14,6 +14,7 @@ */ class BlockLanguageTest extends WebTestBase { + protected $adminUser; /** * Modules to enable. * @@ -29,15 +30,12 @@ public static function getInfo() { ); } - /** - * Tests the visibility settings for the blocks based on language. - */ - public function testLanguageBlockVisibility() { + function setUp() { + parent::setUp(); + // Create a new user, allow him to manage the blocks and the languages. - $admin_user = $this->drupalCreateUser(array( - 'administer languages', 'administer blocks', - )); - $this->drupalLogin($admin_user); + $this->adminUser = $this->drupalCreateUser(array('administer blocks', 'administer languages')); + $this->drupalLogin($this->adminUser); // Add predefined language. $edit = array( @@ -45,156 +43,69 @@ public function testLanguageBlockVisibility() { ); $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language')); $this->assertText('French', 'Language added successfully.'); + } + /** + * Tests the visibility settings for the blocks based on language. + */ + public function testLanguageBlockVisibility() { // Check if the visibility setting is available. - $this->drupalGet('admin/structure/block/add'); - $this->assertField('langcodes[en]', 'Language visibility field is visible.'); - - // Create a new block. - $info_name = $this->randomString(10); - $body = ''; - for ($i = 0; $i <= 100; $i++) { - $body .= chr(rand(97, 122)); - } - $edit = array( - 'regions[stark]' => 'sidebar_first', - 'info' => $info_name, - 'title' => 'test', - 'body[value]' => $body, - ); - $this->drupalPost('admin/structure/block/add', $edit, t('Save block')); + $default_theme = variable_get('theme_default', 'stark'); + $this->drupalGet('admin/structure/block/manage/system_powered_by_block' . '/' . $default_theme); + + $this->assertField('visibility[language][langcodes][en]', 'Language visibility field is visible.'); - // Set visibility setting for one language. + // Enable a standard block and set the visibility setting for one language. $edit = array( - 'langcodes[en]' => TRUE, + 'visibility[language][langcodes][en]' => TRUE, + 'machine_name' => $this->randomName(8), + 'region' => 'sidebar_first', ); - $this->drupalPost('admin/structure/block/manage/block/1/configure', $edit, t('Save block')); + $this->drupalPost('admin/structure/block/manage/system_powered_by_block' . '/' . $default_theme, $edit, t('Save block')); // Change the default language. $edit = array( 'site_default' => 'fr', ); - $this->drupalPost('admin/config/regional/language', $edit, t('Save configuration')); + $this->drupalpost('admin/config/regional/language', $edit, t('Save configuration')); // Reset the static cache of the language list. drupal_static_reset('language_list'); - // Check that a page has a block - $this->drupalGet('', array('language' => language_load('en'))); - $this->assertText($body, 'The body of the custom block appears on the page.'); + // Check that a page has a block. + $this->drupalget('', array('language' => language_load('en'))); + $this->assertText('Powered by Drupal', 'The body of the custom block appears on the page.'); - // Check that a page doesn't has a block for the current language anymore + // Check that a page doesn't has a block for the current language anymore. $this->drupalGet('', array('language' => language_load('fr'))); - $this->assertNoText($body, 'The body of the custom block does not appear on the page.'); + $this->assertNoText('Powered by Drupal', 'The body of the custom block does not appear on the page.'); } /** * Tests if the visibility settings are removed if the language is deleted. */ public function testLanguageBlockVisibilityLanguageDelete() { - // Create a new user, allow him to manage the blocks and the languages. - $admin_user = $this->drupalCreateUser(array( - 'administer languages', 'administer blocks', - )); - $this->drupalLogin($admin_user); - - // Add predefined language. - $edit = array( - 'predefined_langcode' => 'fr', - ); - $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language')); - $this->assertText('French', 'Language added successfully.'); - // Create a new block. - $info_name = $this->randomString(10); - $body = ''; - for ($i = 0; $i <= 100; $i++) { - $body .= chr(rand(97, 122)); - } + $default_theme = variable_get('theme_default', 'stark'); + // Enable a standard block and set the visibility setting for one language. $edit = array( - 'regions[stark]' => 'sidebar_first', - 'info' => $info_name, - 'title' => 'test', - 'body[value]' => $body, + 'visibility[language][langcodes][fr]' => TRUE, + 'machine_name' => 'language_block_test', + 'region' => 'sidebar_first', ); - $this->drupalPost('admin/structure/block/add', $edit, t('Save block')); + $this->drupalPost('admin/structure/block/manage/system_powered_by_block' . '/' . $default_theme, $edit, t('Save block')); - // Set visibility setting for one language. - $edit = array( - 'langcodes[fr]' => TRUE, - ); - $this->drupalPost('admin/structure/block/manage/block/1/configure', $edit, t('Save block')); - - // Check that we have an entry in the database after saving the setting. - $count = db_query('SELECT COUNT(langcode) FROM {block_language} WHERE module = :module AND delta = :delta', array( - ':module' => 'block', - ':delta' => '1' - ))->fetchField(); - $this->assertTrue($count == 1, 'The block language visibility has an entry in the database.'); + // Check that we have the language in config fter saving the setting. + $config = config('plugin.core.block.' . $default_theme . '.language_block_test'); + $setting = $config->get('visibility.language.langcodes.fr'); + $this->assertTrue('fr' === $setting, 'Language was set in the block config.'); // Delete the language. $this->drupalPost('admin/config/regional/language/delete/fr', array(), t('Delete')); - // Check that the setting related to this language has been deleted. - $count = db_query('SELECT COUNT(langcode) FROM {block_language} WHERE module = :module AND delta = :delta', array( - ':module' => 'block', - ':delta' => '1' - ))->fetchField(); - $this->assertTrue($count == 0, 'The block language visibility do not have an entry in the database.'); - } - - /** - * Tests if the visibility settings are removed if the block is deleted. - */ - public function testLanguageBlockVisibilityBlockDelete() { - // Create a new user, allow him to manage the blocks and the languages. - $admin_user = $this->drupalCreateUser(array( - 'administer languages', 'administer blocks', - )); - $this->drupalLogin($admin_user); - - // Add predefined language. - $edit = array( - 'predefined_langcode' => 'fr', - ); - $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language')); - $this->assertText('French', 'Language added successfully.'); - - // Create a new block. - $info_name = $this->randomString(10); - $body = ''; - for ($i = 0; $i <= 100; $i++) { - $body .= chr(rand(97, 122)); - } - $edit = array( - 'regions[stark]' => 'sidebar_first', - 'info' => $info_name, - 'title' => 'test', - 'body[value]' => $body, - ); - $this->drupalPost('admin/structure/block/add', $edit, t('Save block')); - - // Set visibility setting for one language. - $edit = array( - 'langcodes[fr]' => TRUE, - ); - $this->drupalPost('admin/structure/block/manage/block/1/configure', $edit, t('Save block')); - - // Check that we have an entry in the database after saving the setting. - $count = db_query('SELECT COUNT(langcode) FROM {block_language} WHERE module = :module AND delta = :delta', array( - ':module' => 'block', - ':delta' => '1' - ))->fetchField(); - $this->assertTrue($count == 1, 'The block language visibility has an entry in the database.'); - - // Delete the custom block. - $this->drupalPost('admin/structure/block/manage/block/1/delete', array(), t('Delete')); - - // Check that the setting related to this block has been deleted. - $count = db_query('SELECT COUNT(langcode) FROM {block_language} WHERE module = :module AND delta = :delta', array( - ':module' => 'block', - ':delta' => '1' - ))->fetchField(); - $this->assertTrue($count == 0, 'The block language visibility do not have an entry in the database.'); + // Check that we have the language in config fter saving the setting. + $config = config('plugin.core.block.' . $default_theme . '.language_block_test'); + $setting = $config->get('visibility.language.langcodes.fr'); + $this->assertFalse('fr' === $setting, 'Language was not set in the block config.'); } } diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php index 84bf6e2..5dc5378 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php @@ -19,7 +19,7 @@ class BlockTest extends WebTestBase { public static $modules = array('block', 'test_page_test'); protected $regions; - protected $admin_user; + protected $adminUser; public static function getInfo() { return array( @@ -35,25 +35,15 @@ function setUp() { // Use the test page as the front page. config('system.site')->set('page.front', 'test-page')->save(); - // Create Full HTML text format. - $full_html_format = array( - 'format' => 'full_html', - 'name' => 'Full HTML', - ); - $full_html_format = (object) $full_html_format; - filter_format_save($full_html_format); - $this->checkPermissions(array(), TRUE); - // Create and log in an administrative user having access to the Full HTML // text format. - $this->admin_user = $this->drupalCreateUser(array( + $this->adminUser = $this->drupalCreateUser(array( 'administer blocks', - filter_permission_name($full_html_format), 'access administration pages', )); - $this->drupalLogin($this->admin_user); + $this->drupalLogin($this->adminUser); - // Define the existing regions + // Define the existing regions. $this->regions = array(); $this->regions[] = 'header'; $this->regions[] = 'sidebar_first'; @@ -63,145 +53,25 @@ function setUp() { } /** - * Test creating custom block, moving it to a specific region and then deleting it. - */ - function testCustomBlock() { - // Enable a second theme. - theme_enable(array('seven')); - - // Confirm that the add block link appears on block overview pages. - $this->drupalGet('admin/structure/block'); - $this->assertRaw(l('Add block', 'admin/structure/block/add'), 'Add block link is present on block overview page for default theme.'); - $this->drupalGet('admin/structure/block/list/seven'); - $this->assertRaw(l('Add block', 'admin/structure/block/list/seven/add'), 'Add block link is present on block overview page for non-default theme.'); - - // Confirm that hidden regions are not shown as options for block placement - // when adding a new block. - theme_enable(array('bartik')); - $themes = list_themes(); - $this->drupalGet('admin/structure/block/add'); - foreach ($themes as $key => $theme) { - if ($theme->status) { - foreach ($theme->info['regions_hidden'] as $hidden_region) { - $elements = $this->xpath('//select[@id=:id]//option[@value=:value]', array(':id' => 'edit-regions-' . $key, ':value' => $hidden_region)); - $this->assertFalse(isset($elements[0]), format_string('The hidden region @region is not available for @theme.', array('@region' => $hidden_region, '@theme' => $key))); - } - } - } - - // Add a new custom block by filling out the input form on the admin/structure/block/add page. - $custom_block = array(); - $custom_block['info'] = $this->randomName(8); - $custom_block['title'] = $this->randomName(8); - $custom_block['body[value]'] = $this->randomName(32); - $this->drupalPost('admin/structure/block/add', $custom_block, t('Save block')); - - // Confirm that the custom block has been created, and then query the created bid. - $this->assertText(t('The block has been created.'), 'Custom block successfully created.'); - $bid = db_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchField(); - - // Check to see if the custom block was created by checking that it's in the database. - $this->assertNotNull($bid, 'Custom block found in database'); - - // Check that block_block_view() returns the correct title and content. - $data = block_block_view($bid); - $format = db_query("SELECT format FROM {block_custom} WHERE bid = :bid", array(':bid' => $bid))->fetchField(); - $this->assertTrue(array_key_exists('subject', $data) && empty($data['subject']), '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'], 'block_block_view() provides correct block content.'); - - // Check whether the block can be moved to all available regions. - $custom_block['module'] = 'block'; - $custom_block['delta'] = $bid; - foreach ($this->regions as $region) { - $this->moveBlockToRegion($custom_block, $region); - } - - // Verify presence of configure and delete links for custom block. - $this->drupalGet('admin/structure/block'); - $this->assertLinkByHref('admin/structure/block/manage/block/' . $bid . '/configure', 0, 'Custom block configure link found.'); - $this->assertLinkByHref('admin/structure/block/manage/block/' . $bid . '/delete', 0, 'Custom block delete link found.'); - - // Set visibility only for authenticated users, to verify delete functionality. - $edit = array(); - $edit['roles[' . DRUPAL_AUTHENTICATED_RID . ']'] = TRUE; - $this->drupalPost('admin/structure/block/manage/block/' . $bid . '/configure', $edit, t('Save block')); - - // Delete the created custom block & verify that it's been deleted and no longer appearing on the page. - $this->clickLink(t('delete')); - $this->drupalPost('admin/structure/block/manage/block/' . $bid . '/delete', array(), t('Delete')); - $this->assertRaw(t('The block %title has been removed.', array('%title' => $custom_block['info'])), 'Custom block successfully deleted.'); - $this->assertNoText(t($custom_block['title']), 'Custom block no longer appears on page.'); - $count = db_query("SELECT 1 FROM {block_role} WHERE module = :module AND delta = :delta", array(':module' => $custom_block['module'], ':delta' => $custom_block['delta']))->fetchField(); - $this->assertFalse($count, 'Table block_role being cleaned.'); - } - - /** - * Test creating custom block using Full HTML. - */ - function testCustomBlockFormat() { - // Add a new custom block by filling out the input form on the admin/structure/block/add page. - $custom_block = array(); - $custom_block['info'] = $this->randomName(8); - $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; - $this->drupalPost('admin/structure/block/add', $custom_block, t('Save block')); - - // Set the created custom block to a specific region. - $bid = db_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchField(); - $edit = array(); - $edit['blocks[block_' . $bid . '][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. - $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. - $block_admin = $this->drupalCreateUser(array('administer blocks')); - $this->drupalLogin($block_admin); - $this->drupalGet('admin/structure/block/manage/block/' . $bid . '/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('admin/structure/block/manage/block/' . $bid . '/configure', array(), t('Save block')); - $this->assertNoText(t('Ensure that each block description is unique.')); - - // 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.'); - } - - /** * Test block visibility. */ function testBlockVisibility() { - $block = array(); - - // Create a random title for the block + $block_name = 'system_powered_by_block'; + // Create a random title for the block, $title = $this->randomName(8); - - // Create the custom block - $custom_block = array(); - $custom_block['info'] = $this->randomName(8); - $custom_block['title'] = $title; - $custom_block['body[value]'] = $this->randomName(32); - $this->drupalPost('admin/structure/block/add', $custom_block, t('Save block')); - - $bid = db_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchField(); - $block['module'] = 'block'; - $block['delta'] = $bid; - $block['title'] = $title; - + // Enable a standard block. + $default_theme = variable_get('theme_default', 'stark'); + $edit = array( + 'machine_name' => $this->randomName(8), + 'region' => 'sidebar_first', + 'title' => $title, + ); // Set the block to be hidden on any user path, and to be shown only to // authenticated users. - $edit = array(); - $edit['pages'] = 'user*'; - $edit['roles[' . DRUPAL_AUTHENTICATED_RID . ']'] = TRUE; - $this->drupalPost('admin/structure/block/manage/' . $block['module'] . '/' . $block['delta'] . '/configure', $edit, t('Save block')); - - // Move block to the first sidebar. - $this->moveBlockToRegion($block, $this->regions[1]); + $edit['visibility[path][pages]'] = 'user*'; + $edit['visibility[role][roles][' . DRUPAL_AUTHENTICATED_RID . ']'] = TRUE; + $this->drupalPost('admin/structure/block/manage/' . $block_name . '/' . $default_theme, $edit, t('Save block')); + $this->assertText('The block configuration has been saved.', 'Block was saved'); $this->drupalGet(''); $this->assertText($title, 'Block was displayed on the front page.'); @@ -209,7 +79,7 @@ function testBlockVisibility() { $this->drupalGet('user'); $this->assertNoText($title, 'Block was not displayed according to block visibility rules.'); - $this->drupalGet('USER/' . $this->admin_user->uid); + $this->drupalGet('USER/' . $this->adminUser->uid); $this->assertNoText($title, 'Block was not displayed according to block visibility rules regardless of path case.'); // Confirm that the block is not displayed to anonymous users. @@ -218,7 +88,7 @@ function testBlockVisibility() { $this->assertNoText($title, 'Block was not displayed to anonymous users.'); // Confirm that an empty block is not displayed. - $this->assertNoRaw('block-system-help', 'Empty block not displayed.'); + $this->assertNoText('Powered by Drupal', 'Empty block not displayed.'); } /** @@ -226,31 +96,21 @@ function testBlockVisibility() { * "pages" textarea empty */ function testBlockVisibilityListedEmpty() { - $block = array(); - - // Create a random title for the block + $block_name = 'system_powered_by_block'; + // Create a random title for the block, $title = $this->randomName(8); - - // Create the custom block - $custom_block = array(); - $custom_block['info'] = $this->randomName(8); - $custom_block['title'] = $title; - $custom_block['body[value]'] = $this->randomName(32); - $this->drupalPost('admin/structure/block/add', $custom_block, t('Save block')); - - $bid = db_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchField(); - $block['module'] = 'block'; - $block['delta'] = $bid; - $block['title'] = $title; - - // Move block to the first sidebar. - $this->moveBlockToRegion($block, $this->regions[1]); - + // Enable a standard block. + $default_theme = variable_get('theme_default', 'stark'); + $edit = array( + 'machine_name' => $this->randomName(8), + 'region' => 'sidebar_first', + 'title' => $title, + 'visibility[path][visibility]' => BLOCK_VISIBILITY_LISTED, + ); // Set the block to be hidden on any user path, and to be shown only to // authenticated users. - $edit = array(); - $edit['visibility'] = BLOCK_VISIBILITY_LISTED; - $this->drupalPost('admin/structure/block/manage/' . $block['module'] . '/' . $block['delta'] . '/configure', $edit, t('Save block')); + $this->drupalPost('admin/structure/block/manage/' . $block_name . '/' . $default_theme, $edit, t('Save block')); + $this->assertText('The block configuration has been saved.', 'Block was saved'); $this->drupalGet('user'); $this->assertNoText($title, 'Block was not displayed according to block visibility rules.'); @@ -265,77 +125,28 @@ function testBlockVisibilityListedEmpty() { } /** - * Test user customization of block visibility. - */ - function testBlockVisibilityPerUser() { - $block = array(); - - // Create a random title for the block. - $title = $this->randomName(8); - - // Create our custom test block. - $custom_block = array(); - $custom_block['info'] = $this->randomName(8); - $custom_block['title'] = $title; - $custom_block['body[value]'] = $this->randomName(32); - $this->drupalPost('admin/structure/block/add', $custom_block, t('Save block')); - - $bid = db_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchField(); - $block['module'] = 'block'; - $block['delta'] = $bid; - $block['title'] = $title; - - // Move block to the first sidebar. - $this->moveBlockToRegion($block, $this->regions[1]); - - // Set the block to be customizable per user, visible by default. - $edit = array(); - $edit['custom'] = BLOCK_CUSTOM_ENABLED; - $this->drupalPost('admin/structure/block/manage/' . $block['module'] . '/' . $block['delta'] . '/configure', $edit, t('Save block')); - - // Disable block visibility for the admin user. - $edit = array(); - $edit['block[' . $block['module'] . '][' . $block['delta'] . ']'] = FALSE; - $this->drupalPost('user/' . $this->admin_user->uid . '/edit', $edit, t('Save')); - - $this->drupalGet('user'); - $this->assertNoText($block['title'], 'Block was not displayed according to per user block visibility setting.'); - - // Set the block to be customizable per user, hidden by default. - $edit = array(); - $edit['custom'] = BLOCK_CUSTOM_DISABLED; - $this->drupalPost('admin/structure/block/manage/' . $block['module'] . '/' . $block['delta'] . '/configure', $edit, t('Save block')); - - // Enable block visibility for the admin user. - $edit = array(); - $edit['block[' . $block['module'] . '][' . $block['delta'] . ']'] = TRUE; - $this->drupalPost('user/' . $this->admin_user->uid . '/edit', $edit, t('Save')); - - $this->drupalGet('user'); - $this->assertText($block['title'], 'Block was displayed according to per user block visibility setting.'); - } - - /** * Test configuring and moving a module-define block to specific regions. */ - function testBlock() { + public function testBlock() { // Select the 'Powered by Drupal' block to be configured and moved. - $block = array(); - $block['id'] = 'system_powered_by_block'; - $block['title'] = $this->randomName(8); - $block['machine_name'] = $this->randomName(8); - $block['theme'] = variable_get('theme_default', 'stark'); - $block['region'] = 'header'; + $block_id = 'system_powered_by_block'; + $default_theme = variable_get('theme_default', 'stark'); - // Set block title to confirm that interface works and override any custom titles. - $this->drupalPost('admin/structure/block/manage/' . $block['id'] . '/' . $block['theme'], array('title' => $block['title'], 'machine_name' => $block['machine_name'], 'region' => $block['region']), t('Save block')); + $block = array( + 'title' => $this->randomName(8), + 'machine_name' => $this->randomName(8), + 'region' => 'header', + ); + // Set block title to confirm that interface works and override any custom + // titles. + $this->drupalPost('admin/structure/block/manage/' . $block_id . '/' . $default_theme, $block, t('Save block')); $this->assertText(t('The block configuration has been saved.'), 'Block title set.'); // Check to see if the block was created by checking its configuration. - $block['config_id'] = 'plugin.core.block.' . $block['theme'] . '.' . $block['machine_name']; - $instance = block_load($block['config_id']); - $config = $instance->getConfig(); + $config_id = 'plugin.core.block.' . $default_theme . '.' . $block['machine_name']; - $this->assertEqual($config['subject'], $block['title'], t('Stored block title found.')); + $config = config($config_id); + $stored_title = $config->get('subject'); + $this->assertEqual($block['title'], $stored_title, 'Stored block title was found.'); // Check whether the block can be moved to all available regions. foreach ($this->regions as $region) { @@ -357,6 +168,7 @@ function testBlock() { $this->assertNoFieldByXPath($xpath, FALSE, t('Block found in no regions.')); } + /** * Moves a block to a given region via the UI and confirms the result. * @@ -369,14 +181,14 @@ function testBlock() { * The machine name of the theme region to move the block to, for example * 'header' or 'sidebar_first'. */ - function moveBlockToRegion(array $block, $region) { + protected function moveBlockToRegion(array $block, $region) { // Set the created block to a specific region. $edit = array(); $edit['blocks[0][region]'] = $region; $this->drupalPost('admin/structure/block', $edit, t('Save blocks')); // Confirm that the block was moved to the proper region. - $this->assertText(t('The block settings have been updated.'), format_string('Block successfully moved to %region_name region.', array( '%region_name' => $region))); + $this->assertText(t('The block settings have been updated.'), format_string('Block successfully moved to %region_name region.', array('%region_name' => $region))); // Confirm that the block is being displayed. $this->drupalGet(''); @@ -393,35 +205,33 @@ function moveBlockToRegion(array $block, $region) { /** * Test _block_rehash(). */ - function testBlockRehash() { + public function testBlockRehash() { module_enable(array('block_test')); $this->assertTrue(module_exists('block_test'), 'Test block module enabled.'); // Add a test block. - $plugin = block_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')); + $this->assertText('The block configuration has been saved.', 'Block was saved'); // Our test block's caching should default to DRUPAL_CACHE_PER_ROLE. $block['config_id'] = 'plugin.core.block.' . $block['theme'] . '.' . $block['machine_name']; - $instance = block_load($block['config_id']); - $config = $instance->getConfig(); - $this->assertEqual($config['cache'], DRUPAL_CACHE_PER_ROLE, t('Test block cache mode defaults to DRUPAL_CACHE_PER_ROLE.')); + $config = config($block['config_id']); + $setting = $config->get('cache'); + $this->assertEqual($setting, DRUPAL_CACHE_PER_ROLE, t('Test block cache mode defaults to DRUPAL_CACHE_PER_ROLE.')); // Disable caching for this block. - $block_config = config($block['config_id']); - $block_config->set('cache', DRUPAL_NO_CACHE); - $block_config->save(); + $config->set('cache', DRUPAL_NO_CACHE); + $config->save(); // Flushing all caches should call _block_rehash(). $this->resetAll(); // Verify that block is updated with the new caching mode. - $instance = block_load($block['config_id']); - $config = $instance->getConfig(); - $this->assertEqual($config['cache'], DRUPAL_NO_CACHE, t("Test block's database entry updated to DRUPAL_NO_CACHE.")); + $config = config($block['config_id']); + $setting = $config->get('cache'); + $this->assertEqual($setting, DRUPAL_NO_CACHE, "Test block's database entry updated to DRUPAL_NO_CACHE."); } } diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockUiTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockUiTest.php new file mode 100644 index 0000000..179464c --- /dev/null +++ b/core/modules/block/lib/Drupal/block/Tests/BlockUiTest.php @@ -0,0 +1,46 @@ + 'Block UI', + 'description' => 'Checks that the block configuration UI stores data correctly.', + 'group' => 'Block', + ); + } + function setUp() { + parent::setUp(); + // Create and log in an administrative user. + $this->adminUser = $this->drupalCreateUser(array( + 'administer blocks', + 'access administration pages', + )); + $this->drupalLogin($this->adminUser); + } + + /** + * Test block visibility. + */ + function testBlockVisibility() { + } +} diff --git a/core/modules/block/lib/Drupal/block/Tests/NonDefaultBlockAdminTest.php b/core/modules/block/lib/Drupal/block/Tests/NonDefaultBlockAdminTest.php index 381b49a..7cf114c 100644 --- a/core/modules/block/lib/Drupal/block/Tests/NonDefaultBlockAdminTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/NonDefaultBlockAdminTest.php @@ -34,6 +34,7 @@ function testNonDefaultBlockAdmin() { $this->drupalLogin($admin_user); $new_theme = 'bartik'; theme_enable(array($new_theme)); - $this->drupalGet('admin/structure/block/list/' . $new_theme); + $this->drupalGet('admin/structure/block/list/block_plugin_ui:' . $new_theme); + $this->assertText('Bartik(' . t('active tab') . ')', 'Tab for non-default theme found.'); } } diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentBlockTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentBlockTest.php index 0ec3af2..b8c07e6 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentBlockTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentBlockTest.php @@ -46,21 +46,16 @@ public static function getInfo() { */ function testRecentCommentBlock() { $this->drupalLogin($this->admin_user); - - // Set the block to a region to confirm block is available. + $current_theme = variable_get('default_theme', 'stark'); + $machine_name = 'test_recent_comments'; $edit = array( - 'blocks[comment_recent][region]' => 'sidebar_first', - ); - $this->drupalPost('admin/structure/block', $edit, t('Save blocks')); - $this->assertText(t('The block settings have been updated.'), 'Block saved to first sidebar region.'); - - // Set block title and variables. - $block = array( + 'machine_name' => $machine_name, + 'region' => 'sidebar_first', 'title' => $this->randomName(), - 'comment_block_count' => 2, + 'block_count' => 2, ); - $this->drupalPost('admin/structure/block/manage/comment/recent/configure', $block, t('Save block')); - $this->assertText(t('The block configuration has been saved.'), 'Block saved.'); + $this->drupalPost('admin/structure/block/manage/recent_comments/' . $current_theme, $edit, t('Save block')); + $this->assertText(t('The block configuration has been saved.'), 'Block was saved.'); // Add some test comments, one without a subject. $comment1 = $this->postComment($this->node, $this->randomName(), $this->randomName()); @@ -75,14 +70,14 @@ function testRecentCommentBlock() { // posting a node from a node form. cache_invalidate(array('content' => TRUE)); $this->drupalGet(''); - $this->assertNoText($block['title'], 'Block was not found.'); + $this->assertNoText($edit['title'], 'Block was not found.'); user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access comments')); // Test that a user with the 'access comments' permission can see the // block. $this->drupalLogin($this->web_user); $this->drupalGet(''); - $this->assertText($block['title'], 'Block was found.'); + $this->assertText($edit['title'], 'Block was found.'); // Test the only the 2 latest comments are shown and in the proper order. $this->assertNoText($comment1->subject, 'Comment not found in block.'); @@ -94,9 +89,10 @@ function testRecentCommentBlock() { $this->drupalLogout(); $this->drupalLogin($this->admin_user); $block = array( - 'comment_block_count' => 10, + 'block_count' => 10, ); - $this->drupalPost('admin/structure/block/manage/comment/recent/configure', $block, t('Save block')); + + $this->drupalPost("admin/structure/block/manage/plugin.core.block.$current_theme.$machine_name/$current_theme/configure", $block, t('Save block')); $this->assertText(t('The block configuration has been saved.'), 'Block saved.'); // Post an additional comment. diff --git a/core/modules/menu/lib/Drupal/menu/Plugin/Derivative/MenuBlock.php b/core/modules/menu/lib/Drupal/menu/Plugin/Derivative/MenuBlock.php index 6d0bf79..04a4c34 100644 --- a/core/modules/menu/lib/Drupal/menu/Plugin/Derivative/MenuBlock.php +++ b/core/modules/menu/lib/Drupal/menu/Plugin/Derivative/MenuBlock.php @@ -9,6 +9,11 @@ class MenuBlock extends SystemMenuBlock { * Implements DerivativeInterface::getDerivativeDefinitions(). */ public function getDerivativeDefinitions(array $base_plugin_definition) { + // TODO. This check is here for simpletest. See + // http://drupal.org/node/1821658 + if (!module_exists('menu')) { + return array(); + } foreach (menu_get_menus(FALSE) as $menu => $name) { $this->derivatives[$menu] = $base_plugin_definition; $this->derivatives[$menu]['delta'] = $menu;