You are here

public function SchedulerRulesTest::testRulesConditionsNodeIsScheduled in Scheduler 7

Tests the two conditions for whether a node is scheduled.

File

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

Class

SchedulerRulesTest
Tests Schedulers interaction with the Rules module.

Code

public function testRulesConditionsNodeIsScheduled() {
  $this
    ->drupalLogin($this->adminUser);
  $node = $this->node;

  // Create a reaction rule to display a message when a node is updated and
  // is not scheduled for publishing.
  $message5 = 'RULE 5. This content is not scheduled for publishing.';
  $rule = rules_reaction_rule();
  $rule
    ->event('node_update')
    ->condition(rules_condition('scheduler_condition_node_is_scheduled_for_publishing', array(
    'data:select' => 'node:node',
  ))
    ->negate())
    ->action('drupal_message', array(
    'message' => $message5,
  ));
  $rule
    ->access();
  $rule
    ->integrityCheck();
  $rule
    ->save('rule_id_5', $message5);

  // Create a reaction rule to display a message when a node is updated and
  // is not scheduled for unpublishing.
  $message6 = 'RULE 6. This content is not scheduled for unpublishing.';
  $rule = rules_reaction_rule();
  $rule
    ->event('node_update')
    ->condition(rules_condition('scheduler_condition_node_is_scheduled_for_unpublishing', array(
    'data:select' => 'node:node',
  ))
    ->negate())
    ->action('drupal_message', array(
    'message' => $message6,
  ));
  $rule
    ->access();
  $rule
    ->integrityCheck();
  $rule
    ->save('rule_id_6', $message6);

  // Create a reaction rule to display a message when a node is updated and
  // is scheduled for publishing.
  $message7 = 'RULE 7. This content is scheduled for publishing.';
  $rule = rules_reaction_rule();
  $rule
    ->event('node_update')
    ->condition(rules_condition('scheduler_condition_node_is_scheduled_for_publishing', array(
    'data:select' => 'node:node',
  )))
    ->action('drupal_message', array(
    'message' => $message7,
  ));
  $rule
    ->access();
  $rule
    ->integrityCheck();
  $rule
    ->save('rule_id_7', $message7);

  // Create a reaction rule to display a message when a node is updated and
  // is scheduled for unpublishing.
  $message8 = 'RULE 8. This content is scheduled for unpublishing.';
  $rule = rules_reaction_rule();
  $rule
    ->event('node_update')
    ->condition(rules_condition('scheduler_condition_node_is_scheduled_for_unpublishing', array(
    'data:select' => 'node:node',
  )))
    ->action('drupal_message', array(
    'message' => $message8,
  ));
  $rule
    ->access();
  $rule
    ->integrityCheck();
  $rule
    ->save('rule_id_8', $message8);

  // Edit the node but do not enter any scheduling dates.
  $this
    ->drupalPost('node/' . $node->nid . '/edit', array(), t('Save'));

  // Check that the conditions have been met or not as expceted.
  $this
    ->assertText($message5, '"' . $message5 . '" is shown');
  $this
    ->assertText($message6, '"' . $message6 . '" is shown');
  $this
    ->assertNoText($message7, '"' . $message7 . '" is not shown');
  $this
    ->assertNoText($message8, '"' . $message8 . '" is not shown');

  // Edit the node and set a publish_on date.
  $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'));

  // Check that the conditions have been met (or not) as expected.
  $this
    ->assertNoText($message5, '"' . $message5 . '" is not shown');
  $this
    ->assertText($message6, '"' . $message6 . '" is shown');
  $this
    ->assertText($message7, '"' . $message7 . '" is shown');
  $this
    ->assertNoText($message8, '"' . $message8 . '" is not shown');

  // Edit the node and set an unpublish_on date.
  $edit = array(
    'unpublish_on' => date('Y-m-d H:i:s', strtotime('+2 day', REQUEST_TIME)),
  );
  $this
    ->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));

  // Check that the conditions have been met (or not) as expected.
  $this
    ->assertNoText($message5, '"' . $message5 . '" is not shown');
  $this
    ->assertNoText($message6, '"' . $message6 . '" is not shown');
  $this
    ->assertText($message7, '"' . $message7 . '" is shown');
  $this
    ->assertText($message8, '"' . $message8 . '" is shown');
}