You are here

private function WorkbenchSchedulerNodeScheduleTestCase::createScheduledNode in Workbench Scheduler 7.2

Same name and namespace in other branches
  1. 7 tests/workbench_scheduler.test \WorkbenchSchedulerNodeScheduleTestCase::createScheduledNode()

Create Node With Schedule.

Parameters

$schedule:

$ts (optional):

Return value

mixed

1 call to WorkbenchSchedulerNodeScheduleTestCase::createScheduledNode()
WorkbenchSchedulerNodeScheduleTestCase::testNodeSchedule in tests/workbench_scheduler.test
Test Node Schedule.

File

tests/workbench_scheduler.test, line 105
Tests for workbench_scheduler.module.

Class

WorkbenchSchedulerNodeScheduleTestCase
Assign node to schedule.

Code

private function createScheduledNode($schedule, $ts = null) {

  // Parse arguments.
  if (is_numeric($schedule) && !empty($ts)) {
    $schedule = array(
      $schedule => $ts,
    );
  }

  // Create node to edit.
  $langcode = LANGUAGE_NONE;
  $body_key = "body[{$langcode}][0][value]";
  $edit = array();
  $edit['title'] = $this
    ->randomName(8);
  $edit[$body_key] = $this
    ->randomName(16);

  // Adding schedules. Supports multple.
  foreach ($schedule as $sid => $time) {
    $edit['workbench_scheduler_sid[' . $sid . ']'] = TRUE;
    $edit['workbench_scheduler_date[' . $sid . '][date]'] = date('m/d/Y', $time);
    $edit['workbench_scheduler_date[' . $sid . '][time]'] = date('H:i', $time);
  }
  $this
    ->drupalPost('node/add/' . $this->content_type, $edit, t('Save'));

  // Checking the node.
  $node = $this
    ->drupalGetNodeByTitle($edit['title']);
  $this
    ->assertTrue($node, "Node {$node->title} created");
  $result = db_select('workbench_scheduler_nodes', 'wsn')
    ->fields('wsn')
    ->condition('wsn.nid', $node->nid, '=')
    ->condition('wsn.sid', $sid, '=')
    ->condition('wsn.date', $time, '=')
    ->execute()
    ->rowCount();
  $this
    ->assertTrue($result, $result . " schedule(s) assigned to node {$node->title}");
  return $node;
}