Projet

Général

Profil

Paste
Télécharger (5,35 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / twitter_block / tests / twitter_block.test @ 74f6bef0

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
    $this->drupalPost('admin/structure/block/add-twitter-block', $twitter_block, t('Save block'));
53

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

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

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

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

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

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

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

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

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

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