You are here

public function AgendaBlockTestCase::testNicknamedDays in Agenda 7.2

Same name and namespace in other branches
  1. 7 agenda.test \AgendaBlockTestCase::testNicknamedDays()

File

./agenda.test, line 26
Tests for the Agenda module.

Class

AgendaBlockTestCase

Code

public function testNicknamedDays() {

  // Get sample block.
  $block = agenda_settings(1);

  // Timezone.
  $tz = new DateTimeZone($block->timezone);

  // Parse the update timestamp.
  $updated = new DateTime("now", $tz);

  // Loop through all use cases.
  $use_cases = array(
    'yesterday',
    'today',
    'tomorrow',
  );
  foreach ($use_cases as $use_case) {
    $events = array();

    // Construct an event.
    $event = array();
    $event['title'] = "Testing {$use_case}";
    $event['where'] = '';
    $event['description'] = '';
    $event['timezone'] = $block->timezone;

    // Below several parameters are necessary for block appearance.
    $event['index'] = 1;
    $event['calendar'] = 'Calendar title';

    // One day all-day event.
    switch ($use_case) {
      case 'yesterday':
        $start = new DateTime("-1 day", $tz);
        $end = new DateTime("now", $tz);
        break;
      case 'today':
        $start = new DateTime("now", $tz);
        $end = new DateTime("+1 day", $tz);
        break;
      case 'tomorrow':
        $start = new DateTime("+1 day", $tz);
        $end = new DateTime("+2 days", $tz);
        break;
    }
    $event['start date'] = $start
      ->format($block->dateformat);
    $event['start time'] = $start
      ->format($block->timeformat);

    // Use strtotime instead of getTimestamp for < PHP5.3.
    $event['start timestamp'] = strtotime($start
      ->format('c'));
    $event['end date'] = $end
      ->format($block->dateformat);
    $event['end time'] = $end
      ->format($block->timeformat);
    $event['end timestamp'] = strtotime($end
      ->format('c'));
    $event['updated'] = $updated
      ->format($block->dateformat);

    // The day the event occurs on (without time) used for grouping
    $event['when'] = $start
      ->format('Y-m-d');
    $events[] = $event;

    // Group the events by date.
    $events = agenda_group_events_for_block($block, $events);

    // Get the output of the block.
    $output = theme('agenda_block', array(
      'block' => $block,
      'events' => $events,
    ));

    // Test the output.
    $this
      ->verbose($output);
    $this
      ->assertTrue(strpos($output, $nicknamed_day = ucfirst($use_case)) !== FALSE, "{$use_case} : {$nicknamed_day} found");
  }
}