You are here

protected function SchedulerJavascriptDefaultTimeTest::setUp in Scheduler 2.x

Same name and namespace in other branches
  1. 8 tests/src/FunctionalJavascript/SchedulerJavascriptDefaultTimeTest.php \Drupal\Tests\scheduler\FunctionalJavascript\SchedulerJavascriptDefaultTimeTest::setUp()

Overrides SchedulerJavascriptTestBase::setUp

File

tests/src/FunctionalJavascript/SchedulerJavascriptDefaultTimeTest.php, line 22

Class

SchedulerJavascriptDefaultTimeTest
Tests the JavaScript functionality for default dates.

Namespace

Drupal\Tests\scheduler\FunctionalJavascript

Code

protected function setUp() : void {
  parent::setUp();

  // Determine whether the HTML5 date picker is expecting d/m/Y or m/d/Y
  // because this varies with the locale and cannot be set or predetermined
  // using the site timezone. This is a bit of hack but it is necessary due
  // to local testing having a different locale to drupal.org testing.
  // @see https://www.drupal.org/project/scheduler/issues/2913829 from #18.
  $this
    ->drupalLogin($this->schedulerUser);
  $this
    ->drupalGet('node/add/' . $this->type);
  $page = $this
    ->getSession()
    ->getPage();
  $title = 'Determine the date-picker format';
  $page
    ->fillField('edit-title-0-value', $title);
  $page
    ->clickLink('Scheduling options');

  // Set the date using a day and month which could be correctly interpreted
  // either way. Set the year to be next year to ensure a future date.
  // Use a time format which includes 'pm' as this may be necessary, and will
  // be ignored if the time widget wants hh:mm:ss in 24 hours format.
  $page
    ->fillField('edit-publish-on-0-value-date', '05/02/' . (date('Y') + 1));
  $page
    ->fillField('edit-publish-on-0-value-time', '06:00:00pm');
  $page
    ->pressButton('Save');
  $node = $this
    ->drupalGetNodeByTitle($title);

  // If the saved month is 2 then the format is d/m/Y, otherwise it is m/d/Y.
  $this->datepickerFormat = date('n', $node->publish_on->value) == 2 ? 'd/m/Y' : 'm/d/Y';
}