commit 4dd04441d84e1452ddcc8a71c271af33482c911b
Author: Kab00m <Kab00m@1327142.no-reply.drupal.org>
Date:   Tue Feb 24 12:51:32 2015 +0100

    Issue #2122013 by legovaer: Separate tests that depend on the Date module.

diff --git a/scheduler.test b/scheduler.test
index 56a7eef..12d0770 100644
--- a/scheduler.test
+++ b/scheduler.test
@@ -4,8 +4,11 @@
  * @file
  * Scheduler module test case file.
  */
-class SchedulerTestCase extends DrupalWebTestCase {
 
+/**
+ * Provides common helper methods for Scheduler module tests.
+ */
+abstract class SchedulerTestBase extends DrupalWebTestCase {
   /**
    * The profile to install as a basis for testing.
    *
@@ -21,6 +24,123 @@ class SchedulerTestCase extends DrupalWebTestCase {
   protected $admin_user;
 
   /**
+   * Helper function for testScheduler(). Schedules content and asserts status.
+   */
+  function helpTestScheduler($edit) {
+    // Add a page.
+    $langcode = LANGUAGE_NONE;
+    $body = $this->randomName();
+    $edit["body[$langcode][0][value]"] = $body;
+    $this->drupalLogin($this->admin_user);
+    $this->drupalPost('node/add/page', $edit, t('Save'));
+    // Show the site front page for an anonymous visitor, then assert that the
+    // node is correctly published or unpublished.
+    $this->drupalLogout();
+    $this->drupalGet('node');
+    if (isset($edit['publish_on'])) {
+      $key = 'publish_on';
+      $this->assertNoText($body, t('Node is unpublished'));
+    }
+    else {
+      $key = 'unpublish_on';
+      $this->assertText($body, t('Node is published'));
+    }
+    // Verify that the scheduler table is not empty.
+    $this->assertTrue(db_query_range('SELECT 1 FROM {scheduler}', 0, 1)->fetchField(), 'Scheduler table is not empty');
+    // Modify the scheduler row to a time in the past, then run cron.
+    db_update('scheduler')->fields(array($key => time() - 1))->execute();
+    $this->cronRun();
+    // Verify that the scheduler table is empty.
+    $this->assertFalse(db_query_range('SELECT 1 FROM {scheduler}', 0, 1)->fetchField(), 'Scheduler table is empty');
+    // Show the site front page for an anonymous visitor, then assert that the
+    // node is correctly published or unpublished.
+    $this->drupalGet('node');
+    if (isset($edit['publish_on'])) {
+      $this->assertText($body, t('Node is published'));
+    }
+    else {
+      $this->assertNoText($body, t('Node is unpublished'));
+    }
+  }
+
+  /**
+   * Simulates the scheduled (un)publication of a node.
+   *
+   * @param object $node
+   *   The node to schedule.
+   * @param string $action
+   *   The action to perform: either 'publish' or 'unpublish'. Defaults to
+   *   'publish'.
+   *
+   * @return object
+   *   The updated node, after scheduled (un)publication.
+   */
+  function schedule($node, $action = 'publish') {
+    // Simulate scheduling by setting the (un)publication date in the past and
+    // running cron.
+    $node->{$action . '_on'} = strtotime('-1 day');
+    node_save($node);
+    scheduler_cron();
+    return node_load($node->nid, NULL, TRUE);
+  }
+
+  /**
+   * Check if the latest revision log message of a node matches a given string.
+   *
+   * @param int $nid
+   *   The node id of the node to check.
+   * @param string $value
+   *   The value with which the log message will be compared.
+   * @param string $message
+   *   The message to display along with the assertion.
+   * @param string $group
+   *   The type of assertion - examples are "Browser", "PHP".
+   *
+   * @return
+   *   TRUE if the assertion succeeded, FALSE otherwise.
+   */
+  function assertRevisionLogMessage($nid, $value, $message = '', $group = 'Other') {
+    $log_message = db_select('node_revision', 'r')
+      ->fields('r', array('log'))
+      ->condition('nid', $nid)
+      ->orderBy('vid', 'DESC')
+      ->range(0, 1)
+      ->execute()
+      ->fetchColumn();
+    return $this->assertEqual($log_message, $value, $message, $group);
+  }
+
+  /**
+   * Check if the number of revisions for a node matches a given value.
+   *
+   * @param int $nid
+   *   The node id of the node to check.
+   * @param string $value
+   *   The value with which the number of revisions will be compared.
+   * @param string $message
+   *   The message to display along with the assertion.
+   * @param string $group
+   *   The type of assertion - examples are "Browser", "PHP".
+   *
+   * @return
+   *   TRUE if the assertion succeeded, FALSE otherwise.
+   */
+  function assertRevisionCount($nid, $value, $message = '', $group = 'Other') {
+    $count = db_select('node_revision', 'r')
+      ->fields('r', array('vid'))
+      ->condition('nid', $nid)
+      ->countQuery()
+      ->execute()
+      ->fetchColumn();
+    return $this->assertEqual($count, $value, $message, $group);
+  }
+}
+
+/**
+ * Tests the scheduler interface.
+ */
+class SchedulerFunctionalTest extends SchedulerTestBase {
+  /**
    * {@inheritdoc}
    */
   public static function getInfo() {
@@ -35,13 +155,22 @@ class SchedulerTestCase extends DrupalWebTestCase {
    * {@inheritdoc}
    */
   function setUp() {
-    parent::setUp('date', 'date_popup', 'scheduler');
+    parent::setUp('scheduler');
 
     // Create a 'Basic Page' content type.
     $this->drupalCreateContentType(array('type' => 'page', 'name' => t('Basic page')));
 
     // Create an administrator user.
-    $this->admin_user = $this->drupalCreateUser(array('access content', 'administer scheduler', 'create page content', 'edit own page content', 'delete own page content', 'view own unpublished content', 'administer nodes', 'schedule (un)publishing of nodes'));
+    $this->admin_user = $this->drupalCreateUser(array(
+      'access content',
+      'administer scheduler',
+      'create page content',
+      'edit own page content',
+      'delete own page content',
+      'view own unpublished content',
+      'administer nodes',
+      'schedule (un)publishing of nodes'
+    ));
 
     // Add scheduler functionality to the page node type.
     variable_set('scheduler_publish_enable_page', 1);
@@ -67,46 +196,6 @@ class SchedulerTestCase extends DrupalWebTestCase {
   }
 
   /**
-   * Helper function for testScheduler(). Schedules content and asserts status.
-   */
-  function helpTestScheduler($edit) {
-    // Add a page.
-    $langcode = LANGUAGE_NONE;
-    $body = $this->randomName();
-    $edit["body[$langcode][0][value]"] = $body;
-    $this->drupalLogin($this->admin_user);
-    $this->drupalPost('node/add/page', $edit, t('Save'));
-    // Show the site front page for an anonymous visitor, then assert that the
-    // node is correctly published or unpublished.
-    $this->drupalLogout();
-    $this->drupalGet('node');
-    if (isset($edit['publish_on'])) {
-      $key = 'publish_on';
-      $this->assertNoText($body, t('Node is unpublished'));
-    }
-    else {
-      $key = 'unpublish_on';
-      $this->assertText($body, t('Node is published'));
-    }
-    // Verify that the scheduler table is not empty.
-    $this->assertTrue(db_query_range('SELECT 1 FROM {scheduler}', 0, 1)->fetchField(), 'Scheduler table is not empty');
-    // Modify the scheduler row to a time in the past, then run cron.
-    db_update('scheduler')->fields(array($key => time() - 1))->execute();
-    $this->cronRun();
-    // Verify that the scheduler table is empty.
-    $this->assertFalse(db_query_range('SELECT 1 FROM {scheduler}', 0, 1)->fetchField(), 'Scheduler table is empty');
-    // Show the site front page for an anonymous visitor, then assert that the
-    // node is correctly published or unpublished.
-    $this->drupalGet('node');
-    if (isset($edit['publish_on'])) {
-      $this->assertText($body, t('Node is published'));
-    }
-    else {
-      $this->assertNoText($body, t('Node is unpublished'));
-    }
-  }
-
-  /**
    * Test the different options for past publication dates.
    */
   public function testSchedulerPastDates() {
@@ -220,155 +309,7 @@ class SchedulerTestCase extends DrupalWebTestCase {
     $this->assertTrue($this->xpath('//fieldset[@id = "edit-scheduler-settings" and not(contains(@class, "collapsed"))]'), 'The scheduler options are shown as an expanded fieldset.');
   }
 
-  /**
-   * Simulates the scheduled (un)publication of a node.
-   *
-   * @param object $node
-   *   The node to schedule.
-   * @param string $action
-   *   The action to perform: either 'publish' or 'unpublish'. Defaults to
-   *   'publish'.
-   *
-   * @return object
-   *   The updated node, after scheduled (un)publication.
-   */
-  function schedule($node, $action = 'publish') {
-    // Simulate scheduling by setting the (un)publication date in the past and
-    // running cron.
-    $node->{$action . '_on'} = strtotime('-1 day');
-    node_save($node);
-    scheduler_cron();
-    return node_load($node->nid, NULL, TRUE);
-  }
-
-  /**
-   * Check if the latest revision log message of a node matches a given string.
-   *
-   * @param int $nid
-   *   The node id of the node to check.
-   * @param string $value
-   *   The value with which the log message will be compared.
-   * @param string $message
-   *   The message to display along with the assertion.
-   * @param string $group
-   *   The type of assertion - examples are "Browser", "PHP".
-   *
-   * @return
-   *   TRUE if the assertion succeeded, FALSE otherwise.
-   */
-  function assertRevisionLogMessage($nid, $value, $message = '', $group = 'Other') {
-    $log_message = db_select('node_revision', 'r')
-      ->fields('r', array('log'))
-      ->condition('nid', $nid)
-      ->orderBy('vid', 'DESC')
-      ->range(0, 1)
-      ->execute()
-      ->fetchColumn();
-    return $this->assertEqual($log_message, $value, $message, $group);
-  }
-
-  /**
-   * Check if the number of revisions for a node matches a given value.
-   *
-   * @param int $nid
-   *   The node id of the node to check.
-   * @param string $value
-   *   The value with which the number of revisions will be compared.
-   * @param string $message
-   *   The message to display along with the assertion.
-   * @param string $group
-   *   The type of assertion - examples are "Browser", "PHP".
-   *
-   * @return
-   *   TRUE if the assertion succeeded, FALSE otherwise.
-   */
-  function assertRevisionCount($nid, $value, $message = '', $group = 'Other') {
-    $count = db_select('node_revision', 'r')
-      ->fields('r', array('vid'))
-      ->condition('nid', $nid)
-      ->countQuery()
-      ->execute()
-      ->fetchColumn();
-    return $this->assertEqual($count, $value, $message, $group);
-  }
-
-  /**
-   * Test the default time functionality.
-   */
-  public function testDefaultTime() {
-    $this->drupalLogin($this->admin_user);
-
-    foreach (array('textfield', 'date_popup') as $field_type) {
-      // Check that the correct default time is added to the scheduled date.
-      // For testing we use an offset of 6 hours 30 minutes (23400 seconds).
-      $edit = array(
-        'scheduler_date_format' => 'Y-m-d H:i:s',
-        'scheduler_allow_date_only' => TRUE,
-        'scheduler_default_time' => '6:30',
-        'scheduler_field_type' => $field_type,
-      );
-      $this->drupalPost('admin/config/content/scheduler', $edit, t('Save configuration'));
-      $this->assertDefaultTime();
-
-      // Check that it is not possible to enter a date format without a time if
-      // the 'date only' option is not enabled.
-      $edit = array(
-        'scheduler_date_format' => 'Y-m-d',
-        'scheduler_allow_date_only' => FALSE,
-        'scheduler_field_type' => $field_type,
-      );
-      $this->drupalPost('admin/config/content/scheduler', $edit, t('Save configuration'));
-      $this->assertRaw(t('You must either include a time within the date format or enable the date-only option.'), format_string('It is not possible to enter a date format without a time if the "date only" option is not enabled and the field type is set to %field_type.', array('%field_type' => $field_type)));
-    }
-  }
-
-  /**
-   * Asserts that the default time works as expected.
-   */
-  protected function assertDefaultTime() {
-    // Define the form fields and date formats we will test according to whether
-    // date popups have been enabled or not.
-    $using_popup = variable_get('scheduler_field_type', 'date_popup') == 'date_popup';
-    $publish_date_field = $using_popup ? 'publish_on[date]' : 'publish_on';
-    $unpublish_date_field = $using_popup ? 'unpublish_on[date]' : 'unpublish_on';
-    $publish_time_field = $using_popup ? 'publish_on[time]' : 'publish_on';
-    $unpublish_time_field = $using_popup ? 'unpublish_on[time]' : 'unpublish_on';
-    $time_format = $using_popup ? 'H:i:s' : 'Y-m-d H:i:s';
-
-    // We cannot easily test the exact validation messages as they contain the
-    // REQUEST_TIME of the POST request, which can be one or more seconds in the
-    // past. Best we can do is check the fixed part of the message as it is when
-    // passed to t(). This will only work in English.
-    $publish_validation_message = $using_popup ? t('The value input for field %field is invalid:', array('%field' => 'Publish on')) : "The 'publish on' value does not match the expected format of";
-    $unpublish_validation_message = $using_popup ? t('The value input for field %field is invalid:', array('%field' => 'Unpublish on')) : "The 'unpublish on' value does not match the expected format of";
-
-    // First test with the "date only" functionality disabled.
-    $this->drupalPost('admin/config/content/scheduler', array('scheduler_allow_date_only' => FALSE), t('Save configuration'));
-
-    // Test if entering a time is required.
-    $edit = array(
-      'title' => $this->randomName(),
-      $publish_date_field => date('Y-m-d', strtotime('+1 day', REQUEST_TIME)),
-      $unpublish_date_field => date('Y-m-d', strtotime('+2 day', REQUEST_TIME)),
-    );
-    $this->drupalPost('node/add/page', $edit, t('Save'));
-
-    $this->assertRaw($publish_validation_message, 'By default it is required to enter a time when scheduling content for publication.');
-    $this->assertRaw($unpublish_validation_message, 'By default it is required to enter a time when scheduling content for unpublication.');
-
-    // Allow the user to enter only the date and repeat the test.
-    $this->drupalPost('admin/config/content/scheduler', array('scheduler_allow_date_only' => TRUE), t('Save configuration'));
 
-    $this->drupalPost('node/add/page', $edit, t('Save'));
-    $this->assertNoRaw("The 'publish on' value does not match the expected format of", 'If the default time option is enabled the user can skip the time when scheduling content for publication.');
-    $this->assertNoRaw("The 'unpublish on' value does not match the expected format of", 'If the default time option is enabled the user can skip the time when scheduling content for unpublication.');
-    $this->assertRaw(t('This post is unpublished and will be published @publish_time.', array('@publish_time' => date('Y-m-d H:i:s', strtotime('tomorrow', REQUEST_TIME) + 23400))), 'The user is informed that the content will be published on the requested date, on the default time.');
-
-    // Check that the default time has been added to the scheduler form fields.
-    $this->clickLink(t('Edit'));
-    $this->assertFieldByName($publish_time_field, date($time_format, strtotime('tomorrow', REQUEST_TIME) + 23400), 'The default time offset has been added to the date field when scheduling content for publication.');
-    $this->assertFieldByName($unpublish_time_field, date($time_format, strtotime('tomorrow +1 day', REQUEST_TIME) + 23400), 'The default time offset has been added to the date field when scheduling content for unpublication.');
-  }
 
   /**
    * Tests creating and editing nodes with required scheduling enabled.
@@ -581,6 +522,156 @@ class SchedulerTestCase extends DrupalWebTestCase {
     $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 the deletion of a scheduled node.
+   *
+   * This tests if it is possible to delete a node that does not have a
+   * publication date set, when scheduled publishing is required.
+   * @see https://drupal.org/node/1614880
+   */
+  public function testScheduledNodeDelete() {
+    // Log in.
+    $this->drupalLogin($this->admin_user);
+
+    // Create a published and an unpublished node, both without scheduling.
+    $unpublished_node = $this->drupalCreateNode(array('type' => 'page', 'status' => 0));
+    $published_node = $this->drupalCreateNode(array('type' => 'page', 'status' => 1));
+
+    // Make scheduled publishing and unpublishing required.
+    variable_set('scheduler_publish_required_page', TRUE);
+    variable_set('scheduler_unpublish_required_page', TRUE);
+
+    // Check that deleting the nodes does not throw form validation errors.
+    $this->drupalPost('node/' . $published_node->nid . '/edit', array(), t('Delete'));
+    $this->assertNoRaw(t('Error message'), 'No error messages are shown when trying to delete a published node with no scheduling information.');
+
+    $this->drupalPost('node/' . $unpublished_node->nid . '/edit', array(), t('Delete'));
+    $this->assertNoRaw(t('Error message'), 'No error messages are shown when trying to delete an unpublished node with no scheduling information.');
+  }
+}
+
+/**
+ * Tests the components of the scheduler interface which use the date module
+ */
+class SchedulerDateCombinedFunctionalTest extends SchedulerTestBase {
+  /**
+   * {@inheritdoc}
+   */
+  public static function getInfo() {
+    return array(
+      'name' => 'Scheduler date functionalities',
+      'description' => 'Scheduler functionalities which require the date module.',
+      'group' => 'Scheduler',
+    );
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  function setUp() {
+    parent::setUp('date', 'date_popup', 'scheduler');
+
+    // Create a 'Basic Page' content type.
+    $this->drupalCreateContentType(array('type' => 'page', 'name' => t('Basic page')));
+
+    // Create an administrator user.
+    $this->admin_user = $this->drupalCreateUser(array(
+      'access content',
+      'administer scheduler',
+      'create page content',
+      'edit own page content',
+      'delete own page content',
+      'view own unpublished content',
+      'administer nodes',
+      'schedule (un)publishing of nodes'
+    ));
+
+    // Add scheduler functionality to the page node type.
+    variable_set('scheduler_publish_enable_page', 1);
+    variable_set('scheduler_unpublish_enable_page', 1);
+    variable_set('scheduler_field_type', 'textfield');
+  }
+
+  /**
+   * Asserts that the default time works as expected.
+   */
+  protected function assertDefaultTime() {
+    // Define the form fields and date formats we will test according to whether
+    // date popups have been enabled or not.
+    $using_popup = variable_get('scheduler_field_type', 'date_popup') == 'date_popup';
+    $publish_date_field = $using_popup ? 'publish_on[date]' : 'publish_on';
+    $unpublish_date_field = $using_popup ? 'unpublish_on[date]' : 'unpublish_on';
+    $publish_time_field = $using_popup ? 'publish_on[time]' : 'publish_on';
+    $unpublish_time_field = $using_popup ? 'unpublish_on[time]' : 'unpublish_on';
+    $time_format = $using_popup ? 'H:i:s' : 'Y-m-d H:i:s';
+
+    // We cannot easily test the exact validation messages as they contain the
+    // REQUEST_TIME of the POST request, which can be one or more seconds in the
+    // past. Best we can do is check the fixed part of the message as it is when
+    // passed to t(). This will only work in English.
+    $publish_validation_message = $using_popup ? t('The value input for field %field is invalid:', array('%field' => 'Publish on')) : "The 'publish on' value does not match the expected format of";
+    $unpublish_validation_message = $using_popup ? t('The value input for field %field is invalid:', array('%field' => 'Unpublish on')) : "The 'unpublish on' value does not match the expected format of";
+
+    // First test with the "date only" functionality disabled.
+    $this->drupalPost('admin/config/content/scheduler', array('scheduler_allow_date_only' => FALSE), t('Save configuration'));
+
+    // Test if entering a time is required.
+    $edit = array(
+      'title' => $this->randomName(),
+      $publish_date_field => date('Y-m-d', strtotime('+1 day', REQUEST_TIME)),
+      $unpublish_date_field => date('Y-m-d', strtotime('+2 day', REQUEST_TIME)),
+    );
+    $this->drupalPost('node/add/page', $edit, t('Save'));
+
+    $this->assertRaw($publish_validation_message, 'By default it is required to enter a time when scheduling content for publication.');
+    $this->assertRaw($unpublish_validation_message, 'By default it is required to enter a time when scheduling content for unpublication.');
+
+    // Allow the user to enter only the date and repeat the test.
+    $this->drupalPost('admin/config/content/scheduler', array('scheduler_allow_date_only' => TRUE), t('Save configuration'));
+
+    $this->drupalPost('node/add/page', $edit, t('Save'));
+    $this->assertNoRaw("The 'publish on' value does not match the expected format of", 'If the default time option is enabled the user can skip the time when scheduling content for publication.');
+    $this->assertNoRaw("The 'unpublish on' value does not match the expected format of", 'If the default time option is enabled the user can skip the time when scheduling content for unpublication.');
+    $this->assertRaw(t('This post is unpublished and will be published @publish_time.', array('@publish_time' => date('Y-m-d H:i:s', strtotime('tomorrow', REQUEST_TIME) + 23400))), 'The user is informed that the content will be published on the requested date, on the default time.');
+
+    // Check that the default time has been added to the scheduler form fields.
+    $this->clickLink(t('Edit'));
+    $this->assertFieldByName($publish_time_field, date($time_format, strtotime('tomorrow', REQUEST_TIME) + 23400), 'The default time offset has been added to the date field when scheduling content for publication.');
+    $this->assertFieldByName($unpublish_time_field, date($time_format, strtotime('tomorrow +1 day', REQUEST_TIME) + 23400), 'The default time offset has been added to the date field when scheduling content for unpublication.');
+  }
+
+  /**
+   * Test the default time functionality.
+   */
+  public function testDefaultTime() {
+    $this->drupalLogin($this->admin_user);
+
+    foreach (array('textfield', 'date_popup') as $field_type) {
+      // Check that the correct default time is added to the scheduled date.
+      // For testing we use an offset of 6 hours 30 minutes (23400 seconds).
+      $edit = array(
+        'scheduler_date_format' => 'Y-m-d H:i:s',
+        'scheduler_allow_date_only' => TRUE,
+        'scheduler_default_time' => '6:30',
+        'scheduler_field_type' => $field_type,
+      );
+      $this->drupalPost('admin/config/content/scheduler', $edit, t('Save configuration'));
+      $this->assertDefaultTime();
+
+      // Check that it is not possible to enter a date format without a time if
+      // the 'date only' option is not enabled.
+      $edit = array(
+        'scheduler_date_format' => 'Y-m-d',
+        'scheduler_allow_date_only' => FALSE,
+        'scheduler_field_type' => $field_type,
+      );
+      $this->drupalPost('admin/config/content/scheduler', $edit, t('Save configuration'));
+      $this->assertRaw(t('You must either include a time within the date format or enable the date-only option.'), format_string('It is not possible to enter a date format without a time if the "date only" option is not enabled and the field type is set to %field_type.', array('%field_type' => $field_type)));
+    }
+  }
+
   /**
    * Tests configuration of different date formats with the Date Popup field.
    */
@@ -626,32 +717,4 @@ class SchedulerTestCase extends DrupalWebTestCase {
       $this->$assert('Error message', $message);
     }
   }
-
-  /**
-   * Tests the deletion of a scheduled node.
-   *
-   * This tests if it is possible to delete a node that does not have a
-   * publication date set, when scheduled publishing is required.
-   * @see https://drupal.org/node/1614880
-   */
-  public function testScheduledNodeDelete() {
-    // Log in.
-    $this->drupalLogin($this->admin_user);
-
-    // Create a published and an unpublished node, both without scheduling.
-    $unpublished_node = $this->drupalCreateNode(array('type' => 'page', 'status' => 0));
-    $published_node = $this->drupalCreateNode(array('type' => 'page', 'status' => 1));
-
-    // Make scheduled publishing and unpublishing required.
-    variable_set('scheduler_publish_required_page', TRUE);
-    variable_set('scheduler_unpublish_required_page', TRUE);
-
-    // Check that deleting the nodes does not throw form validation errors.
-    $this->drupalPost('node/' . $published_node->nid . '/edit', array(), t('Delete'));
-    $this->assertNoRaw(t('Error message'), 'No error messages are shown when trying to delete a published node with no scheduling information.');
-
-    $this->drupalPost('node/' . $unpublished_node->nid . '/edit', array(), t('Delete'));
-    $this->assertNoRaw(t('Error message'), 'No error messages are shown when trying to delete an unpublished node with no scheduling information.');
-  }
-
 }
