home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (rules_test.test)

This example Drupal source code file (rules_test.test) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

argument, error, evaluated, false, function, log, math, not, php, rules_test_show_log, successfully, true, variable, was

The rules_test.test Drupal example source code

<?php
// $Id: rules_test.test,v 1.1.2.8 2009/07/31 10:45:44 fago Exp $

/**
 * @file Rules Testing Module - File containing test cases.
 */

class RulesTestCase extends DrupalWebTestCase {
  public static function getInfo() {
    return array(
      'name' => t('Rules engine API tests'),
      'description' => t('Tests the rules engine API to work correctly.'),
      'group' => t('Rules engine tests'),
    );
  }

  function setUp() {
    parent::setUp();
    drupal_install_modules(array('rules', 'rules_test'));
    rules_test_keep_rules_log();
  }
  function tearDown() {
    parent::tearDown();
    rules_test_done();
  }

  //Test changing an argument when taken by reference and verify that the changes are kept
  function test_1() {
    $argument = array('property_xy' => TRUE);
    rules_invoke_rule_set('rules_test_1', $argument);
    $error = FALSE;
    $log = rules_test_show_log($error);
    $this->assertFalse($error, t('Rule was not evaluated successfully.') .' '. $log);
  }

  //Test changing an argument by action and verify that the changes are kept for later rules
  function test_2() {
    $argument = array('property_xy' => TRUE);
    rules_invoke_rule_set('rules_test_2', $argument);
    $error = FALSE;
    $log = rules_test_show_log($error);

    $this->assertFalse($error, t('Rule was not evaluated successfully.') .' '. $log);
  }

  //Test passing arguments by reference to a set
  function test_3() {
    $argument = array('property_xy' => TRUE);
    rules_invoke_rule_set('rules_test_2', array('rules_test' => &$argument));
    $error = FALSE;
    $log = rules_test_show_log($error);

    $this->assertTrue(isset($argument['altered']) && $argument['altered'], t('Argument has not been altered correctly.'));
    $this->assertFalse($error, t('Rule was not evaluated successfully.') .' '. $log);
  }

  //Tests argument mapping and argument loading by handler
  function test_4() {
    $argument = array('property_xy' => TRUE);
    rules_invoke_rule_set('rules_test_4', $argument);
    $error = FALSE;
    $log = rules_test_show_log($error);

    $this->assertFalse($error, t('Rule was not evaluated successfully.') .' '. $log);
    $this->assertTrue(strpos($log, 'Loaded variable "node"') !== FALSE, t('Variable was not loaded successfully.') .' '. $log);
  }

  //Tests adding a new variable
  function test_5() {
    rules_invoke_rule_set('rules_test_5');
    $error = FALSE;
    $log = rules_test_show_log($error);
    $this->assertFalse($error, t('Rule was not evaluated successfully.') .' '. $log);
    $this->assertTrue(strpos($log, 'Successfully added the new variable "test"') !== FALSE, t('Variable was not added successfully.') .' '. $log);
  }
}

/**
 * Argument handler for argument 2 of rule set 4
 */
function rules_test_4_load_data($arg1) {
  if (isset($arg1) && $arg1['property_xy']) {
    return  array('property_xy' => TRUE, 'altered' => TRUE);
  }
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal rules_test.test source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.