You are here

public function DateRecurBasicFormatterTest::testFormatterSameDay in Recurring Dates Field 8.2

Same name and namespace in other branches
  1. 3.x tests/src/Kernel/DateRecurBasicFormatterTest.php \Drupal\Tests\date_recur\Kernel\DateRecurBasicFormatterTest::testFormatterSameDay()
  2. 3.0.x tests/src/Kernel/DateRecurBasicFormatterTest.php \Drupal\Tests\date_recur\Kernel\DateRecurBasicFormatterTest::testFormatterSameDay()
  3. 3.1.x tests/src/Kernel/DateRecurBasicFormatterTest.php \Drupal\Tests\date_recur\Kernel\DateRecurBasicFormatterTest::testFormatterSameDay()

Tests formatter output for same start/end date.

It doesnt matter which time zone the data is in, we only check same date for the current logged in user.

File

tests/src/Kernel/DateRecurBasicFormatterTest.php, line 422

Class

DateRecurBasicFormatterTest
Tests date recur formatter.

Namespace

Drupal\Tests\date_recur\Kernel

Code

public function testFormatterSameDay() {
  $user = User::create([
    'uid' => 2,
    // UTC+10.
    'timezone' => 'Pacific/Port_Moresby',
  ]);
  $this->container
    ->get('current_user')
    ->setAccount($user);
  $dateFormatSameDate = DateFormat::create([
    'id' => $this
      ->randomMachineName(),
    'pattern' => '\\s\\a\\m\\e \\d\\a\\t\\e',
  ]);
  $dateFormatSameDate
    ->save();
  $settings = [
    'format_type' => $this->dateFormat
      ->id(),
    'occurrence_format_type' => $this->dateFormat
      ->id(),
    'same_end_date_format_type' => $dateFormatSameDate
      ->id(),
    'interpreter' => $this->interpreter
      ->id(),
  ];
  $entity = DrEntityTest::create();
  $entity->dr = [
    // 10pm-9:59:59pm HK time.
    'value' => '2014-06-14T14:00:00',
    'end_value' => '2014-06-15T13:59:59',
    'rrule' => '',
    'infinite' => '0',
    // HK is UTC+8.
    'timezone' => 'Asia/Hong_Kong',
  ];
  $this
    ->renderFormatterSettings($entity, $settings);
  $dates = $this
    ->cssSelect('time');
  $this
    ->assertCount(2, $dates);

  // First time is start date.
  $this
    ->assertEquals('Sun, 15 Jun 2014 00:00:00 +1000', (string) $dates[0]);

  // Second time is end date.
  $this
    ->assertEquals('same date', (string) $dates[1]);
}