function BlockTestCase::testBlock in SimpleTest 6.2
Test configuring and moving a module-define block to specific regions.
File
- tests/
block.test, line 71 - Backport of Drupal 7 block.test with modifications, see BACKPORT.txt.
Class
- BlockTestCase
- @file Backport of Drupal 7 block.test with modifications, see BACKPORT.txt.
Code
function testBlock() {
// 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]'] = 'left';
$this
->drupalPost('admin/build/block', $edit, t('Save blocks'));
// Confirm that the block was moved to the proper region.
// TODO: Implement full region checking.
$this
->assertText(t('The block settings have been updated.'), t('Block successfully moved to left region.'));
// Confirm that the block is being displayed.
$this
->assertText(t($block['title']), t('Block successfully being displayed on the page.'));
// Set the block to the disabled region.
$edit = array();
$edit[$block['module'] . '_' . $block['delta'] . '[region]'] = '-1';
$this
->drupalPost('admin/build/block', $edit, t('Save blocks'));
// Confirm that the block was moved to the proper region.
$this
->assertText(t('The block settings have been updated.'), t('Block successfully move to disabled region.'));
$this
->assertNoText(t($block['title']), t('Block no longer appears on page.'));
// For convenience of developers, put the navigation block back.
$edit = array();
$edit[$block['module'] . '_' . $block['delta'] . '[region]'] = 'left';
$this
->drupalPost('admin/build/block', $edit, t('Save blocks'));
$this
->assertText(t('The block settings have been updated.'), t('Block successfully move to disabled region.'));
$this
->drupalPost('admin/build/block/configure/' . $block['module'] . '/' . $block['delta'], array(
'title' => 'Navigation',
), t('Save block'));
$this
->assertText(t('The block configuration has been saved.'), t('Block title set.'));
}