You are here

save_draft.test in Save Draft 6.2

Same filename and directory in other branches
  1. 7 save_draft.test

File

save_draft.test
View source
<?php

class SaveDraftTestCase extends DrupalWebTestCase {
  protected $admin;
  public static function getInfo() {
    return array(
      'name' => 'Save draft',
      'description' => 'Make sure the node form still works with Save Draft enabled.',
      'group' => 'Save draft',
    );
  }
  public function setUp() {
    parent::setUp(array(
      'save_draft',
    ));
    $this->admin = $this
      ->drupalCreateUser(array(
      'create story content',
      'edit any story content',
      'administer nodes',
    ));
    $this
      ->drupalLogin($this->admin);
    $this->title_key = "title";
    $this->body_key = "body";
  }

  /**
   * Return a basic $edit array that can be used to save a node.
   */
  public function getNodeArray() {
    $edit = array();
    $edit[$this->title_key] = $this
      ->randomName(8);
    $edit[$this->body_key] = $this
      ->randomName(8);
    return $edit;
  }

  /**
   * Make sure nodes save with the right publication status.
   */
  public function testNodeSave() {

    // Publish a node, and make sure it's published.
    $edit = $this
      ->getNodeArray();
    $this
      ->drupalPost('node/add/story', $edit, t('Publish'));
    $node = $this
      ->drupalGetNodeByTitle($edit[$this->title_key]);
    $this
      ->assertEqual($node->status, 1, t('Node saved correctly.'));

    // Unpublish it, and make sure it's unpublished.
    $this
      ->drupalPost("node/{$node->nid}/edit", array(), t('Save as unpublish'));
    $node = node_load($node->nid, NULL, TRUE);
    $this
      ->assertEqual($node->status, 0, t('Node unpublished correctly.'));

    // Save a new node as a draft, and make sure it's unpublished.
    $edit = $this
      ->getNodeArray();
    $this
      ->drupalPost('node/add/story', $edit, t('Save as Draft'));
    $node = $this
      ->drupalGetNodeByTitle($edit[$this->title_key]);
    $this
      ->assertEqual($node->status, 0, t('Node saved correctly as draft.'));

    // Publish the node, and make sure it's published.
    $this
      ->drupalPost("node/{$node->nid}/edit", array(), t('Save Changes'));
    $node = node_load($node->nid, NULL, TRUE);
    $this
      ->assertEqual($node->status, 1, t('Node published correctly.'));
  }

}

Classes

Namesort descending Description
SaveDraftTestCase