You are here

public function PublicationDateTest::testActionSavingSetDate in Publication Date 8

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/PublicationDateTest.php \Drupal\publication_date\Tests\PublicationDateTest::testActionSavingSetDate()

File

src/Tests/PublicationDateTest.php, line 184
Contains \Drupal\publication_date\Tests\PublicationDateTest.

Class

PublicationDateTest
Tests for publication_date.

Namespace

Drupal\publication_date\Tests

Code

public function testActionSavingSetDate() {
  $node = $this
    ->drupalCreateNode(array(
    'status' => 0,
  ));
  $unpublished_node = node_load($node
    ->id());
  $this
    ->assertTrue(empty($unpublished_node->published_at->value), 'Published date is initially empty');

  // Now publish this with our custom time...
  $unpublished_node->status = 1;
  $static_time = 12345678;
  $unpublished_node->published_at->value = $static_time;
  $unpublished_node
    ->save();
  $published_node = node_load($node
    ->id());

  // ...and see if it comes back with it correctly.
  $this
    ->assertTrue(is_numeric($published_node->published_at->value), 'Published date is integer/numberic once published');
  $this
    ->assertTrue($published_node->published_at->value == $static_time, 'Published date is set to what we expected');
}