You are here

public function ClockBlockTestCase::testClockBlock in Clock 7

Same name and namespace in other branches
  1. 6 clock.test \ClockBlockTestCase::testClockBlock()
  2. 7.2 clock.test \ClockBlockTestCase::testClockBlock()

File

./clock.test, line 33
Tests for Clock module.

Class

ClockBlockTestCase
@file Tests for Clock module.

Code

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.");
  }
}