You are here

function PublicationDateTestCase::testActionSaving in Publication Date 7

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

Test automatic saving of variables.

File

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

Class

PublicationDateTestCase
@file Publication Date module tests.

Code

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');

  // 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');

  // 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');

  // 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');

  // Now try it by purely pushing the forms around.
}