You are here

function ContextBlocksTestCase::testContextBlockTitles in Context 6.2

Check that the block title setting is respected by Context.

File

tests/context_blocks.test, line 93

Class

ContextBlocksTestCase

Code

function testContextBlockTitles() {

  // Select the Navigation block to be configured and moved.
  $block = array();
  $block['module'] = 'user';
  $block['delta'] = 1;
  $block['title'] = $this
    ->randomName(8);

  // Set block title to confirm that interface works and override any custom titles.
  $this
    ->drupalPost('admin/build/block/configure/' . $block['module'] . '/' . $block['delta'], array(
    'title' => $block['title'],
  ), t('Save block'));
  $this
    ->assertText(t('The block configuration has been saved.'), t('Block title set.'));
  $bid = db_result(db_query("SELECT bid FROM {blocks} WHERE module = '%s' AND delta = '%s'", array(
    $block['module'],
    $block['delta'],
  )));

  // Check to see if the block was created by checking that it's in the database.
  $this
    ->assertNotNull($bid, t('Block found in database'));

  // Set the created block to a specific region.
  $edit = array();
  $edit[$block['module'] . '_' . $block['delta'] . '[region]'] = '-1';
  $this
    ->drupalPost('admin/build/block', $edit, t('Save blocks'));

  // Confirm that the block is NOT being displayed.
  $this
    ->assertNoText(t($block['title']), t('Block successfully being NOT displayed on the page.'));

  // Add the block via context:
  $context = array(
    'namespace' => $this
      ->randomName(8),
    'attribute' => $this
      ->randomName(8),
    'value' => $this
      ->randomName(8),
    'sitewide' => '1',
    'block' => array(
      $block['module'] . '_' . $block['delta'] => array(
        'module' => $block['module'],
        'delta' => $block['delta'],
        'region' => 'left',
      ),
    ),
  );
  context_save_context((object) $context);

  // Confirm that the block is being displayed.
  $this
    ->drupalGet('<front>');
  $this
    ->assertText(t($block['title']), t('Block successfully being displayed on the page.'));

  // Change the title of the block:
  $block['old_title'] = $block['title'];
  $block['title'] = '<none>';

  // Set block title to confirm that interface works and override any custom titles.
  $this
    ->drupalPost('admin/build/block/configure/' . $block['module'] . '/' . $block['delta'], array(
    'title' => $block['title'],
  ), t('Save block'));
  $this
    ->assertText(t('The block configuration has been saved.'), t('Block title set.'));
  $bid = db_result(db_query("SELECT bid FROM {blocks} WHERE module = '%s' AND delta = '%s'", array(
    $block['module'],
    $block['delta'],
  )));

  // Check to see if the block was created by checking that it's in the database.
  $this
    ->assertNotNull($bid, t('Block found in database'));

  // Confirm that the block is NOT being displayed with its old title.
  $this
    ->assertNoText(t($block['old_title']), t('Old block title successfully being NOT displayed on the page.'));
  $account = $this->loggedInUser;
  $this
    ->assertNoText(t($account->name), t('Block tile successfully being NOT displayed on the page.'));

  // Change the title of the block to the default:
  $block['title'] = '';

  // Set block title to confirm that interface works and override any custom titles.
  $this
    ->drupalPost('admin/build/block/configure/' . $block['module'] . '/' . $block['delta'], array(
    'title' => $block['title'],
  ), t('Save block'));
  $this
    ->assertText(t('The block configuration has been saved.'), t('Block title set.'));
  $bid = db_result(db_query("SELECT bid FROM {blocks} WHERE module = '%s' AND delta = '%s'", array(
    $block['module'],
    $block['delta'],
  )));

  // Check to see if the block was created by checking that it's in the database.
  $this
    ->assertNotNull($bid, t('Block found in database'));

  // Confirm that the block is NOT being displayed with its old title.
  $this
    ->assertNoText(t($block['old_title']), t('Old block title successfully being NOT displayed on the page.'));
  $account = $this->loggedInUser;
  $this
    ->assertText(t($account->name), t('Default block tile successfully being displayed on the page.'));
}