You are here

public function DateRecurTokenTest::testTokens in Recurring Dates Field 3.0.x

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

Tests tokens.

File

tests/src/Kernel/DateRecurTokenTest.php, line 47

Class

DateRecurTokenTest
Tests token functionality provided by token.module.

Namespace

Drupal\Tests\date_recur\Kernel

Code

public function testTokens() {
  $user = User::create([
    'uid' => 2,
    // UTC+8.
    'timezone' => 'Asia/Singapore',
  ]);
  $this->container
    ->get('current_user')
    ->setAccount($user);
  $entity = DrEntityTest::create();
  $entity->dr = [
    'value' => '2014-06-15T23:00:00',
    'end_value' => '2014-06-16T07:00:00',
    'rrule' => 'FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR',
    'infinite' => '1',
    // UTC+7.
    'timezone' => 'Indian/Christmas',
  ];

  // Start date token.
  $replaced = \Drupal::token()
    ->replace('[dr_entity_test:dr:start_date:long]', [
    'dr_entity_test' => $entity,
  ]);
  $this
    ->assertEquals('Monday, June 16, 2014 - 07:00', $replaced);

  // End date token.
  $replaced = \Drupal::token()
    ->replace('[dr_entity_test:dr:end_date:long]', [
    'dr_entity_test' => $entity,
  ]);
  $this
    ->assertEquals('Monday, June 16, 2014 - 15:00', $replaced);
}