1 node.test NodePublishScheduling::testNodeTypeCreateDefaultDraft()

File

core/modules/node/tests/node.test, line 3915
Tests for node.module.

Class

NodePublishScheduling
Tests Draft, Published, Schedule Publish Time options for node types and node instances.

Code

function testNodeTypeCreateDefaultDraft() {
  // Create a content type of foobar via the user interface.
  $this->admin_user = $this->backdropCreateUser(array('bypass node access', 'administer nodes'));
  $web_user = $this->backdropCreateUser(array('bypass node access', 'administer content types', 'administer nodes'));
  $this->backdropLogin($web_user);
  $edit = array(
    'name' => 'foobar',
    'title_label' => 'title for foobar',
    'type' => 'foobar',
    'status_default' => 0,
  );
  $this->backdropPost('admin/structure/types/add', $edit, t('Save content type'));
  // Create a node of type foobee and assert that its published-state is set
  // to Draft.
  $name = $this->randomName(8);
  $edit = array(
    'title' => $name,
  );
  $this->backdropPost('node/add/foobar', $edit, t('Save'));
  $node = $this->backdropGetNodeByTitle($name);
  $this->assertEqual($node->status, '0', 'The node is in the state Draft.');

  // Create a content type of type foobee via the user interface.
  $edit = array(
    'name' => 'foobee',
    'title_label' => 'title for foobee',
    'type' => 'foobee',
    'status_default' => 1,
  );
  $this->backdropPost('admin/structure/types/add', $edit, t('Save content type'));
  // Create a node of type foobee and assert that its published-state is set
  // to Published.
  $name = $this->randomName(8);
  $edit = array(
    'title' => $name,
  );
  $this->backdropPost('node/add/foobee', $edit, t('Save'));
  $node = $this->backdropGetNodeByTitle($name);
  $this->assertEqual($node->status, '1', 'The node is in the state Published.');

  // Create a content type of type foobsee via the user interface.
  $edit = array(
    'name' => 'foobsee',
    'title_label' => 'title for foobsee',
    'type' => 'foobsee',
    'status_default' => 2,
  );
  $this->backdropPost('admin/structure/types/add', $edit, t('Save content type'));

  // Create a node of type foobee and assert that its published-state is set
  // to Draft.
  $name = $this->randomName(8);
  $edit = array(
    'title' => $name,
    // Schedule five minutes into the future to be sure we past the current time.
    'scheduled[date]' => format_date(REQUEST_TIME + 300, 'custom', 'Y-m-d', $web_user->timezone),
    'scheduled[time]' => format_date(REQUEST_TIME + 300, 'custom', 'H:i:s', $web_user->timezone),
  );
  $this->backdropPost('node/add/foobsee', $edit, t('Save'));

  $node = $this->backdropGetNodeByTitle($name);
  $this->assertEqual($node->status, '0', 'The node is in the state Unpublished.');
  $this->assertNotEqual($node->scheduled, 0, 'The node has a non zero scheduled date.');

  // Set the scheduled date in the past and run cron.
  $node->scheduled = 1;
  node_save($node);
  $this->cronRun();
  $node = node_load($node->nid);
  $this->assertEqual($node->status, '1', 'The node is in the state Published.');

  // Ensure Node module still checks the date is valid.
  $name = $this->randomName(9);
  $invalid_date = format_date(REQUEST_TIME, 'custom', 'dddY-m-d', $web_user->timezone);
  $edit = array(
    'title' => $name,
    'status' => NODE_SCHEDULED,
    'scheduled[date]' => $invalid_date,
    'scheduled[time]' => format_date(REQUEST_TIME, 'custom', 'H:i', $web_user->timezone),
  );
  $this->backdropPost('node/add/foobsee', $edit, t('Save'));
  $this->assertText(t('@date is not a valid date.', array('@date' => $invalid_date)));

  // Ensure scheduling in the past is not allowed.
  $edit = array(
    'title' => $name,
    'status' => NODE_SCHEDULED,
    'scheduled[date]' => format_date(REQUEST_TIME - 300, 'custom', 'Y-m-d', $web_user->timezone),
    'scheduled[time]' => format_date(REQUEST_TIME - 300, 'custom', 'H:i:s', $web_user->timezone),
  );
  $this->backdropPost('node/add/foobsee', $edit, t('Save'));
  $this->assertText(t('Scheduled publish time cannot be in the past.'));
}