drupalCreateContentType(['type' => 'page', 'name' => t('Basic page')]); // Add scheduler functionality to the page node type. /** @var NodeTypeInterface $node_type */ $node_type = NodeType::load('page'); $node_type->setThirdPartySetting('scheduler', 'publish_enable', TRUE); $node_type->setThirdPartySetting('scheduler', 'unpublish_enable', TRUE); $node_type->save(); // Create an administrator user. $this->adminUser = $this->drupalCreateUser([ 'access content', 'administer scheduler', 'create page content', 'edit own page content', 'delete own page content', 'view own unpublished content', 'administer nodes', 'schedule (un)publishing of nodes', ]); } /** * Tests basic scheduling of content. */ public function testTry() { // Show if the old and new formatters give the same result $minus_one_day = strtotime('-1 day'); $old_and_new = [ 'old format_date()' => format_date($minus_one_day, 'custom', $this->datetimeFormat), 'new date.formatter' => \Drupal::service('date.formatter')->format($minus_one_day, 'custom', $this->datetimeFormat), ]; debug($old_and_new, '>>> 1. $old_and_new'); $edit = [ 'title[0][value]' => '>>> 2. date.formatter time() - 60*60*24', 'publish_on[0][value][date]' => \Drupal::service('date.formatter')->format(time() - 60*60*24, 'custom', $this->dateOnlyFormat), 'publish_on[0][value][time]' => \Drupal::service('date.formatter')->format(time() - 60*60*24, 'custom', $this->timeOnlyFormat), 'promote[value]' => 1, ]; debug($edit, 'edit'); $this->drupalLogin($this->adminUser); // If run after login, gives date time -13 hours ago instead of -24. Is this AUS +11 hrs - 1 day? $edit = [ 'title[0][value]' => '>>> 3. date.formatter strToTime(-1 day)', 'publish_on[0][value][date]' => \Drupal::service('date.formatter')->format(strtotime('-1 day'), 'custom', $this->dateOnlyFormat), 'publish_on[0][value][time]' => \Drupal::service('date.formatter')->format(strtotime('-1 day'), 'custom', $this->timeOnlyFormat), 'body[0][value]' => \Drupal::service('date.formatter')->format(strtotime('-1 day'), 'custom', $this->datetimeFormat), ]; debug($edit, 'edit'); $this->drupalLogout(); // Logout does not fix it. Seems default timezone is now set for anonymous users too. $edit = [ 'title[0][value]' => '>>> 4. date.formatter $minus_one_day', 'publish_on[0][value][date]' => \Drupal::service('date.formatter')->format($minus_one_day, 'custom', $this->dateOnlyFormat), 'publish_on[0][value][time]' => \Drupal::service('date.formatter')->format($minus_one_day, 'custom', $this->timeOnlyFormat), 'body[0][value]' => \Drupal::service('date.formatter')->format($minus_one_day, 'custom', $this->datetimeFormat), ]; debug($edit, 'edit'); } }