You are here

public function SchedulerFunctionalTest::testNonEnabledType in Scheduler 7

Test that Scheduler does not interfere with non-scheduler-enabled nodes.

File

tests/scheduler.test, line 558
Scheduler module test case file.

Class

SchedulerFunctionalTest
Tests the scheduler interface.

Code

public function testNonEnabledType() {

  // Create a 'Non-enabled' content type.
  $this
    ->drupalCreateContentType(array(
    'type' => 'story',
    'name' => t('Story Book'),
  ));

  // Create a user who can add and edit story content, and log in.
  $this
    ->drupalLogin($this
    ->drupalCreateUser(array(
    'access content overview',
    'access site reports',
    'create story content',
    'delete own story content',
    'edit own story content',
    'schedule publishing of nodes',
    'view scheduled content',
    'view own unpublished content',
  )));
  foreach ($this
    ->dataNonEnabledType() as $data) {
    list($id, $description, $publishing_enabled, $unpublishing_enabled) = $data;

    // The first test case specifically checks the behavior of the default
    // unchanged settings, so only change these settings for later runs.
    if ($id > 0) {
      variable_set('scheduler_publish_enable_story', $publishing_enabled);
      variable_set('scheduler_unpublish_enable_story', $unpublishing_enabled);
    }

    // Create info string to show what combinations are being tested.
    $info = 'Publishing ' . ($publishing_enabled ? 'enabled' : 'not enabled') . ', Unpublishing ' . ($unpublishing_enabled ? 'enabled' : 'not enabled') . ', ' . $description;

    // Check that the field(s) are displayed only for the correct settings.
    $title = $id . 'a - ' . $info;
    $this
      ->drupalGet('node/add/story');
    if ($publishing_enabled) {
      $this
        ->assertFieldByName('publish_on', '', "The Publish-on field is shown: {$title}");
    }
    else {
      $this
        ->assertNoFieldByName('publish_on', '', "The Publish-on field is not shown: {$title}");
    }
    if ($unpublishing_enabled) {
      $this
        ->assertFieldByName('unpublish_on', '', "The Unpublish-on field is shown: {$title}");
    }
    else {
      $this
        ->assertNoFieldByName('unpublish_on', '', "The Unpublish-on field is not shown: {$title}");
    }

    // When publishing and/or unpublishing are not enabled but the 'required'
    // setting remains on, the node must be able to be saved without a date.
    variable_set('scheduler_publish_required_story', !$publishing_enabled);
    variable_set('scheduler_unpublish_required_story', !$unpublishing_enabled);
    $this
      ->drupalPost('node/add/story', array(
      'title' => $title,
    ), t('Save'));

    // Check that the node has saved OK.
    $string = sprintf('%s %s has been created.', 'Story Book', check_plain($title));
    $this
      ->assertText($string, "Node added: {$title}");

    // Check that the node can be editted and saved again.
    $node = $this
      ->drupalGetNodeByTitle($title);
    if ($node) {
      $this
        ->drupalPost('node/' . $node->nid . '/edit', array(), t('Save'));
      $string = sprintf('%s %s has been updated.', 'Story Book', check_plain($title));
      $this
        ->assertText($string, "Node updated: {$title}");
    }
    else {
      $this
        ->fail("No node to edit: {$title}");
    }

    // Create an unpublished node with a publishing date, which mimics what
    // could be done by a third-party module, or a by-product of the node type
    // being enabled for publishing then being disabled before publishing.
    $title = $id . 'b - ' . $info;
    $edit = array(
      'title' => $title,
      'status' => FALSE,
      'type' => 'story',
      'publish_on' => strtotime('- 2 min', REQUEST_TIME),
    );
    $node = $this
      ->drupalCreateNode($edit);

    // Run cron and display the dblog.
    $this
      ->cronRun();
    $this
      ->drupalGet('admin/reports/dblog');

    // Reload the node.
    $node = node_load($node->nid, NULL, TRUE);

    // Check if the node has been published or remains unpublished.
    if ($publishing_enabled) {
      $this
        ->assertTrue($node->status, 'The unpublished node has been published: ' . $title);
    }
    else {
      $this
        ->assertFalse($node->status, 'The unpublished node remains unpublished: ' . $title);
    }

    // Do the same for unpublishing.
    $title = $id . 'c - ' . $info;
    $edit = array(
      'title' => $title,
      'status' => TRUE,
      'type' => 'story',
      'unpublish_on' => strtotime('- 2 min', REQUEST_TIME),
    );
    $node = $this
      ->drupalCreateNode($edit);

    // Run cron and display the dblog.
    $this
      ->cronRun();
    $this
      ->drupalGet('admin/reports/dblog');

    // Reload the node.
    $node = node_load($node->nid, NULL, TRUE);

    // Check if the node has been unpublished or remains published.
    if ($unpublishing_enabled) {
      $this
        ->assertFalse($node->status, 'The published node has been unpublished: ' . $title);
    }
    else {
      $this
        ->assertTrue($node->status, 'The published node remains published: ' . $title);
    }

    // Display the full content list and the scheduled list. Calls to these
    // pages are for information and debug only. They could be removed.
    $this
      ->drupalGet('admin/content');
    $this
      ->drupalGet('admin/content/scheduler');
  }
}