Commit c53fd9cb authored by Jonathan Smith's avatar Jonathan Smith Committed by Pieter Frenssen
Browse files

Issue #2365707 by jonathan1055: Fixed Missing validation allows Unpublish date to be blank.

parent 36b3afff
Loading
Loading
Loading
Loading
+7 −0
Changes for scheduler.module: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -1153,9 +1153,16 @@ function scheduler_node_validate($node, $form) {
      form_set_error('unpublish_on', t("The 'unpublish on' date must be in the future"));
    }
  }

  if (isset($publishtime) && isset($unpublishtime) && $unpublishtime < $publishtime) {
    form_set_error('unpublish_on', t("The 'unpublish on' date must be later than the 'publish on' date."));
  }

  // The unpublish-on 'required' form attribute may not be set in some cases,
  // but a value must be entered if also setting a publish-on date.
  if (variable_get('scheduler_unpublish_required_' . $node->type) && !empty($node->publish_on) && empty($node->unpublish_on)) {
    form_set_error('unpublish_on', t("If you set a 'publish-on' date then you must also set an 'unpublish-on' date."));
  }
}

/**
+20 −2
Changes for scheduler.test: 20 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -302,11 +302,9 @@ class SchedulerTestCase extends DrupalWebTestCase {
    $this->drupalLogin($this->admin_user);

    // First test the regular date entry, without popup.
    debug('Testing default time using a textfield');
    $this->assertDefaultTime();

    // Enable date popup and repeat the test.
    debug('Testing default time using date popup');
    variable_set('scheduler_field_type', 'date_popup');
    $this->assertDefaultTime();
  }
@@ -550,6 +548,26 @@ class SchedulerTestCase extends DrupalWebTestCase {
    }
  }

  /**
   * Tests the validation when editing a node.
   */
  function testValidationDuringEdit() {
    $this->drupalLogin($this->admin_user);

    // Create an unpublished page node.
    $node = $this->drupalCreateNode(array('type' => 'page', 'status' => FALSE, 'title' => $this->randomName()));

    // Set unpublishing to be required.
    variable_set('scheduler_unpublish_required_page', TRUE);

    // Edit the node and check the validation.
    $edit = array(
      'publish_on' => date('Y-m-d H:i:s', strtotime('+1 day', REQUEST_TIME)),
    );
    $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
    $this->assertRaw(t("If you set a 'publish-on' date then you must also set an 'unpublish-on' date."), 'Validation prevents entering a publish-on date with no unpublish-on date if unpublishing is required.');
  }

  /**
   * Tests configuration of different date formats with the Date Popup field.
   */