Project

General

Profile

Paste
Download (5.4 KB) Statistics
| Branch: | Revision:

root / drupal7 / sites / all / modules / twitter_block / tests / twitter_block.test @ 66b5cbf6

1
<?php
2

    
3
/**
4
 * @file
5
 * Tests for Twitter Block module.
6
 */
7
class TwitterBlockTestCase extends DrupalWebTestCase {
8
  protected $admin_user;
9

    
10
  public static function getInfo() {
11
    return array(
12
      'name' => 'Twitter Block functionality',
13
      'description' => 'Add, edit and delete custom Twitter block. Configure and move a Twitter block.',
14
      'group' => 'Twitter Block',
15
    );
16
  }
17

    
18
  function setUp() {
19
    parent::setUp('block', 'twitter_block');
20

    
21
    // Create and log in an administrative user.
22
    $this->admin_user = $this->drupalCreateUser(array(
23
      'administer blocks',
24
      'access administration pages',
25
    ));
26
    $this->drupalLogin($this->admin_user);
27

    
28
    // Define the existing regions
29
    $this->regions = array();
30
    $this->regions[] = 'header';
31
    $this->regions[] = 'sidebar_first';
32
    $this->regions[] = 'content';
33
    $this->regions[] = 'sidebar_second';
34
    $this->regions[] = 'footer';
35
  }
36

    
37
  /**
38
   * Test creating custom Twitter block, moving it to a specific region and then deleting it.
39
   */
40
  function testTwitterBlock() {
41
    // Confirm that the add Twitter block link appears on block overview pages.
42
    $this->drupalGet('admin/structure/block');
43
    $this->assertRaw(l(t('Add Twitter block'), 'admin/structure/block/add-twitter-block'), 'Add Twitter block link is present on block overview page for default theme.');
44
    $this->drupalGet('admin/structure/block/list/seven');
45
    $this->assertRaw(l(t('Add Twitter block'), 'admin/structure/block/list/seven/add-twitter-block'), 'Add Twitter block link is present on block overview page for non-default theme.');
46

    
47
    // Add a new custom Twitter block by filling out the input form on the admin/structure/block/add-twitter-block page.
48
    $twitter_block = array();
49
    $twitter_block['info'] = $this->randomName(8);
50
    $twitter_block['title'] = $this->randomName(8);
51
    $twitter_block['widget_id'] = $this->randomName(8);
52
    $twitter_block['username'] = $this->randomName(8);
53
    $this->drupalPost('admin/structure/block/add-twitter-block', $twitter_block, t('Save block'));
54

    
55
    // Confirm that the custom Twitter block has been created, and then query the created bid.
56
    $this->assertText(t('The block has been created.'), 'Custom Twitter block successfully created.');
57
    $bid = db_query("SELECT bid FROM {twitter_block} WHERE info = :info", array(':info' => $twitter_block['info']))->fetchField();
58

    
59
    // Check to see if the custom Twitter block was created by checking that it's in the database.
60
    $this->assertNotNull($bid, 'Custom Twitter block found in database');
61

    
62
    // Check whether the block can be moved to all available regions.
63
    $twitter_block['module'] = 'twitter_block';
64
    $twitter_block['delta'] = $bid;
65
    foreach ($this->regions as $region) {
66
      $this->moveBlockToRegion($twitter_block, $region);
67
    }
68

    
69
    // Verify presence of configure and delete links for custom Twitter block.
70
    $this->drupalGet('admin/structure/block');
71
    $this->assertLinkByHref('admin/structure/block/manage/twitter_block/' . $bid . '/configure', 0, 'Custom Twitter block configure link found.');
72
    $this->assertLinkByHref('admin/structure/block/administer/twitter_block/' . $bid . '/delete', 0, 'Custom Twitter block delete link found.');
73

    
74
    // Set visibility only for authenticated users, to verify delete functionality.
75
    $edit = array();
76
    $edit['roles[' . DRUPAL_AUTHENTICATED_RID . ']'] = TRUE;
77
    $this->drupalPost('admin/structure/block/manage/twitter_block/' . $bid . '/configure', $edit, t('Save block'));
78

    
79
    // Delete the created custom Twitter block & verify that it's been deleted and no longer appearing on the page.
80
    $this->clickLink(t('delete'));
81
    $this->drupalPost('admin/structure/block/administer/twitter_block/' . $bid . '/delete', array(), t('Delete'));
82
    $this->assertRaw(t('The block %title has been removed.', array('%title' => $twitter_block['info'])), 'Custom Twitter block successfully deleted.');
83
    $this->assertNoText(t($twitter_block['title']), 'Custom Twitter block no longer appears on page.');
84
    $count = db_query("SELECT 1 FROM {block_role} WHERE module = :module AND delta = :delta", array(':module' => $twitter_block['module'], ':delta' => $twitter_block['delta']))->fetchField();
85
    $this->assertFalse($count, 'Table block_role being cleaned.');
86
  }
87

    
88
  function moveBlockToRegion($block, $region) {
89
    // Set the created block to a specific region.
90
    $edit = array();
91
    $edit['blocks[' . $block['module'] . '_' . $block['delta'] . '][region]'] = $region;
92
    $this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
93

    
94
    // Confirm that the block was moved to the proper region.
95
    $this->assertText(t('The block settings have been updated.'), format_string('Block successfully moved to %region_name region.', array('%region_name' => $region)));
96

    
97
    // Confirm that the block is being displayed.
98
    $this->drupalGet('node');
99
    $this->assertText(t($block['title']), 'Block successfully being displayed on the page.');
100

    
101
    // Confirm that the custom Twitter block was found at the proper region.
102
    $xpath = $this->buildXPathQuery('//div[@class=:region-class]//div[@id=:block-id]/*', array(
103
      ':region-class' => 'region region-' . str_replace('_', '-', $region),
104
      ':block-id' => 'block-' . drupal_clean_css_identifier($block['module']) . '-' . $block['delta'],
105
    ));
106
    $this->assertFieldByXPath($xpath, NULL, format_string('Custom Twitter block found in %region_name region.', array('%region_name' => $region)));
107
  }
108
}