public function SchedulerRulesTest::testRulesConditionsNodetypeEnabled in Scheduler 7
Tests the two conditions for a content type being enabled for scheduling.
File
- tests/
scheduler.test, line 1391 - Scheduler module test case file.
Class
- SchedulerRulesTest
- Tests Schedulers interaction with the Rules module.
Code
public function testRulesConditionsNodetypeEnabled() {
$this
->drupalLogin($this->adminUser);
$node = $this->node;
// Create a reaction rule to display a message when viewing a node of a type
// that is enabled for scheduled publishing.
// "viewing content" actually means "viewing PUBLISHED content".
$message1 = 'RULE 1. This node type is enabled for scheduled publishing.';
$rule = rules_reaction_rule();
$rule
->event('node_view')
->condition(rules_condition('scheduler_condition_publishing_is_enabled', array(
'data:select' => 'node:node',
)))
->action('drupal_message', array(
'message' => $message1,
));
// Check access and integrity, then save the rule.
$rule
->access();
$rule
->integrityCheck();
$rule
->save('rule_id_1', $message1);
// Create a reaction rule to display a message when viewing a node of a type
// that is enabled for scheduled unpublishing.
$message2 = 'RULE 2. This node type is enabled for scheduled unpublishing.';
$rule = rules_reaction_rule();
$rule
->event('node_view')
->condition(rules_condition('scheduler_condition_unpublishing_is_enabled', array(
'data:select' => 'node:node',
)))
->action('drupal_message', array(
'message' => $message2,
));
$rule
->access();
$rule
->integrityCheck();
$rule
->save('rule_id_2', $message2);
// Create a reaction rule to display a message when viewing a node of a type
// that is NOT enabled for scheduled publishing.
$message3 = 'RULE 3. This node type is not enabled for scheduled publishing.';
$rule = rules_reaction_rule();
$rule
->event('node_view')
->condition(rules_condition('scheduler_condition_publishing_is_enabled', array(
'data:select' => 'node:node',
))
->negate())
->action('drupal_message', array(
'message' => $message3,
));
$rule
->access();
$rule
->integrityCheck();
$rule
->save('rule_id_3', $message3);
// Create a reaction rule to display a message when viewing a node of a type
// that is not enabled for scheduled unpublishing.
$message4 = 'RULE 4. This node type is not enabled for scheduled unpublishing.';
$rule = rules_reaction_rule();
$rule
->event('node_view')
->condition(rules_condition('scheduler_condition_unpublishing_is_enabled', array(
'data:select' => 'node:node',
))
->negate())
->action('drupal_message', array(
'message' => $message4,
));
$rule
->access();
$rule
->integrityCheck();
$rule
->save('rule_id_4', $message4);
// View the node and check the default position - that the node type is
// enabled for both publishing and unpublishing.
$this
->drupalGet('node/' . $node->nid);
$this
->assertText($message1, '"' . $message1 . '" is shown');
$this
->assertText($message2, '"' . $message2 . '" is shown');
$this
->assertNoText($message3, '"' . $message3 . '" is not shown');
$this
->assertNoText($message4, '"' . $message4 . '" is not shown');
// Turn off scheduled publishing for the node type and check the rules.
variable_set('scheduler_publish_enable_page', FALSE);
$this
->drupalGet('node/' . $node->nid);
$this
->assertNoText($message1, '"' . $message1 . '" is not shown');
$this
->assertText($message2, '"' . $message2 . '" is shown');
$this
->assertText($message3, '"' . $message3 . '" is shown');
$this
->assertNoText($message4, '"' . $message4 . '" is not shown');
// Turn off scheduled unpublishing for the node type and the check again.
variable_set('scheduler_unpublish_enable_page', FALSE);
$this
->drupalGet('node/' . $node->nid);
$this
->assertNoText($message1, '"' . $message1 . '" is not shown');
$this
->assertNoText($message2, '"' . $message2 . '" is not shown');
$this
->assertText($message3, '"' . $message3 . '" is shown');
$this
->assertText($message4, '"' . $message4 . '" is shown');
}