function RulesIntegrationTestCase::testNodeIntegration

Same name in other branches
  1. 7.x-2.x tests/rules.test \RulesIntegrationTestCase::testNodeIntegration()

Test integration for the node module.

File

d7-tests/rules_integration_test_case.test, line 448

Class

RulesIntegrationTestCase
Tests provided module integration.

Code

function testNodeIntegration() {
    $tests = array(
        array(
            'node_unpublish',
            'node_is_published',
            'node_publish',
            'status',
        ),
        array(
            'node_make_unsticky',
            'node_is_sticky',
            'node_make_sticky',
            'sticky',
        ),
        array(
            'node_unpromote',
            'node_is_promoted',
            'node_promote',
            'promote',
        ),
    );
    $node = $this->drupalCreateNode(array(
        'type' => 'page',
        'status' => 1,
        'sticky' => 1,
        'promote' => 1,
    ));
    foreach ($tests as $info) {
        list($action1, $condition, $action2, $property) = $info;
        rules_action($action1)->execute($node);
        $node = node_load($node->nid, NULL, TRUE);
        $this->assertFalse($node->{$property}, 'Action has permanently disabled node ' . $property);
        $return = rules_condition($condition)->execute($node);
        $this->assertFalse($return, 'Condition determines node ' . $property . ' is disabled.');
        rules_action($action2)->execute($node);
        $node = node_load($node->nid, NULL, TRUE);
        $this->assertTrue($node->{$property}, 'Action has permanently enabled node ' . $property);
        $return = rules_condition($condition)->execute($node);
        $this->assertTrue($return, 'Condition determines node ' . $property . ' is enabled.');
    }
    $return = rules_condition('node_is_of_type', array(
        'type' => array(
            'page',
            'article',
        ),
    ))->execute($node);
    $this->assertTrue($return, 'Condition determines node is of type page.');
    $return = rules_condition('node_is_of_type', array(
        'type' => array(
            'article',
        ),
    ))->execute($node);
    $this->assertFalse($return, 'Condition determines node is not of type article.');
    // Test auto saving of a new node after it has been inserted into the DB.
    $rule = rules_reaction_rule();
    $rand = $this->randomName();
    $rule->event('node_insert')
        ->action('data_set', array(
        'data:select' => 'node:title',
        'value' => $rand,
    ));
    $rule->save('test');
    $node = $this->drupalCreateNode();
    $node = node_load($node->nid);
    $this->assertEqual($node->title, $rand, 'Node title is correct.');
    RulesLog::logger()->checkLog();
}