Line # | Frequency | Source Line |
1 | | <?php
|
2 | | // $Id: block.test,v 1.9 2008/04/01 23:33:54 boombatower Exp $
|
3 | |
|
4 | | class BlockTestCase extends DrupalTestCase {
|
5 | | /**
|
6 | | * Implementation of getInfo().
|
7 | | */
|
8 | | function getInfo() {
|
9 | | return array(
|
10 | 1 | 'name' => t('Block functionality'),
|
11 | | 'description' => t('Add, edit and delete custom block. Configure and move a module-defined block.'),
|
12 | | 'group' => t('Block Tests'),
|
13 | | );
|
14 | | }
|
15 | |
|
16 | | /**
|
17 | | * Create user, setup permissions and login user.
|
18 | | */
|
19 | | function setUp() {
|
20 | | parent::setUp();
|
21 | |
|
22 | | // Create and login user
|
23 | | $admin_user = $this->drupalCreateUser(array('administer blocks'));
|
24 | | $this->drupalLogin($admin_user);
|
25 | | }
|
26 | |
|
27 | | /**
|
28 | | * Test creating custom block (i.e. box), moving it to a specific region and then deleting it.
|
29 | | */
|
30 | | function testBox() {
|
31 | | // Add a new box by filling out the input form on the admin/build/block/add page.
|
32 | | $box = array();
|
33 | | $box['info'] = $this->randomName(8);
|
34 | | $box['title'] = $this->randomName(8);
|
35 | | $box['body'] = $this->randomName(32);
|
36 | | $this->drupalPost('admin/build/block/add', $box, t('Save block'));
|
37 | |
|
38 | | // Confirm that the box has been created, and then query the created bid.
|
39 | | $this->assertText(t('The block has been created.'), t('Box successfully created.'));
|
40 | | $bid = db_result(db_query("SELECT bid FROM {boxes} WHERE info = '%s'", array($box['info'])));
|
41 | |
|
42 | | // Check to see if the box was created by checking that it's in the database..
|
43 | | $this->assertNotNull($bid, t('Box found in database'));
|
44 | |
|
45 | | // Set the created box to a specific region.
|
46 | | // TODO: Implement full region checking.
|
47 | | $edit = array();
|
48 | | $edit['block_'. $bid .'[region]'] = 'left';
|
49 | | $this->drupalPost('admin/build/block', $edit, t('Save blocks'));
|
50 | |
|
51 | | // Confirm that the box was moved to the proper region.
|
52 | | $this->assertText(t('The block settings have been updated.'), t('Box successfully moved to left region.'));
|
53 | |
|
54 | | // Confirm that the box is being displayed.
|
55 | | $this->assertText(t($box['title']), t('Box successfully being displayed on the page.'));
|
56 | |
|
57 | | // Delete the created box & verify that it's been deleted and no longer appearing on the page.
|
58 | | $this->drupalPost('admin/build/block/delete/'. $bid, array(), t('Delete'));
|
59 | | $this->assertRaw(t('The block %title has been removed.', array('%title' => $box['info'])), t('Box successfully deleted.'));
|
60 | | $this->assertNoText(t($box['title']), t('Box no longer appears on page.'));
|
61 | | }
|
62 | |
|
63 | | /**
|
64 | | * Test configuring and moving a module-define block to specific regions.
|
65 | | */
|
66 | | function testBlock() {
|
67 | | // Select the Navigation block to be configured and moved.
|
68 | | $block = array();
|
69 | | $block['module'] = 'user';
|
70 | | $block['delta'] = 1;
|
71 | | $block['title'] = $this->randomName(8);
|
72 | |
|
73 | | // Set block title to confirm that interface works and override any custom titles.
|
74 | | $this->drupalPost('admin/build/block/configure/'. $block['module'] .'/'. $block['delta'], array('title' => $block['title']), t('Save block'));
|
75 | | $this->assertText(t('The block configuration has been saved.'), t('Block title set.'));
|
76 | | $bid = db_result(db_query("SELECT bid FROM {blocks} WHERE module = '%s' AND delta = %d", array($block['module'], $block['delta'])));
|
77 | |
|
78 | | // Check to see if the block was created by checking that it's in the database.
|
79 | | $this->assertNotNull($bid, t('Block found in database'));
|
80 | |
|
81 | | // Set the created block to a specific region.
|
82 | | $edit = array();
|
83 | | $edit[$block['module'] .'_'. $block['delta'] .'[region]'] = 'left';
|
84 | | $this->drupalPost('admin/build/block', $edit, t('Save blocks'));
|
85 | |
|
86 | | // Confirm that the block was moved to the proper region.
|
87 | | // TODO: Implement full region checking.
|
88 | | $this->assertText(t('The block settings have been updated.'), t('Block successfully moved to left region.'));
|
89 | |
|
90 | | // Confirm that the block is being displayed.
|
91 | | $this->assertText(t($block['title']), t('Block successfully being displayed on the page.'));
|
92 | |
|
93 | | // Set the block to the disabled region.
|
94 | | $edit = array();
|
95 | | $edit[$block['module'] .'_'. $block['delta'] .'[region]'] = '-1';
|
96 | | $this->drupalPost('admin/build/block', $edit, t('Save blocks'));
|
97 | |
|
98 | | // Confirm that the block was moved to the proper region.
|
99 | | $this->assertText(t('The block settings have been updated.'), t('Block successfully move to disabled region.'));
|
100 | | $this->assertNoText(t($block['title']), t('Block no longer appears on page.'));
|
101 | |
|
102 | | // For convenience of developers, put the navigation block back.
|
103 | | $edit = array();
|
104 | | $edit[$block['module'] .'_'. $block['delta'] .'[region]'] = 'left';
|
105 | | $this->drupalPost('admin/build/block', $edit, t('Save blocks'));
|
106 | | $this->assertText(t('The block settings have been updated.'), t('Block successfully move to disabled region.'));
|
107 | |
|
108 | | $this->drupalPost('admin/build/block/configure/'. $block['module'] .'/'. $block['delta'], array('title' => 'Navigation'), t('Save block'));
|
109 | | $this->assertText(t('The block configuration has been saved.'), t('Block title set.'));
|
110 | | }
|
111 | | }
|