00001 <?php
00002
00010 class BlockTestCase extends DrupalWebTestCase {
00014 public static function getInfo() {
00015 return array(
00016 'name' => t('Block functionality'),
00017 'description' => t('Add, edit and delete custom block. Configure and move a module-defined block.'),
00018 'group' => t('Block'),
00019 );
00020 }
00021
00025 function setUp() {
00026 parent::setUp();
00027
00028
00029 $admin_user = $this->drupalCreateUser(array('administer blocks'));
00030 $this->drupalLogin($admin_user);
00031 }
00032
00036 function testBox() {
00037
00038 $box = array();
00039 $box['info'] = $this->randomName(8);
00040 $box['title'] = $this->randomName(8);
00041 $box['body'] = $this->randomName(32);
00042 $this->drupalPost('admin/build/block/add', $box, t('Save block'));
00043
00044
00045 $this->assertText(t('The block has been created.'), t('Box successfully created.'));
00046 $bid = db_result(db_query("SELECT bid FROM {boxes} WHERE info = '%s'", array($box['info'])));
00047
00048
00049 $this->assertNotNull($bid, t('Box found in database'));
00050
00051
00052
00053 $edit = array();
00054 $edit['block_'. $bid .'[region]'] = 'left';
00055 $this->drupalPost('admin/build/block', $edit, t('Save blocks'));
00056
00057
00058 $this->assertText(t('The block settings have been updated.'), t('Box successfully moved to left region.'));
00059
00060
00061 $this->assertText(t($box['title']), t('Box successfully being displayed on the page.'));
00062
00063
00064 $this->drupalPost('admin/build/block/delete/'. $bid, array(), t('Delete'));
00065 $this->assertRaw(t('The block %title has been removed.', array('%title' => $box['info'])), t('Box successfully deleted.'));
00066 $this->assertNoText(t($box['title']), t('Box no longer appears on page.'));
00067 }
00068
00072 function testBlock() {
00073
00074 $block = array();
00075 $block['module'] = 'user';
00076 $block['delta'] = 1;
00077 $block['title'] = $this->randomName(8);
00078
00079
00080 $this->drupalPost('admin/build/block/configure/'. $block['module'] .'/'. $block['delta'], array('title' => $block['title']), t('Save block'));
00081 $this->assertText(t('The block configuration has been saved.'), t('Block title set.'));
00082 $bid = db_result(db_query("SELECT bid FROM {blocks} WHERE module = '%s' AND delta = '%s'", array($block['module'], $block['delta'])));
00083
00084
00085 $this->assertNotNull($bid, t('Block found in database'));
00086
00087
00088 $edit = array();
00089 $edit[$block['module'] .'_'. $block['delta'] .'[region]'] = 'left';
00090 $this->drupalPost('admin/build/block', $edit, t('Save blocks'));
00091
00092
00093
00094 $this->assertText(t('The block settings have been updated.'), t('Block successfully moved to left region.'));
00095
00096
00097 $this->assertText(t($block['title']), t('Block successfully being displayed on the page.'));
00098
00099
00100 $edit = array();
00101 $edit[$block['module'] .'_'. $block['delta'] .'[region]'] = '-1';
00102 $this->drupalPost('admin/build/block', $edit, t('Save blocks'));
00103
00104
00105 $this->assertText(t('The block settings have been updated.'), t('Block successfully move to disabled region.'));
00106 $this->assertNoText(t($block['title']), t('Block no longer appears on page.'));
00107
00108
00109 $edit = array();
00110 $edit[$block['module'] .'_'. $block['delta'] .'[region]'] = 'left';
00111 $this->drupalPost('admin/build/block', $edit, t('Save blocks'));
00112 $this->assertText(t('The block settings have been updated.'), t('Block successfully move to disabled region.'));
00113
00114 $this->drupalPost('admin/build/block/configure/'. $block['module'] .'/'. $block['delta'], array('title' => 'Navigation'), t('Save block'));
00115 $this->assertText(t('The block configuration has been saved.'), t('Block title set.'));
00116 }
00117 }
00118