You are here

function ContextBlocksTestCase::testContextCustomBlockTitles in Context 6.2

Check that the block title setting is respected by Context for custom blocks.

File

tests/context_blocks.test, line 30

Class

ContextBlocksTestCase

Code

function testContextCustomBlockTitles() {

  // Add a new box by filling out the input form on the admin/build/block/add page.
  $box = array();
  $box['info'] = $this
    ->randomName(8);
  $box['title'] = $this
    ->randomName(8);
  $box['body'] = $this
    ->randomName(32);
  $this
    ->drupalPost('admin/build/block/add', $box, t('Save block'));

  // Confirm that the box has been created, and then query the created bid.
  $this
    ->assertText(t('The block has been created.'), t('Box successfully created.'));
  $bid = db_result(db_query("SELECT bid FROM {boxes} WHERE info = '%s'", array(
    $box['info'],
  )));

  // Check to see if the box was created by checking that it's in the database..
  $this
    ->assertNotNull($bid, t('Box found in database'));
  $box['module'] = 'block';
  $box['delta'] = $bid;

  // Confirm that the box is NOT being displayed.
  $this
    ->assertNoText(t($box['title']), t('Box 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(
      $box['module'] . '_' . $box['delta'] => array(
        'module' => $box['module'],
        'delta' => $box['delta'],
        'region' => 'left',
      ),
    ),
  );
  context_save_context((object) $context);

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

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

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

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

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