View source
<?php
namespace Drupal\Tests\date_recur\Kernel;
use Drupal\date_recur_entity_test\Entity\DrEntityTest;
use Drupal\KernelTests\KernelTestBase;
use Drupal\user\Entity\User;
class DateRecurTokenTest extends KernelTestBase {
protected static $modules = [
'date_recur_entity_test',
'entity_test',
'datetime',
'datetime_range',
'date_recur',
'field',
'user',
'token',
'text',
'filter',
'system',
];
protected function setUp() : void {
parent::setUp();
$this
->installConfig([
'system',
]);
}
public function testTokens() {
$user = User::create([
'uid' => 2,
'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',
'timezone' => 'Indian/Christmas',
];
$replaced = \Drupal::token()
->replace('[dr_entity_test:dr:start_date:long]', [
'dr_entity_test' => $entity,
]);
$this
->assertEquals('Monday, June 16, 2014 - 07:00', $replaced);
$replaced = \Drupal::token()
->replace('[dr_entity_test:dr:end_date:long]', [
'dr_entity_test' => $entity,
]);
$this
->assertEquals('Monday, June 16, 2014 - 15:00', $replaced);
}
}