You are here

public function ClockBlockTestCase::testClockBlock in Clock 7.2

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

File

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

Class

ClockBlockTestCase
@file Tests for Clock module.

Code

public function testClockBlock() {

  // Add a new clock for each time zone type.
  $time_zone_types = array(
    'site' => variable_get('date_default_timezone', 'UTC'),
    'user' => NULL,
    'local' => variable_get('date_default_timezone', 'UTC'),
    'custom' => 'UTC',
  );
  foreach ($time_zone_types as $type => $time_zone) {
    $edit = array();
    $edit['time_zone_type'] = $type;
    $edit['date_type'] = 'long';
    $this
      ->drupalPost('admin/structure/block/manage/clock/clock/configure/add', $edit, 'Save');
    $clock = date_format_date(date_now($time_zone), 'long');
    $this
      ->assertText($clock, "Adding a clock with the {$type} time zone type works.");
  }

  // Edit the first block to show each date type.
  $clocks = clock_info();
  $cids = array_keys($clocks);
  $cid = $cids[0];
  foreach (system_get_date_types() as $type => $info) {
    $stub = new StdClass();
    $stub->date_type = $type;
    $format = clock_get_date_format($stub);
    $edit = array();
    $edit['date_type'] = $type;
    $this
      ->drupalPost("admin/structure/block/manage/clock/clock/configure/{$cid}/edit", $edit, 'Save');
    $clock = date_format_date(date_now(NULL), 'custom', $format);
    $this
      ->assertText($clock, "Editing a clock to show the {$type} date format type works.");
  }

  // Reorder the clocks.
  $clocks = clock_info();
  $cids = array_keys($clocks);
  $output = '';
  foreach (array(
    0,
    1,
    2,
    3,
  ) as $i) {
    $clock = date_format_date(date_now(clock_get_time_zone($clocks[$cids[$i]])), 'custom', clock_get_date_format($clocks[$cids[$i]]));
    $output .= '<div class="clock clock-' . $cids[$i] . '">' . $clock . '</div>';
  }
  $this
    ->assertRaw($output, 'Multiple clocks are displayed correctly.');
  $edit = array();
  $edit['clocks[' . $cids[0] . '][4]'] = 1;
  $edit['clocks[' . $cids[1] . '][4]'] = 0;
  $edit['clocks[' . $cids[2] . '][4]'] = 3;
  $edit['clocks[' . $cids[3] . '][4]'] = 2;
  $this
    ->drupalPost('admin/structure/block/manage/clock/clock/configure', $edit, 'Save block');
  $output = '';
  foreach (array(
    1,
    0,
    3,
    2,
  ) as $i) {
    $clock = date_format_date(date_now(clock_get_time_zone($clocks[$cids[$i]])), 'custom', clock_get_date_format($clocks[$cids[$i]]));
    $output .= '<div class="clock clock-' . $cids[$i] . '">' . $clock . '</div>';
  }
  $this
    ->assertRaw($output, 'Reordering the clocks works.');

  // Deleting a clock.
  $clocks = clock_info();
  $cids = array_keys($clocks);
  $cid = $cids[0];
  $this
    ->drupalPost("admin/structure/block/manage/clock/clock/configure/{$cid}/delete", NULL, 'Delete');
  $clocks = clock_info();
  $this
    ->assertTrue(!isset($clocks[$cid]), 'Deleting a clock works.');
}