You are here

function GoogleCalendarBlockTestCase::testGoogleCalendarBlock in Google Calendar Block 7

Same name and namespace in other branches
  1. 7.2 tests/google_calendar_block.test \GoogleCalendarBlockTestCase::testGoogleCalendarBlock()

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

File

tests/google_calendar_block.test, line 40
Tests for Google Calendar Block module.

Class

GoogleCalendarBlockTestCase
@file Tests for Google Calendar Block module.

Code

function testGoogleCalendarBlock() {

  // Confirm that the add Google Calendar block link appears on block overview pages.
  $this
    ->drupalGet('admin/structure/block');
  $this
    ->assertRaw(l(t('Add Google Calendar block'), 'admin/structure/block/add-google-calendar-block'), 'Add Google Calendar block link is present on block overview page for default theme.');
  $this
    ->drupalGet('admin/structure/block/list/seven');
  $this
    ->assertRaw(l(t('Add Google Calendar block'), 'admin/structure/block/list/seven/add-google-calendar-block'), 'Add Google Calendar block link is present on block overview page for non-default theme.');

  // Add a new custom Google Calendar block by filling out the input form on the admin/structure/block/add-google-calendar-block page.
  $google_calendar_block = array();
  $google_calendar_block['info'] = $this
    ->randomName(8);
  $google_calendar_block['title'] = $this
    ->randomName(8);
  $google_calendar_block['calendar_user'] = $this
    ->randomName(8);
  $google_calendar_block['calendar_visibility'] = $this
    ->randomName(8);
  $this
    ->drupalPost('admin/structure/block/add-google-calendar-block', $google_calendar_block, t('Save block'));

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

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

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

  // Verify presence of configure and delete links for custom Google Calendar block.
  $this
    ->drupalGet('admin/structure/block');
  $this
    ->assertLinkByHref('admin/structure/block/manage/google_calendar_block/' . $bid . '/configure', 0, 'Custom Google Calendar block configure link found.');
  $this
    ->assertLinkByHref('admin/structure/block/administer/google_calendar_block/' . $bid . '/delete', 0, 'Custom Google Calendar 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/google_calendar_block/' . $bid . '/configure', $edit, t('Save block'));

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