You are here

public function DateRecurModularSierraTest::testUserNoTimeZone in Recurring Date Field Modular Widgets 8

Same name and namespace in other branches
  1. 3.x tests/src/Functional/DateRecurModularSierraTest.php \Drupal\Tests\date_recur_modular\Functional\DateRecurModularSierraTest::testUserNoTimeZone()
  2. 2.x tests/src/Functional/DateRecurModularSierraTest.php \Drupal\Tests\date_recur_modular\Functional\DateRecurModularSierraTest::testUserNoTimeZone()

Tests user without time zone.

File

tests/src/Functional/DateRecurModularSierraTest.php, line 57

Class

DateRecurModularSierraTest
Tests Sierra Widget.

Namespace

Drupal\Tests\date_recur_modular\Functional

Code

public function testUserNoTimeZone() : void {

  // Turn of configurable time zone so \system_user_presave() doesn't
  // set a default timezone field value on save.
  \Drupal::configFactory()
    ->getEditable('system.date')
    ->set('timezone.user.configurable', FALSE)
    ->save();
  $user = $this
    ->drupalCreateUser([
    'administer entity_test content',
  ]);

  // When this user is logged in it should get Sydney timezone.
  $user->timezone = '';
  $user
    ->save();

  // Make sure timezone isn't changed elsewhere.
  $this
    ->assertNull($user->timezone->value);
  $this
    ->drupalLogin($user);

  // Test a date/time appears as all-day.
  $entity = DrEntityTest::create();
  $entity->dr = [
    // Time is 00:00am Sydney. (UTC+10)
    'value' => '2015-05-13T14:00:00',
    // Time is 11:59:59pm Sydney.
    'end_value' => '2015-05-14T13:59:59',
    'rrule' => 'FREQ=WEEKLY;INTERVAL=1;COUNT=1',
    // Doesnt matter what time zone storage is.
    'timezone' => 'Asia/Singapore',
  ];
  $entity
    ->save();
  $this
    ->drupalGet($entity
    ->toUrl('edit-form'));
  $this
    ->assertSession()
    ->checkboxChecked('dr[0][is_all_day]');

  // Test a date/time that does not appear as all-day.
  $entity = DrEntityTest::create();
  $entity->dr = [
    // Time is 00:00am Sydney. (UTC+10)
    'value' => '2015-05-13T14:00:00',
    // Time is 11:58:59pm Sydney.
    'end_value' => '2015-05-14T13:58:59',
    'rrule' => 'FREQ=WEEKLY;INTERVAL=1;COUNT=1',
    // Doesnt matter what time zone storage is.
    'timezone' => 'Asia/Singapore',
  ];
  $entity
    ->save();
  $this
    ->drupalGet($entity
    ->toUrl('edit-form'));
  $this
    ->assertSession()
    ->checkboxNotChecked('dr[0][is_all_day]');
}