7.x block.test BlockInvalidRegionTestCase::testBlockInInvalidRegion()

Tests that blocks assigned to invalid regions work correctly.

File

modules/block/block.test, line 859
Tests for block.module.

Class

BlockInvalidRegionTestCase
Tests that a block assigned to an invalid region triggers the warning.

Code

function testBlockInInvalidRegion() {

  // Enable a test block in the default theme and place it in an invalid region.
  db_merge('block')
    ->key(array(
    'module' => 'block_test',
    'delta' => 'test_html_id',
    'theme' => variable_get('theme_default', 'stark'),
  ))
    ->fields(array(
    'status' => 1,
    'region' => 'invalid_region',
    'cache' => DRUPAL_NO_CACHE,
  ))
    ->execute();
  $warning_message = t('The block %info was assigned to the invalid region %region and has been disabled.', array(
    '%info' => t('Test block html id'),
    '%region' => 'invalid_region',
  ));

  // Clearing the cache should disable the test block placed in the invalid region.
  $this
    ->drupalPost('admin/config/development/performance', array(), 'Clear all caches');
  $this
    ->assertRaw($warning_message, 'Enabled block was in the invalid region and has been disabled.');

  // Clear the cache to check if the warning message is not triggered.
  $this
    ->drupalPost('admin/config/development/performance', array(), 'Clear all caches');
  $this
    ->assertNoRaw($warning_message, 'Disabled block in the invalid region will not trigger the warning.');

  // Place disabled test block in the invalid region of the default theme.
  db_merge('block')
    ->key(array(
    'module' => 'block_test',
    'delta' => 'test_html_id',
    'theme' => variable_get('theme_default', 'stark'),
  ))
    ->fields(array(
    'region' => 'invalid_region',
    'cache' => DRUPAL_NO_CACHE,
  ))
    ->execute();

  // Clear the cache to check if the warning message is not triggered.
  $this
    ->drupalPost('admin/config/development/performance', array(), 'Clear all caches');
  $this
    ->assertNoRaw($warning_message, 'Disabled block in the invalid region will not trigger the warning.');
}