You are here

public function ClockBlockTestCase::testClockBlock in Clock 6

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

File

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

Class

ClockBlockTestCase
@file Tests for Clock module.

Code

public function testClockBlock() {

  // Test the default display.
  $clock = date_format_date(date_now('UTC'), 'short');
  $this
    ->assertText($clock, 'Ensure that the clock is correctly displayed by default.');
  $edit['timezone'] = '3';
  $this
    ->drupalPost('admin/build/block/configure/clock/clock', $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_name'] = 'Pacific/Fiji';
  $this
    ->drupalPost('user/' . variable_get('test_user_id', '1') . '/edit', $edit, 'Save');

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

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

  // Reset the time zone.
  $edit['timezone'] = '1';
  $this
    ->drupalPost('admin/build/block/configure/clock/clock', $edit, 'Save block');

  // Test the medium date format.
  $edit = array();
  $edit['date_format'] = 'medium';
  $this
    ->drupalPost('admin/build/block/configure/clock/clock', $edit, 'Save block');
  $clock = date_format_date(date_now(), 'medium');
  $this
    ->assertText($clock, 'Ensure that the clock is correctly displayed in the medium date format.');

  // Test the long date format.
  $edit = array();
  $edit['date_format'] = 'long';
  $this
    ->drupalPost('admin/build/block/configure/clock/clock', $edit, 'Save block');
  $clock = date_format_date(date_now(), 'long');
  $this
    ->assertText($clock, 'Ensure that the clock is correctly displayed in the long date format.');

  // Test a custom date format.
  $this
    ->drupalGet('admin/build/block/configure/clock/clock');
  $this
    ->assertNoText('Custom date format', 'Ensure that no custom date formats are displayed if there are none.');

  // Create a custom date format.
  $format = 'aAbBcCdDeEfFgGhHiIjJlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ';
  $edit = array();
  $edit['add_date_format'] = $format;
  $this
    ->drupalPost('admin/settings/date-time/formats/add', $edit, 'Save configuration');
  $this
    ->drupalGet('admin/build/block/configure/clock/clock');

  // Set the clock block to display the custom format.
  $edit = array();
  $edit['date_format'] = 'custom';
  $edit['custom_date_format'] = $format;
  $this
    ->drupalPost('admin/build/block/configure/clock/clock', $edit, 'Save block');
  $clock = date_format_date(date_now(), 'custom', $format);
  $this
    ->assertText($clock, 'Ensure that the clock is correctly displayed in a custom format.');
}