You are here

google_calendar_block.test in Google Calendar Block 7.2

Same filename and directory in other branches
  1. 7 tests/google_calendar_block.test

Tests for Google Calendar Block module.

File

tests/google_calendar_block.test
View source
<?php

/**
 * @file
 * Tests for Google Calendar Block module.
 */
class GoogleCalendarBlockTestCase extends DrupalWebTestCase {
  protected $admin_user;
  public static function getInfo() {
    return array(
      'name' => 'Google Calendar Block functionality',
      'description' => 'Add, edit and delete custom Google Calendar block. Configure and move a Google Calendar block.',
      'group' => 'Google Calendar Block',
    );
  }
  function setUp() {
    parent::setUp('block', 'google_calendar_block');

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

    // Define the existing regions
    $this->regions = array();
    $this->regions[] = 'header';
    $this->regions[] = 'sidebar_first';
    $this->regions[] = 'content';
    $this->regions[] = 'sidebar_second';
    $this->regions[] = 'footer';
  }

  /**
   * Test creating custom Google Calendar block, moving it to a specific region and then deleting it.
   */
  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['application_name'] = $this
      ->randomName(8);
    $google_calendar_block['developer_key'] = $this
      ->randomName(8);
    $google_calendar_block['calendar_id'] = $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.');
  }
  function moveBlockToRegion($block, $region) {

    // Set the created block to a specific region.
    $edit = array();
    $edit['blocks[' . $block['module'] . '_' . $block['delta'] . '][region]'] = $region;
    $this
      ->drupalPost('admin/structure/block', $edit, t('Save blocks'));

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

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

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

}

Classes

Namesort descending Description
GoogleCalendarBlockTestCase @file Tests for Google Calendar Block module.