You are here

clock.test in Clock 7

Same filename and directory in other branches
  1. 6 clock.test
  2. 7.2 clock.test

Tests for Clock module.

File

clock.test
View source
<?php

/**
 * @file
 * Tests for Clock module.
 */
class ClockBlockTestCase extends DrupalWebTestCase {
  protected $profile = 'testing';
  public static function getInfo() {
    return array(
      'name' => 'Clock module tests',
      'description' => 'Ensure that the clock block and the configuration form functions properly.',
      'group' => 'Clock',
    );
  }
  public function setUp() {
    parent::setUp('block', 'date_api', 'clock');
    $privileged_user = $this
      ->drupalCreateUser(array(
      'administer blocks',
      'administer site configuration',
    ));

    // Save the test user's uid to access the user edit page later.
    variable_set('test_user_id', $privileged_user->uid);
    $this
      ->drupalLogin($privileged_user);

    // Enable the clock block (and the main content block) in main content area.
    $theme = variable_get('theme_default', '');
    $edit = array();
    $edit['blocks[clock_clock][region]'] = 'content';
    $edit['blocks[system_main][region]'] = 'content';
    $this
      ->drupalPost("admin/structure/block/list/{$theme}", $edit, 'Save blocks');
  }
  public function testClockBlock() {

    // Should $language_content be used instead?
    global $language;

    // Test the default display of the clock.
    $clock = date_format_date(date_now(variable_get('date_default_timezone', 'UTC')), 'long');
    $this
      ->assertText($clock, 'Ensure that the clock is correctly displayed by default.');
    $edit = array();
    $edit['time_zone_type'] = 3;
    $this
      ->drupalPost('admin/structure/block/manage/clock/clock/configure', $edit, 'Save block');
    $this
      ->assertText($clock, 'Ensure that the clock falls back to the site time with Local time zone enabled and without JavaScript.');

    // Test the user time zone.
    $edit = array();
    $edit['timezone'] = 'Pacific/Fiji';
    $this
      ->drupalPost('user/' . variable_get('test_user_id', '1') . '/edit', $edit, 'Save');

    // Make sure user-configurable time zones are enabled.
    variable_set('configurable_timezones', 1);

    // Set the clock block to display the user time zone.
    $edit = array();
    $edit['time_zone_type'] = 2;
    $this
      ->drupalPost('admin/structure/block/manage/clock/clock/configure', $edit, 'Save block');
    $clock = date_format_date(date_now('Pacific/Fiji'), 'long');
    $this
      ->assertText($clock, 'Ensure that the clock is correctly displayed in the user time zone.');

    // Test a custom time zone.
    $edit = array();
    $edit['time_zone_type'] = 4;
    $edit['time_zone_custom'] = 'Africa/Lubumbashi';
    $this
      ->drupalPost('admin/structure/block/manage/clock/clock/configure', $edit, 'Save block');
    $clock = date_format_date(date_now('Africa/Lubumbashi'), 'long');
    $this
      ->assertText($clock, 'Ensure that the clock is correctly displayed in a custom date format');

    // Create a custom date type.
    $date_type = $this
      ->randomName();
    system_date_format_type_save(array(
      'type' => $date_type,
      'title' => $date_type,
      'locked' => 0,
    ));
    $date_format = 'aAbBcCdDeEfFgGhHiIjJlLmMnNoOpPqQRsStTuUvVwWxXyYzZ';

    // Create a custom date format. We leave the 'r' formatter out, because
    // there is a bug in Date API. See http://drupal.org/node/697144
    system_date_format_save(array(
      'type' => $date_type,
      'format' => $date_format,
      'locked' => FALSE,
    ));

    // Make the date format the default for the new date type.
    include_once DRUPAL_ROOT . '/includes/locale.inc';
    locale_date_format_save($language->language, $date_type, $date_format);

    // Test all date types (including the custom one).
    foreach (system_get_date_types() as $type => $info) {
      $format = variable_get('date_format_' . $type, key(system_get_date_formats($type)));
      $edit = array();
      $edit['date_type'] = $type;
      $this
        ->drupalPost('admin/structure/block/manage/clock/clock/configure', $edit, 'Save block');
      $clock = date_format_date(date_now('Africa/Lubumbashi'), 'custom', $format);
      $title = $info['title'];
      $this
        ->assertText($clock, "Ensure that the clock is correctly displayed in the {$title} date format type.");
    }
  }
  public function testClockInterfaceUserTimezone() {
    variable_set('configurable_timezones', 1);
    $this
      ->drupalGet('admin/structure/block/manage/clock/clock/configure');
    $this
      ->assertText('User time zone', "Make sure the 'User time zone' setting is available when user time zones are enabled.");
    variable_set('configurable_timezones', 0);
    $this
      ->drupalGet('admin/structure/block/manage/clock/clock/configure');
    $this
      ->assertNoText('User time zone', "Make sure the 'User time zone' setting is not available when user time zones are disabled.");
  }

}

Classes

Namesort descending Description
ClockBlockTestCase @file Tests for Clock module.