You are here

public function PublicationDateTestCase::testActionSaving in Publication Date 7.2

Same name and namespace in other branches
  1. 7 tests/publication_date.test \PublicationDateTestCase::testActionSaving()

Test automatic saving of variables.

File

tests/publication_date.test, line 47
Publication Date module tests.

Class

PublicationDateTestCase
Test publication date functionality.

Code

public function testActionSaving() {

  // Create node to edit.
  $node = $this
    ->drupalCreateNode(array(
    'status' => 0,
  ));
  $unpublished_node = node_load($node->nid);
  $this
    ->assertTrue(empty($unpublished_node->published_at), 'Published date is initially empty');
  $this
    ->assertTrue($unpublished_node->published_at_or_now == REQUEST_TIME, 'Published at or now date is REQUEST_TIME');

  // Publish the node.
  $unpublished_node->status = 1;
  node_save($unpublished_node);
  $published_node = node_load($node->nid);
  $this
    ->assertTrue(is_numeric($published_node->published_at), 'Published date is integer/numberic once published');
  $this
    ->assertTrue($published_node->published_at == REQUEST_TIME, 'Published date is REQUEST_TIME');
  $this
    ->assertTrue($unpublished_node->published_at_or_now == $published_node->published_at, 'Published at or now date equals published date');

  // Remember time.
  $time = $published_node->published_at;

  // Unpublish the node and check that the field value is maintained.
  $published_node->status = 0;
  node_save($published_node);
  $unpublished_node = node_load($node->nid);
  $this
    ->assertTrue($unpublished_node->published_at == $time, 'Published date is maintained when unpublished');

  // Set the field to zero and and make sure the published date is empty.
  $unpublished_node->published_at = 0;
  node_save($unpublished_node);
  $unpublished_node = node_load($node->nid);
  $this
    ->assertTrue(empty($unpublished_node->published_at), 'Published date is empty when reset');

  // Set a custom time and make sure that it is saved.
  $time = $unpublished_node->published_at = 122630400;
  node_save($unpublished_node);
  $unpublished_node = node_load($node->nid);
  $this
    ->assertTrue($unpublished_node->published_at == $time, 'Custom published date is saved');
  $this
    ->assertTrue($unpublished_node->published_at_or_now == $time, 'Published at or now date equals published date');

  // Republish the node and check that the field value is maintained.
  $unpublished_node->status = 1;
  node_save($unpublished_node);
  $published_node = node_load($node->nid);
  $this
    ->assertTrue($published_node->published_at == $time, 'Custom published date is maintained when republished');

  // Set the field to zero and and make sure the published date is reset.
  $published_node->published_at = 0;
  node_save($published_node);
  $published_node = node_load($node->nid);
  $this
    ->assertTrue($published_node->published_at > $time, 'Published date is reset');
}