You are here

public function SchedulerTestBase::helpTestScheduler in Scheduler 7

Helper function for testScheduler(). Schedules content and asserts status.

Parameters

array $edit: Node data, as if it was sent from the edit form.

bool $scheduler_cron_only: TRUE to only run Scheduler cron, FALSE to run default full Drupal cron.

1 call to SchedulerTestBase::helpTestScheduler()
SchedulerFunctionalTest::testBasicScheduling in tests/scheduler.test
Tests basic scheduling of content.

File

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

Class

SchedulerTestBase
Provides common helper methods for Scheduler module tests.

Code

public function helpTestScheduler(array $edit, $scheduler_cron_only = FALSE) {

  // Add a page.
  $langcode = LANGUAGE_NONE;
  $title = $this
    ->randomName();
  $edit["title"] = $title;
  $body = $this
    ->randomName();
  $edit["body[{$langcode}][0][value]"] = $body;
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalPost('node/add/page', $edit, t('Save'));
  $node = $this
    ->drupalGetNodeByTitle($title);

  // Show the specific page for an anonymous visitor, then assert that the
  // node is correctly published or unpublished.
  $this
    ->drupalLogout();
  $this
    ->drupalGet("node/{$node->nid}");
  if (isset($edit['publish_on'])) {
    $key = 'publish_on';
    $this
      ->assertResponse(403, 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 far enough in the past because
  // scheduler_cron uses REQUEST_TIME and our timestamp has to be before that.
  db_update('scheduler')
    ->fields(array(
    $key => time() - 3600,
  ))
    ->execute();
  if ($scheduler_cron_only) {
    scheduler_cron();
  }
  else {
    $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 specific page for an anonymous visitor, then assert that the
  // node is correctly published or unpublished.
  $this
    ->drupalGet("node/{$node->nid}");
  if (isset($edit['publish_on'])) {
    $this
      ->assertText($body, t('Node is published'));
  }
  else {
    $this
      ->assertResponse(403, t('Node is unpublished'));
  }
}