You are here

function TwitterBlockTestCase::testTwitterBlock in Twitter Block 7

Same name and namespace in other branches
  1. 7.2 tests/twitter_block.test \TwitterBlockTestCase::testTwitterBlock()

Test creating custom Twitter block, moving it to a specific region and then deleting it.

File

tests/twitter_block.test, line 40
Tests for Twitter Block module.

Class

TwitterBlockTestCase
@file Tests for Twitter Block module.

Code

function testTwitterBlock() {

  // Confirm that the add Twitter block link appears on block overview pages.
  $this
    ->drupalGet('admin/structure/block');
  $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.');
  $this
    ->drupalGet('admin/structure/block/list/seven');
  $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.');

  // Add a new custom Twitter block by filling out the input form on the admin/structure/block/add-twitter-block page.
  $twitter_block = array();
  $twitter_block['info'] = $this
    ->randomName(8);
  $twitter_block['title'] = $this
    ->randomName(8);
  $twitter_block['search_type'] = 'searchHashtag';
  $twitter_block['search_string'] = 'Drupal';
  $twitter_block['include_rts'] = TRUE;
  $twitter_block['lang'] = '';
  $twitter_block['results_per_page'] = 10;
  $this
    ->drupalPost('admin/structure/block/add-twitter-block', $twitter_block, t('Save block'));

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

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

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

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

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

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