View source
<?php
class ContextBlocksTestCase extends DrupalWebTestCase {
function getInfo() {
return array(
'name' => t('Context block reactions'),
'description' => t('Checks that our implementation of the block reactions works.'),
'group' => t('Context'),
);
}
function setUp() {
parent::setUp('context');
$admin_user = $this
->drupalCreateUser(array(
'administer blocks',
));
$this
->drupalLogin($admin_user);
}
function testContextCustomBlockTitles() {
$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'));
$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'],
)));
$this
->assertNotNull($bid, t('Box found in database'));
$box['module'] = 'block';
$box['delta'] = $bid;
$this
->assertNoText(t($box['title']), t('Box successfully being NOT displayed on the page.'));
$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);
$this
->drupalGet('<front>');
$this
->assertText(t($box['title']), t('Box successfully being displayed on the page.'));
$box['old_title'] = $box['title'];
$box['title'] = '<none>';
$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'],
)));
$this
->assertNotNull($bid, t('Box found in database'));
$this
->assertNoText(t($box['old_title']), t('Old box title successfully being NOT displayed on the page.'));
}
function testContextBlockTitles() {
$block = array();
$block['module'] = 'user';
$block['delta'] = 1;
$block['title'] = $this
->randomName(8);
$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'],
)));
$this
->assertNotNull($bid, t('Block found in database'));
$edit = array();
$edit[$block['module'] . '_' . $block['delta'] . '[region]'] = '-1';
$this
->drupalPost('admin/build/block', $edit, t('Save blocks'));
$this
->assertNoText(t($block['title']), t('Block successfully being NOT displayed on the page.'));
$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);
$this
->drupalGet('<front>');
$this
->assertText(t($block['title']), t('Block successfully being displayed on the page.'));
$block['old_title'] = $block['title'];
$block['title'] = '<none>';
$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'],
)));
$this
->assertNotNull($bid, t('Block found in database'));
$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.'));
$block['title'] = '';
$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'],
)));
$this
->assertNotNull($bid, t('Block found in database'));
$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.'));
}
}