You are here

class RulesIntegrationTestCase in Rules 7.2

Same name and namespace in other branches
  1. 8.3 d7-tests/rules_integration_test_case.test \RulesIntegrationTestCase

Tests provided module integration.

Hierarchy

Expanded class hierarchy of RulesIntegrationTestCase

File

tests/rules.test, line 1373
Rules tests.

View source
class RulesIntegrationTestCase extends DrupalWebTestCase {

  /**
   * Declares test metadata.
   */
  public static function getInfo() {
    return array(
      'name' => 'Rules Core Integration',
      'description' => 'Tests provided integration for drupal core.',
      'group' => 'Rules',
    );
  }

  /**
   * Overrides DrupalWebTestCase::setUp().
   */
  protected function setUp() {
    parent::setUp('rules', 'rules_test', 'php', 'path');
    RulesLog::logger()
      ->clear();
    variable_set('rules_debug_log', TRUE);
  }

  /**
   * Just makes sure the access callback run without errors.
   */
  public function testAccessCallbacks() {
    $cache = rules_get_cache();
    foreach (array(
      'action',
      'condition',
      'event',
    ) as $type) {
      foreach (rules_fetch_data($type . '_info') as $name => $info) {
        if (isset($info['access callback'])) {
          $info['access callback']($type, $name);
        }
      }
    }
  }

  /**
   * Tests data integration.
   */
  public function testDataIntegration() {

    // Test data_create action.
    $action = rules_action('data_create', array(
      'type' => 'log_entry',
      'param_type' => 'rules_test',
      'param_message' => 'Rules test log message',
      'param_severity' => WATCHDOG_WARNING,
      'param_request_uri' => 'http://example.com',
      'param_link' => '',
    ));
    $action
      ->access();
    $action
      ->execute();
    $text = RulesLog::logger()
      ->render();
    $pos = strpos($text, RulesTestCase::t('Added the provided variable %data_created of type %log_entry', array(
      'data_created',
      'log_entry',
    )));
    $this
      ->assertTrue($pos !== FALSE, 'Data of type log entry has been created.');

    // Test variable_add action.
    $action = rules_action('variable_add', array(
      'type' => 'text_formatted',
      'value' => array(
        'value' => 'test text',
        'format' => 1,
      ),
    ));
    $action
      ->access();
    $action
      ->execute();
    $text = RulesLog::logger()
      ->render();
    $pos = strpos($text, RulesTestCase::t('Added the provided variable %variable_added of type %text_formatted', array(
      'variable_added',
      'text_formatted',
    )));
    $this
      ->assertTrue($pos !== FALSE, 'Data of type text formatted has been created.');

    // Test using the list actions.
    $rule = rule(array(
      'list' => array(
        'type' => 'list<text>',
        'label' => 'A list of text',
      ),
    ));
    $rule
      ->action('list_add', array(
      'list:select' => 'list',
      'item' => 'bar2',
    ));
    $rule
      ->action('list_add', array(
      'list:select' => 'list',
      'item' => 'bar',
      'pos' => 'start',
    ));
    $rule
      ->action('list_add', array(
      'list:select' => 'list',
      'item' => 'bar',
      'unique' => TRUE,
    ));
    $rule
      ->action('list_remove', array(
      'list:select' => 'list',
      'item' => 'bar2',
    ));
    $list = entity_metadata_wrapper('list', array(
      'foo',
      'foo2',
    ));
    $rule
      ->execute($list);
    RulesLog::logger()
      ->checkLog();
    $this
      ->assertEqual($list
      ->value(), array(
      'bar',
      'foo',
      'foo2',
    ), 'List items removed and added.');
    $this
      ->assertFalse(rules_condition('list_contains')
      ->execute($list, 'foo-bar'), 'Condition "List item contains" evaluates to FALSE');
    $this
      ->assertTrue(rules_condition('list_contains')
      ->execute($list, 'foo'), 'Condition "List item contains" evaluates to TRUE');

    // debug(RulesLog::logger()->render());
    // Test data_is condition with IN operation.
    $rule = rule(array(
      'node' => array(
        'type' => 'node',
      ),
    ));
    $rule
      ->condition('data_is', array(
      'data:select' => 'node:title',
      'op' => 'IN',
      'value' => array(
        'foo',
        'bar',
      ),
    ));
    $rule
      ->action('data_set', array(
      'data:select' => 'node:title',
      'value' => 'bar',
    ));
    $rule
      ->integrityCheck();
    $node = $this
      ->drupalCreateNode(array(
      'title' => 'foo',
    ));
    $rule
      ->execute($node);
    $this
      ->assertEqual($node->title, 'bar', "Data comparison using IN operation evaluates to TRUE.");

    // Test Condition: Data is empty.
    $rule = rule(array(
      'node' => array(
        'type' => 'node',
      ),
    ));
    $rule
      ->condition('data_is_empty', array(
      'data:select' => 'node:title',
    ));
    $rule
      ->action('data_set', array(
      'data:select' => 'node:title',
      'value' => 'bar',
    ));
    $rule
      ->integrityCheck();

    // Data is empty condition evaluates to TRUE
    // for node with empty title, action sets title to 'bar'.
    $node = $this
      ->drupalCreateNode(array(
      'title' => '',
      'type' => 'article',
    ));
    $rule
      ->execute($node);
    $this
      ->assertEqual($node->title, 'bar', "Data is empty condition evaluates to TRUE for node with empty title, action sets title to 'bar'.");

    // Data is empty condition evaluates to FALSE
    // for node with title 'foo', action is not executed.
    $node = $this
      ->drupalCreateNode(array(
      'title' => 'foo',
      'type' => 'article',
    ));
    $rule
      ->execute($node);
    $this
      ->assertEqual($node->title, 'foo', "Data is empty condition evaluates to FALSE for node with title 'foo', action is not executed.");

    // Data is empty condition evaluates to TRUE for the parent of a
    // not existing term in the tags field of the node.
    $rule = rule(array(
      'node' => array(
        'type' => 'node',
      ),
    ));
    $rule
      ->condition('node_is_of_type', array(
      'type' => array(
        'article',
      ),
    ));
    $rule
      ->condition('data_is_empty', array(
      'data:select' => 'node:field-tags:0:parent',
    ));
    $rule
      ->action('data_set', array(
      'data:select' => 'node:title',
      'value' => 'bar',
    ));
    $rule
      ->integrityCheck();
    $node = $this
      ->drupalCreateNode(array(
      'title' => 'foo',
      'type' => 'article',
    ));
    $rule
      ->execute($node);
    $this
      ->assertEqual($node->title, 'bar', "Data is empty condition evaluates to TRUE for not existing data structures");

    // Test Action: Calculate a value.
    $rule = rule(array(
      'node' => array(
        'type' => 'node',
      ),
    ));
    $rule
      ->action('data_calc', array(
      'input_1:select' => 'node:nid',
      'op' => '*',
      'input_2' => 2,
    ));
    $rule
      ->action('data_set', array(
      'data:select' => 'node:title',
      'value:select' => 'result',
    ));
    $rule
      ->integrityCheck();
    $rule
      ->execute($node);
    $this
      ->assertEqual($node->title, $node->nid * 2, "Value has been calculated.");

    // Test moving a date.
    $action_set = rules_action_set(array(
      'date' => array(
        'type' => 'date',
      ),
    ), array(
      'date',
    ));
    $action_set
      ->action('data_calc', array(
      'input_1:select' => 'date',
      'op' => '+',
      'input_2' => 3600,
    ))
      ->action('data_set', array(
      'data:select' => 'date',
      'value:select' => 'result',
    ));
    $action_set
      ->integrityCheck();
    list($result) = $action_set
      ->execute(REQUEST_TIME);
    $this
      ->assertEqual($result, REQUEST_TIME + 3600, 'Used data calculation action to move a date by an hour.');

    // Test data type conversion action.
    $set = rules_action_set(array(
      'result' => array(
        'type' => 'text',
        'parameter' => FALSE,
      ),
    ), array(
      'result',
    ));
    $set
      ->action('data_convert', array(
      'type' => 'text',
      'value:select' => 'site:login-url',
    ));
    $set
      ->action('data_set', array(
      'data:select' => 'result',
      'value:select' => 'conversion_result',
    ));
    list($result) = $set
      ->execute();
    $set
      ->integrityCheck();
    $this
      ->assertEqual($result, url('user', array(
      'absolute' => TRUE,
    )), 'Converted URI to text.');
    $set = rules_action_set(array(
      'result' => array(
        'type' => 'integer',
        'parameter' => FALSE,
      ),
      'source' => array(
        'type' => 'text',
      ),
    ), array(
      'result',
    ));
    $set
      ->action('data_convert', array(
      'type' => 'integer',
      'value:select' => 'source',
    ));
    $set
      ->action('data_set', array(
      'data:select' => 'result',
      'value:select' => 'conversion_result',
    ));
    list($result) = $set
      ->execute('9.4');
    $this
      ->assertEqual($result, 9, 'Converted decimal to integer using rounding.');
    $set = rules_action_set(array(
      'result' => array(
        'type' => 'integer',
        'parameter' => FALSE,
      ),
      'source' => array(
        'type' => 'text',
      ),
    ), array(
      'result',
    ));
    $set
      ->action('data_convert', array(
      'type' => 'integer',
      'value:select' => 'source',
      'rounding_behavior' => 'down',
    ));
    $set
      ->action('data_set', array(
      'data:select' => 'result',
      'value:select' => 'conversion_result',
    ));
    list($result) = $set
      ->execute('9.6');
    $this
      ->assertEqual($result, 9, 'Converted decimal to integer using rounding behavior down.');
    $set = rules_action_set(array(
      'result' => array(
        'type' => 'integer',
        'parameter' => FALSE,
      ),
      'source' => array(
        'type' => 'text',
      ),
    ), array(
      'result',
    ));
    $set
      ->action('data_convert', array(
      'type' => 'integer',
      'value:select' => 'source',
      'rounding_behavior' => 'up',
    ));
    $set
      ->action('data_set', array(
      'data:select' => 'result',
      'value:select' => 'conversion_result',
    ));
    list($result) = $set
      ->execute('9.4');
    $this
      ->assertEqual($result, 10, 'Converted decimal to integer using rounding behavior up.');

    // Test text matching condition.
    $result = rules_condition('text_matches')
      ->execute('my-text', 'text', 'contains');
    $result2 = rules_condition('text_matches')
      ->execute('my-text', 'tex2t', 'contains');
    $this
      ->assertTrue($result && !$result2, 'Text matching condition using operation contain evaluated.');
    $result = rules_condition('text_matches')
      ->execute('my-text', 'my', 'starts');
    $result2 = rules_condition('text_matches')
      ->execute('my-text', 'text', 'starts');
    $this
      ->assertTrue($result && !$result2, 'Text matching condition using operation starts evaluated.');
    $result = rules_condition('text_matches')
      ->execute('my-text', 'text', 'ends');
    $result2 = rules_condition('text_matches')
      ->execute('my-text', 'my', 'ends');
    $this
      ->assertTrue($result && !$result2, 'Text matching condition using operation ends evaluated.');
    $result = rules_condition('text_matches')
      ->execute('my-text', 'me?y-texx?t', 'regex');
    $result2 = rules_condition('text_matches')
      ->execute('my-text', 'me+y-texx?t', 'regex');
    $this
      ->assertTrue($result && !$result2, 'Text matching condition using operation regex evaluated.');
  }

  /**
   * Tests entity related integration.
   */
  public function testEntityIntegration() {
    global $user;
    $page = $this
      ->drupalCreateNode(array(
      'type' => 'page',
    ));
    $article = $this
      ->drupalCreateNode(array(
      'type' => 'article',
    ));
    $result = rules_condition('entity_field_access')
      ->execute(entity_metadata_wrapper('node', $article), 'field_tags');
    $this
      ->assertTrue($result);

    // Test entity_is_of_bundle condition.
    $result = rules_condition('entity_is_of_bundle', array(
      'type' => 'node',
      'bundle' => array(
        'article',
      ),
    ))
      ->execute(entity_metadata_wrapper('node', $page));
    $this
      ->assertFalse($result, 'Entity is of bundle condition has not been met.');
    $result = rules_condition('entity_is_of_bundle', array(
      'type' => 'node',
      'bundle' => array(
        'article',
      ),
    ))
      ->execute(entity_metadata_wrapper('node', $article));
    $this
      ->assertTrue($result, 'Entity is of bundle condition has been met.');

    // Also test a full rule so the integrity check must work.
    $term_wrapped = entity_property_values_create_entity('taxonomy_term', array(
      'name' => $this
        ->randomName(),
      'vocabulary' => 1,
    ))
      ->save();
    $rule = rule(array(
      'node' => array(
        'type' => 'node',
      ),
    ));
    $rule
      ->condition('entity_is_of_bundle', array(
      'entity:select' => 'node',
      'bundle' => array(
        'article',
      ),
    ));
    $rule
      ->action('data_set', array(
      'data:select' => 'node:field_tags',
      'value' => array(
        $term_wrapped
          ->getIdentifier(),
      ),
    ));
    $rule
      ->integrityCheck();
    $rule
      ->execute($article);
    $this
      ->assertEqual($term_wrapped
      ->getIdentifier(), $article->field_tags[LANGUAGE_NONE][0]['tid'], 'Entity is of bundle condition has been met.');

    // Test again using an entity variable.
    $article = $this
      ->drupalCreateNode(array(
      'type' => 'article',
    ));
    $rule = rule(array(
      'entity' => array(
        'type' => 'entity',
      ),
    ));
    $rule
      ->condition('entity_is_of_bundle', array(
      'entity:select' => 'entity',
      'type' => 'node',
      'bundle' => array(
        'article',
      ),
    ));
    $rule
      ->action('data_set', array(
      'data:select' => 'entity:field_tags',
      'value' => array(
        $term_wrapped
          ->getIdentifier(),
      ),
    ));
    $rule
      ->integrityCheck();
    $rule
      ->execute(entity_metadata_wrapper('node', $article));
    $this
      ->assertEqual($term_wrapped
      ->getIdentifier(), $article->field_tags[LANGUAGE_NONE][0]['tid'], 'Entity is of bundle condition has been met.');

    // Test CRUD actions.
    $action = rules_action('entity_create', array(
      'type' => 'node',
      'param_type' => 'page',
      'param_title' => 'foo',
      'param_author' => $GLOBALS['user'],
    ));
    $action
      ->access();
    $action
      ->execute();
    $text = RulesLog::logger()
      ->render();
    $pos = strpos($text, RulesTestCase::t('Added the provided variable %entity_created of type %node', array(
      'entity_created',
      'node',
    )));
    $pos = $pos !== FALSE ? strpos($text, RulesTestCase::t('Saved %entity_created of type %node.', array(
      'entity_created',
      'node',
    )), $pos) : FALSE;
    $this
      ->assertTrue($pos !== FALSE, 'Data has been created and saved.');
    $node = $this
      ->drupalCreateNode(array(
      'type' => 'page',
      'sticky' => 0,
      'status' => 0,
    ));
    $rule = rule();
    $rule
      ->action('entity_fetch', array(
      'type' => 'node',
      'id' => $node->nid,
      'entity_fetched:var' => 'node',
    ));
    $rule
      ->action('entity_save', array(
      'data:select' => 'node',
      'immediate' => TRUE,
    ));
    $rule
      ->action('entity_delete', array(
      'data:select' => 'node',
    ));
    $rule
      ->access();
    $rule
      ->integrityCheck()
      ->execute();
    $text = RulesLog::logger()
      ->render();
    $pos = strpos($text, RulesTestCase::t('Evaluating the action %entity_fetch.', array(
      'entity_fetch' => 'Fetch entity by id',
    )));
    $pos = $pos !== FALSE ? strpos($text, RulesTestCase::t('Added the provided variable %node of type %node', array(
      'node',
    )), $pos) : FALSE;
    $pos = $pos !== FALSE ? strpos($text, RulesTestCase::t('Saved %node of type %node.', array(
      'node',
    )), $pos) : FALSE;
    $pos = $pos !== FALSE ? strpos($text, RulesTestCase::t('Evaluating the action %entity_delete.', array(
      'entity_delete' => 'Delete entity',
    )), $pos) : FALSE;
    $this
      ->assertTrue($pos !== FALSE, 'Data has been fetched, saved and deleted.');

    // debug(RulesLog::logger()->render());
    $node = entity_property_values_create_entity('node', array(
      'type' => 'article',
      'author' => $user,
      'title' => 'foo',
    ))
      ->value();
    $term_wrapped = entity_property_values_create_entity('taxonomy_term', array(
      'name' => $this
        ->randomName(),
      'vocabulary' => 1,
    ))
      ->save();

    // Test asserting the field and using it afterwards.
    $rule = rule(array(
      'node' => array(
        'type' => 'node',
      ),
    ));
    $rule
      ->condition('entity_has_field', array(
      'entity:select' => 'node',
      'field' => 'field_tags',
    ));
    $rule
      ->condition('entity_is_new', array(
      'entity:select' => 'node',
    ));
    $rule
      ->action('list_add', array(
      'list:select' => 'node:field-tags',
      'item' => $term_wrapped,
    ));
    $rule
      ->integrityCheck();
    $rule
      ->execute($node);
    $tid = $term_wrapped
      ->getIdentifier();
    $this
      ->assertEqual(array_values($node->field_tags[LANGUAGE_NONE]), array(
      0 => array(
        'tid' => $tid,
      ),
    ), 'Entity has field conditions evaluted.');

    // Test loading a non-node entity.
    $action = rules_action('entity_fetch', array(
      'type' => 'taxonomy_term',
      'id' => $tid,
    ));
    list($term) = $action
      ->execute();
    $this
      ->assertEqual($term->tid, $tid, 'Fetched a taxonomy term using "entity_fetch".');

    // Test the entity is of type condition.
    $rule = rule(array(
      'entity' => array(
        'type' => 'entity',
        'label' => 'entity',
      ),
    ));
    $rule
      ->condition('entity_is_of_type', array(
      'type' => 'node',
    ));
    $rule
      ->action('data_set', array(
      'data:select' => 'entity:title',
      'value' => 'bar',
    ));
    $rule
      ->integrityCheck();
    $rule
      ->execute(entity_metadata_wrapper('node', $node));
    $this
      ->assertEqual(entity_metadata_wrapper('node', $node->nid)->title
      ->value(), 'bar', 'Entity is of type condition correctly asserts the entity type.');

    // Test the entity_query action.
    $node = $this
      ->drupalCreateNode(array(
      'type' => 'page',
      'title' => 'foo2',
    ));
    $rule = rule();
    $rule
      ->action('entity_query', array(
      'type' => 'node',
      'property' => 'title',
      'value' => 'foo2',
    ))
      ->action('data_set', array(
      'data:select' => 'entity_fetched:0:title',
      'value' => 'bar',
    ));
    $rule
      ->access();
    $rule
      ->integrityCheck();
    $rule
      ->execute();
    $node = node_load($node->nid);
    $this
      ->assertEqual('bar', $node->title, 'Fetched a node by title and modified it.');
    RulesLog::logger()
      ->checkLog();
  }

  /**
   * Tests integration for the taxonomy module.
   */
  public function testTaxonomyIntegration() {
    $term = entity_property_values_create_entity('taxonomy_term', array(
      'name' => $this
        ->randomName(),
      'vocabulary' => 1,
    ))
      ->value();
    $term2 = clone $term;
    taxonomy_term_save($term);
    taxonomy_term_save($term2);
    $tags[LANGUAGE_NONE][0]['tid'] = $term->tid;
    $node = $this
      ->drupalCreateNode(array(
      'title' => 'foo',
      'type' => 'article',
      'field_tags' => $tags,
    ));

    // Test assigning and remove a term from an article.
    $rule = rule(array(
      'node' => array(
        'type' => 'node',
        'bundle' => 'article',
      ),
    ));
    $term_wrapped = rules_wrap_data($term->tid, array(
      'type' => 'taxonomy_term',
    ));
    $term_wrapped2 = rules_wrap_data($term2->tid, array(
      'type' => 'taxonomy_term',
    ));
    $rule
      ->action('list_add', array(
      'list:select' => 'node:field-tags',
      'item' => $term_wrapped2,
    ));
    $rule
      ->action('list_remove', array(
      'list:select' => 'node:field-tags',
      'item' => $term_wrapped,
    ));
    $rule
      ->execute($node);
    RulesLog::logger()
      ->checkLog();
    $this
      ->assertEqual(array_values($node->field_tags[LANGUAGE_NONE]), array(
      0 => array(
        'tid' => $term2->tid,
      ),
    ), 'Term removed and added from a node.');

    // Test using the taxonomy term reference field on a term object.
    $field_name = drupal_strtolower($this
      ->randomName() . '_field_name');
    $field = field_create_field(array(
      'field_name' => $field_name,
      'type' => 'taxonomy_term_reference',
      // Set cardinality to unlimited for tagging.
      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
      'settings' => array(
        'allowed_values' => array(
          array(
            'vocabulary' => 'tags',
            'parent' => 0,
          ),
        ),
      ),
    ));
    $instance = array(
      'field_name' => $field_name,
      'entity_type' => 'taxonomy_term',
      'bundle' => 'tags',
      // Machine name of vocabulary.
      'label' => $this
        ->randomName() . '_label',
      'description' => $this
        ->randomName() . '_description',
      'weight' => mt_rand(0, 127),
      'widget' => array(
        'type' => 'taxonomy_autocomplete',
        'weight' => -4,
      ),
      'display' => array(
        'default' => array(
          'type' => 'taxonomy_term_reference_link',
          'weight' => 10,
        ),
      ),
    );
    field_create_instance($instance);
    $term1 = entity_property_values_create_entity('taxonomy_term', array(
      'name' => $this
        ->randomName(),
      'vocabulary' => 1,
    ))
      ->save();
    $term2 = entity_property_values_create_entity('taxonomy_term', array(
      'name' => $this
        ->randomName(),
      'vocabulary' => 1,
    ))
      ->save();

    // Test asserting the term reference field and using it afterwards.
    $rule = rule(array(
      'taxonomy_term' => array(
        'type' => 'taxonomy_term',
      ),
    ));
    $rule
      ->condition('entity_has_field', array(
      'entity:select' => 'taxonomy-term',
      'field' => $field_name,
    ));

    // Add $term2 to $term1 using the term reference field.
    $selector = str_replace('_', '-', 'taxonomy_term:' . $field_name);
    $rule
      ->action('list_add', array(
      'list:select' => $selector,
      'item' => $term2,
    ));
    $rule
      ->integrityCheck();
    $rule
      ->execute($term1);
    RulesLog::logger()
      ->checkLog();
    $this
      ->assertEqual($term1->{$field_name}[0]
      ->getIdentifier(), $term2
      ->getIdentifier(), 'Rule appended a term to the term reference field on a term.');

    // Test an action set for merging term parents, which is provided as default
    // config.
    $term = entity_property_values_create_entity('taxonomy_term', array(
      'name' => $this
        ->randomName(),
      'vocabulary' => 1,
      'parent' => array(
        $term1
          ->value(),
      ),
    ))
      ->save();
    $action = rules_action('component_rules_retrieve_term_parents');
    list($parents) = $action
      ->execute(array(
      $term
        ->getIdentifier(),
    ));
    $this
      ->assertTrue($parents[0]->tid == $term1
      ->getIdentifier(), 'Invoked component to retrieve term parents.');
    RulesLog::logger()
      ->checkLog();
  }

  /**
   * Tests integration for the node module.
   */
  public 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();
  }

  /**
   * Tests integration for the user module.
   */
  public function testUserIntegration() {
    $rid = $this
      ->drupalCreateRole(array(
      'administer nodes',
    ), 'foo');
    $user = $this
      ->drupalCreateUser();

    // Test assigning a role with the list_add action.
    $rule = rule(array(
      'user' => array(
        'type' => 'user',
      ),
    ));
    $rule
      ->action('list_add', array(
      'list:select' => 'user:roles',
      'item' => $rid,
    ));
    $rule
      ->execute($user);
    $this
      ->assertTrue(isset($user->roles[$rid]), 'Role assigned to user.');

    // Test removing a role with the list_remove action.
    $rule = rule(array(
      'user' => array(
        'type' => 'user',
      ),
    ));
    $rule
      ->action('list_remove', array(
      'list:select' => 'user:roles',
      'item' => $rid,
    ));
    $rule
      ->execute($user);
    $this
      ->assertTrue(!isset($user->roles[$rid]), 'Role removed from user.');

    // Test assigning a role with user_add_role action.
    $rule = rule(array(
      'user' => array(
        'type' => 'user',
      ),
    ));
    $rule
      ->action('user_add_role', array(
      'account:select' => 'user',
      'roles' => array(
        $rid,
      ),
    ));
    $rule
      ->execute($user);
    $user = user_load($user->uid, TRUE);
    $result = rules_condition('user_has_role', array(
      'roles' => array(
        $rid,
      ),
    ))
      ->execute($user);
    $this
      ->assertTrue($result, 'Role assigned to user.');

    // Test removing a role with the user_remove_role action.
    $rule = rule(array(
      'user' => array(
        'type' => 'user',
      ),
    ));
    $rule
      ->action('user_remove_role', array(
      'account:select' => 'user',
      'roles' => array(
        $rid,
      ),
    ));
    $rule
      ->execute($user);
    $user = user_load($user->uid, TRUE);
    $result = rules_condition('user_has_role', array(
      'roles' => array(
        $rid,
      ),
    ))
      ->execute($user);
    $this
      ->assertFalse($result, 'Role removed from user.');

    // Test user blocking.
    rules_action('user_block')
      ->execute($user);
    $user = user_load($user->uid, TRUE);
    $this
      ->assertTrue(rules_condition('user_is_blocked')
      ->execute($user), 'User has been blocked.');
    rules_action('user_unblock')
      ->execute($user);
    $user = user_load($user->uid, TRUE);
    $this
      ->assertFalse(rules_condition('user_is_blocked')
      ->execute($user), 'User has been unblocked.');
    RulesLog::logger()
      ->checkLog();
  }

  /**
   * Tests integration for the php module.
   */
  public function testPHPIntegration() {
    $node = $this
      ->drupalCreateNode(array(
      'title' => 'foo',
    ));
    $rule = rule(array(
      'var_name' => array(
        'type' => 'node',
      ),
    ));
    $rule
      ->condition('php_eval', array(
      'code' => 'return TRUE;',
    ))
      ->action('php_eval', array(
      'code' => 'drupal_set_message("Executed-" . $var_name->title);',
    ))
      ->action('drupal_message', array(
      'message' => 'Title: <?php echo $var_name->title; ?> Token: [var_name:title]',
    ));
    $rule
      ->execute($node);
    $rule
      ->access();
    RulesLog::logger()
      ->checkLog();
    $msg = drupal_get_messages();
    $this
      ->assertEqual(array_pop($msg['status']), "Title: foo Token: foo", 'PHP input evaluation has been applied.');
    $this
      ->assertEqual(array_pop($msg['status']), "Executed-foo", 'PHP code condition and action have been evaluated.');

    // Test PHP data processor.
    $rule = rule(array(
      'var_name' => array(
        'type' => 'node',
      ),
    ));
    $rule
      ->action('drupal_message', array(
      'message:select' => 'var_name:title',
      'message:process' => array(
        'php' => array(
          'code' => 'return "Title: $value";',
        ),
      ),
    ));
    $rule
      ->execute($node);
    $rule
      ->access();
    RulesLog::logger()
      ->checkLog();
    $msg = drupal_get_messages();
    $this
      ->assertEqual(array_pop($msg['status']), "Title: foo", 'PHP data processor has been applied.');
  }

  /**
   * Tests the "rules_core" integration.
   */
  public function testRulesCoreIntegration() {

    // Make sure the date input evaluator evaluates properly using strtotime().
    $node = $this
      ->drupalCreateNode(array(
      'title' => 'foo',
    ));
    $rule = rule(array(
      'node' => array(
        'type' => 'node',
      ),
    ));
    $rule
      ->action('data_set', array(
      'data:select' => 'node:created',
      'value' => '+1 day',
    ));
    $rule
      ->execute($node);
    RulesLog::logger()
      ->checkLog();
    $node = node_load($node->nid, NULL, TRUE);
    $now = RulesDateInputEvaluator::gmstrtotime('now');

    // Tolerate a difference of a second.
    $this
      ->assertTrue(abs($node->created - $now - 86400) <= 1, 'Date input has been evaluated.');

    // Test using a numeric offset.
    $rule = rule(array(
      'number' => array(
        'type' => 'decimal',
      ),
    ), array(
      'number',
    ));
    $rule
      ->action('data_set', array(
      'data:select' => 'number',
      'value:select' => 'number',
      'value:process' => array(
        'num_offset' => array(
          'value' => 1,
        ),
      ),
    ));
    $rule
      ->integrityCheck();
    list($result) = $rule
      ->execute(10);
    $this
      ->assertTrue($result == 11, 'Numeric offset has been applied');

    // Test using a date offset.
    $set = rules_action_set(array(
      'date' => array(
        'type' => 'date',
      ),
    ), array(
      'date',
    ));
    $set
      ->action('data_set', array(
      'data:select' => 'date',
      'value:select' => 'date',
      'value:process' => array(
        'date_offset' => array(
          'value' => 1000,
        ),
      ),
    ));
    $date = date_create("14 Mar 1984 10:19:23 +01:00")
      ->format('U');
    list($result) = $set
      ->execute($date);
    $this
      ->assertEqual($result, $date + 1000, 'Date offset in seconds has been added.');

    // Test using a negative offset of 2 months.
    $set = rules_action_set(array(
      'date' => array(
        'type' => 'date',
      ),
    ), array(
      'date',
    ));
    $set
      ->action('data_set', array(
      'data:select' => 'date',
      'value:select' => 'date',
      'value:process' => array(
        'date_offset' => array(
          'value' => -86400 * 30 * 2,
        ),
      ),
    ));
    $date = date_create("14 Mar 1984 10:19:23 +01:00")
      ->format('U');
    list($result) = $set
      ->execute($date);
    $this
      ->assertEqual($result, date_create("14 Jan 1984 10:19:23 +01:00")
      ->format('U'), 'Date offset of -2 months has been added.');

    // Test using a positive offset of 1 year 6 months and 30 minutes.
    $set = rules_action_set(array(
      'date' => array(
        'type' => 'date',
      ),
    ), array(
      'date',
    ));
    $set
      ->action('data_set', array(
      'data:select' => 'date',
      'value:select' => 'date',
      'value:process' => array(
        'date_offset' => array(
          'value' => 86400 * 30 * 18 + 30 * 60,
        ),
      ),
    ));
    $date = date_create("14 Mar 1984 10:19:23 +01:00")
      ->format('U');
    list($result) = $set
      ->execute($date);
    $this
      ->assertEqual($result, date_create("14 Sep 1985 10:49:23 +01:00")
      ->format('U'), 'Date offset of 1 year 6 months and 30 minutes has been added.');
    RulesLog::logger()
      ->checkLog();
  }

  /**
   * Tests site/system integration.
   */
  public function testSystemIntegration() {

    // Test using the 'site' variable.
    $condition = rules_condition('data_is', array(
      'data:select' => 'site:current-user:name',
      'value' => $GLOBALS['user']->name,
    ));
    $this
      ->assertTrue($condition
      ->execute(), 'Retrieved the current user\'s name.');

    // Another test using a token replacement.
    $condition = rules_condition('data_is', array(
      'data:select' => 'site:current-user:name',
      'value' => '[site:current-user:name]',
    ));
    $this
      ->assertTrue($condition
      ->execute(), 'Replaced the token for the current user\'s name.');

    // Test breadcrumbs and drupal set message.
    $rule = rules_reaction_rule();
    $rule
      ->event('init')
      ->action('breadcrumb_set', array(
      'titles' => array(
        'foo',
      ),
      'paths' => array(
        'bar',
      ),
    ))
      ->action('drupal_message', array(
      'message' => 'A message.',
    ));
    $rule
      ->save('test');
    $this
      ->drupalGet('node');
    $this
      ->assertLink('foo', 0, 'Breadcrumb has been set.');
    $this
      ->assertText('A message.', 'Drupal message has been shown.');

    // Test the page redirect.
    $node = $this
      ->drupalCreateNode();
    $rule = rules_reaction_rule();
    $rule
      ->event('node_view')
      ->action('redirect', array(
      'url' => 'user',
    ));
    $rule
      ->save('test2');
    $this
      ->drupalGet('node/' . $node->nid);
    $this
      ->assertEqual($this
      ->getUrl(), url('user', array(
      'absolute' => TRUE,
    )), 'Redirect has been issued.');

    // Also test using a url including a fragment.
    $actions = $rule
      ->actions();
    $actions[0]->settings['url'] = 'user#fragment';
    $rule
      ->save();
    $this
      ->drupalGet('node/' . $node->nid);
    $this
      ->assertEqual($this
      ->getUrl(), url('user', array(
      'absolute' => TRUE,
      'fragment' => 'fragment',
    )), 'Redirect has been issued.');

    // Test sending mail.
    $settings = array(
      'to' => 'mail@example.com',
      'subject' => 'subject',
      'message' => 'hello.',
    );
    rules_action('mail', $settings)
      ->execute();
    $this
      ->assertMail('to', 'mail@example.com', 'Mail has been sent.');
    $this
      ->assertMail('from', variable_get('site_mail', ini_get('sendmail_from')), 'Default from address has been used');
    rules_action('mail', $settings + array(
      'from' => 'sender@example.com',
    ))
      ->execute();
    $this
      ->assertMail('from', 'sender@example.com', 'Specified from address has been used');

    // Test sending mail to all users of a role. First clear the mail
    // collector to remove the mail sent in the previous line of code.
    variable_set('drupal_test_email_collector', array());

    // Now make sure there is a custom role and two users with that role.
    $user1 = $this
      ->drupalCreateUser(array(
      'administer nodes',
    ));
    $roles = $user1->roles;

    // Remove the authenticated role so we only use the new role created by
    // drupalCreateUser().
    unset($roles[DRUPAL_AUTHENTICATED_RID]);

    // Now create a second user with the same role.
    $user2 = $this
      ->drupalCreateUser();
    user_save($user2, array(
      'roles' => $roles,
    ));

    // Now create a third user without the same role - this user should NOT
    // receive the role email.
    $user3 = $this
      ->drupalCreateUser(array(
      'administer blocks',
    ));
    $additional_roles = $user3->roles;
    unset($additional_roles[DRUPAL_AUTHENTICATED_RID]);

    // Execute action and check that only two mails were sent.
    rules_action('mail_to_users_of_role', $settings + array(
      'roles' => array_keys($roles),
    ))
      ->execute();
    $mails = $this
      ->drupalGetMails();
    $this
      ->assertEqual(count($mails), 2, '2 e-mails were sent to users of a role.');

    // Check each mail to ensure that only $user1 and $user2 got the mail.
    $mail = array_pop($mails);
    $this
      ->assertTrue($mail['to'] == $user2->mail, 'Mail to user of a role has been sent.');
    $mail = array_pop($mails);
    $this
      ->assertTrue($mail['to'] == $user1->mail, 'Mail to user of a role has been sent.');

    // Execute action again, this time to send mail to both roles.
    // This time check that three mails were sent - one for each user..
    variable_set('drupal_test_email_collector', array());
    rules_action('mail_to_users_of_role', $settings + array(
      'roles' => array_keys($roles + $additional_roles),
    ))
      ->execute();
    $mails = $this
      ->drupalGetMails();
    $this
      ->assertEqual(count($mails), 3, '3 e-mails were sent to users of multiple roles.');

    // Test reacting on new log entries and make sure the log entry is usable.
    $rule = rules_reaction_rule();
    $rule
      ->event('watchdog');
    $rule
      ->action('drupal_message', array(
      'message:select' => 'log_entry:message',
    ));
    $rule
      ->integrityCheck()
      ->save('test_watchdog');
    watchdog('php', 'test %message', array(
      '%message' => 'message',
    ));
    $msg = drupal_get_messages();
    $this
      ->assertEqual(array_pop($msg['status']), t('test %message', array(
      '%message' => 'message',
    )), 'Watchdog event occurred and log entry properties can be used.');
  }

  /**
   * Tests the path module integration.
   */
  public function testPathIntegration() {
    rules_action('path_alias')
      ->execute('foo', 'bar');
    $path = path_load('foo');
    $this
      ->assertTrue($path['alias'] == 'bar', 'URL alias has been created.');
    $alias_exists = rules_condition('path_alias_exists', array(
      'alias' => 'bar',
    ))
      ->execute();
    $this
      ->assertTrue($alias_exists, 'Created URL alias exists.');
    $has_alias = rules_condition('path_has_alias', array(
      'source' => 'foo',
    ))
      ->execute();
    $this
      ->assertTrue($has_alias, 'System path has an alias.');

    // Test node alias action.
    $node = $this
      ->drupalCreateNode();
    rules_action('node_path_alias')
      ->execute($node, 'test');
    $path = path_load("node/{$node->nid}");
    $this
      ->assertTrue($path['alias'] == 'test', 'Node URL alias has been created.');

    // Test term alias action.
    $term = entity_property_values_create_entity('taxonomy_term', array(
      'name' => $this
        ->randomName(),
      'vocabulary' => 1,
    ))
      ->value();
    rules_action('taxonomy_term_path_alias')
      ->execute($term, 'term-test');
    $path = path_load("taxonomy/term/{$term->tid}");
    $this
      ->assertTrue($path['alias'] == 'term-test', 'Term URL alias has been created.');
    RulesLog::logger()
      ->checkLog();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalTestCase::$assertions protected property Assertions thrown in that test case.
DrupalTestCase::$databasePrefix protected property The database prefix of this test run.
DrupalTestCase::$originalFileDirectory protected property The original file directory, before it was changed for testing purposes.
DrupalTestCase::$results public property Current results of this test case.
DrupalTestCase::$setup protected property Flag to indicate whether the test has been set up.
DrupalTestCase::$setupDatabasePrefix protected property
DrupalTestCase::$setupEnvironment protected property
DrupalTestCase::$skipClasses protected property This class is skipped when looking for the source of an assertion.
DrupalTestCase::$testId protected property The test run ID.
DrupalTestCase::$timeLimit protected property Time limit for the test.
DrupalTestCase::$useSetupInstallationCache public property Whether to cache the installation part of the setUp() method.
DrupalTestCase::$useSetupModulesCache public property Whether to cache the modules installation part of the setUp() method.
DrupalTestCase::$verboseDirectoryUrl protected property URL to the verbose output file directory.
DrupalTestCase::assert protected function Internal helper: stores the assert.
DrupalTestCase::assertEqual protected function Check to see if two values are equal.
DrupalTestCase::assertFalse protected function Check to see if a value is false (an empty string, 0, NULL, or FALSE).
DrupalTestCase::assertIdentical protected function Check to see if two values are identical.
DrupalTestCase::assertNotEqual protected function Check to see if two values are not equal.
DrupalTestCase::assertNotIdentical protected function Check to see if two values are not identical.
DrupalTestCase::assertNotNull protected function Check to see if a value is not NULL.
DrupalTestCase::assertNull protected function Check to see if a value is NULL.
DrupalTestCase::assertTrue protected function Check to see if a value is not false (not an empty string, 0, NULL, or FALSE).
DrupalTestCase::deleteAssert public static function Delete an assertion record by message ID.
DrupalTestCase::error protected function Fire an error assertion. 1
DrupalTestCase::errorHandler public function Handle errors during test runs. 1
DrupalTestCase::exceptionHandler protected function Handle exceptions.
DrupalTestCase::fail protected function Fire an assertion that is always negative.
DrupalTestCase::generatePermutations public static function Converts a list of possible parameters into a stack of permutations.
DrupalTestCase::getAssertionCall protected function Cycles through backtrace until the first non-assertion method is found.
DrupalTestCase::getDatabaseConnection public static function Returns the database connection to the site running Simpletest.
DrupalTestCase::insertAssert public static function Store an assertion from outside the testing context.
DrupalTestCase::pass protected function Fire an assertion that is always positive.
DrupalTestCase::randomName public static function Generates a random string containing letters and numbers.
DrupalTestCase::randomString public static function Generates a random string of ASCII characters of codes 32 to 126.
DrupalTestCase::run public function Run all tests in this class.
DrupalTestCase::verbose protected function Logs a verbose message in a text file.
DrupalWebTestCase::$additionalCurlOptions protected property Additional cURL options.
DrupalWebTestCase::$content protected property The content of the page currently loaded in the internal browser.
DrupalWebTestCase::$cookieFile protected property The current cookie file used by cURL.
DrupalWebTestCase::$cookies protected property The cookies of the page currently loaded in the internal browser.
DrupalWebTestCase::$curlHandle protected property The handle of the current cURL connection.
DrupalWebTestCase::$drupalSettings protected property The value of the Drupal.settings JavaScript variable for the page currently loaded in the internal browser.
DrupalWebTestCase::$elements protected property The parsed version of the page.
DrupalWebTestCase::$generatedTestFiles protected property Whether the files were copied to the test files directory.
DrupalWebTestCase::$headers protected property The headers of the page currently loaded in the internal browser.
DrupalWebTestCase::$httpauth_credentials protected property HTTP authentication credentials (<username>:<password>).
DrupalWebTestCase::$httpauth_method protected property HTTP authentication method
DrupalWebTestCase::$loggedInUser protected property The current user logged in using the internal browser.
DrupalWebTestCase::$originalShutdownCallbacks protected property The original shutdown handlers array, before it was cleaned for testing purposes.
DrupalWebTestCase::$originalUser protected property The original user, before it was changed to a clean uid = 1 for testing purposes.
DrupalWebTestCase::$plainTextContent protected property The content of the page currently loaded in the internal browser (plain text version).
DrupalWebTestCase::$profile protected property The profile to install as a basis for testing. 20
DrupalWebTestCase::$redirect_count protected property The number of redirects followed during the handling of a request.
DrupalWebTestCase::$session_id protected property The current session ID, if available.
DrupalWebTestCase::$session_name protected property The current session name, if available.
DrupalWebTestCase::$url protected property The URL currently loaded in the internal browser.
DrupalWebTestCase::assertField protected function Asserts that a field exists with the given name or ID.
DrupalWebTestCase::assertFieldById protected function Asserts that a field exists in the current page with the given ID and value.
DrupalWebTestCase::assertFieldByName protected function Asserts that a field exists in the current page with the given name and value.
DrupalWebTestCase::assertFieldByXPath protected function Asserts that a field exists in the current page by the given XPath.
DrupalWebTestCase::assertFieldChecked protected function Asserts that a checkbox field in the current page is checked.
DrupalWebTestCase::assertLink protected function Pass if a link with the specified label is found, and optional with the specified index.
DrupalWebTestCase::assertLinkByHref protected function Pass if a link containing a given href (part) is found.
DrupalWebTestCase::assertMail protected function Asserts that the most recently sent e-mail message has the given value.
DrupalWebTestCase::assertMailPattern protected function Asserts that the most recently sent e-mail message has the pattern in it.
DrupalWebTestCase::assertMailString protected function Asserts that the most recently sent e-mail message has the string in it.
DrupalWebTestCase::assertNoDuplicateIds protected function Asserts that each HTML ID is used for just a single element.
DrupalWebTestCase::assertNoField protected function Asserts that a field does not exist with the given name or ID.
DrupalWebTestCase::assertNoFieldById protected function Asserts that a field does not exist with the given ID and value.
DrupalWebTestCase::assertNoFieldByName protected function Asserts that a field does not exist with the given name and value.
DrupalWebTestCase::assertNoFieldByXPath protected function Asserts that a field doesn't exist or its value doesn't match, by XPath.
DrupalWebTestCase::assertNoFieldChecked protected function Asserts that a checkbox field in the current page is not checked.
DrupalWebTestCase::assertNoLink protected function Pass if a link with the specified label is not found.
DrupalWebTestCase::assertNoLinkByHref protected function Pass if a link containing a given href (part) is not found.
DrupalWebTestCase::assertNoOptionSelected protected function Asserts that a select option in the current page is not checked.
DrupalWebTestCase::assertNoPattern protected function Will trigger a pass if the perl regex pattern is not present in raw content.
DrupalWebTestCase::assertNoRaw protected function Pass if the raw text is NOT found on the loaded page, fail otherwise. Raw text refers to the raw HTML that the page generated.
DrupalWebTestCase::assertNoResponse protected function Asserts the page did not return the specified response code.
DrupalWebTestCase::assertNoText protected function Pass if the text is NOT found on the text version of the page. The text version is the equivalent of what a user would see when viewing through a web browser. In other words the HTML has been filtered out of the contents.
DrupalWebTestCase::assertNoTitle protected function Pass if the page title is not the given string.
DrupalWebTestCase::assertNoUniqueText protected function Pass if the text is found MORE THAN ONCE on the text version of the page.
DrupalWebTestCase::assertOptionSelected protected function Asserts that a select option in the current page is checked.
DrupalWebTestCase::assertPattern protected function Will trigger a pass if the Perl regex pattern is found in the raw content.
DrupalWebTestCase::assertRaw protected function Pass if the raw text IS found on the loaded page, fail otherwise. Raw text refers to the raw HTML that the page generated.
DrupalWebTestCase::assertResponse protected function Asserts the page responds with the specified response code.
DrupalWebTestCase::assertText protected function Pass if the text IS found on the text version of the page. The text version is the equivalent of what a user would see when viewing through a web browser. In other words the HTML has been filtered out of the contents.
DrupalWebTestCase::assertTextHelper protected function Helper for assertText and assertNoText.
DrupalWebTestCase::assertThemeOutput protected function Asserts themed output.
DrupalWebTestCase::assertTitle protected function Pass if the page title is the given string.
DrupalWebTestCase::assertUniqueText protected function Pass if the text is found ONLY ONCE on the text version of the page.
DrupalWebTestCase::assertUniqueTextHelper protected function Helper for assertUniqueText and assertNoUniqueText.
DrupalWebTestCase::assertUrl protected function Pass if the internal browser's URL matches the given path.
DrupalWebTestCase::buildXPathQuery protected function Builds an XPath query.
DrupalWebTestCase::changeDatabasePrefix protected function Changes the database connection to the prefixed one.
DrupalWebTestCase::checkForMetaRefresh protected function Check for meta refresh tag and if found call drupalGet() recursively. This function looks for the http-equiv attribute to be set to "Refresh" and is case-sensitive.
DrupalWebTestCase::checkPermissions protected function Check to make sure that the array of permissions are valid.
DrupalWebTestCase::clickLink protected function Follows a link by name.
DrupalWebTestCase::constructFieldXpath protected function Helper function: construct an XPath for the given set of attributes and value.
DrupalWebTestCase::copySetupCache protected function Copy the setup cache from/to another table and files directory.
DrupalWebTestCase::cronRun protected function Runs cron in the Drupal installed by Simpletest.
DrupalWebTestCase::curlClose protected function Close the cURL handler and unset the handler.
DrupalWebTestCase::curlExec protected function Initializes and executes a cURL request.
DrupalWebTestCase::curlHeaderCallback protected function Reads headers and registers errors received from the tested site.
DrupalWebTestCase::curlInitialize protected function Initializes the cURL connection.
DrupalWebTestCase::drupalCompareFiles protected function Compare two files based on size and file name.
DrupalWebTestCase::drupalCreateContentType protected function Creates a custom content type based on default settings.
DrupalWebTestCase::drupalCreateNode protected function Creates a node based on default settings.
DrupalWebTestCase::drupalCreateRole protected function Creates a role with specified permissions.
DrupalWebTestCase::drupalCreateUser protected function Create a user with a given set of permissions.
DrupalWebTestCase::drupalGet protected function Retrieves a Drupal path or an absolute path.
DrupalWebTestCase::drupalGetAJAX protected function Retrieve a Drupal path or an absolute path and JSON decode the result.
DrupalWebTestCase::drupalGetContent protected function Gets the current raw HTML of requested page.
DrupalWebTestCase::drupalGetHeader protected function Gets the value of an HTTP response header. If multiple requests were required to retrieve the page, only the headers from the last request will be checked by default. However, if TRUE is passed as the second argument, all requests will be processed…
DrupalWebTestCase::drupalGetHeaders protected function Gets the HTTP response headers of the requested page. Normally we are only interested in the headers returned by the last request. However, if a page is redirected or HTTP authentication is in use, multiple requests will be required to retrieve the…
DrupalWebTestCase::drupalGetMails protected function Gets an array containing all e-mails sent during this test case.
DrupalWebTestCase::drupalGetNodeByTitle function Get a node from the database based on its title.
DrupalWebTestCase::drupalGetSettings protected function Gets the value of the Drupal.settings JavaScript variable for the currently loaded page.
DrupalWebTestCase::drupalGetTestFiles protected function Get a list files that can be used in tests.
DrupalWebTestCase::drupalGetToken protected function Generate a token for the currently logged in user.
DrupalWebTestCase::drupalHead protected function Retrieves only the headers for a Drupal path or an absolute path.
DrupalWebTestCase::drupalLogin protected function Log in a user with the internal browser.
DrupalWebTestCase::drupalLogout protected function
DrupalWebTestCase::drupalPost protected function Execute a POST request on a Drupal page. It will be done as usual POST request with SimpleBrowser.
DrupalWebTestCase::drupalPostAJAX protected function Execute an Ajax submission.
DrupalWebTestCase::drupalSetContent protected function Sets the raw HTML content. This can be useful when a page has been fetched outside of the internal browser and assertions need to be made on the returned page.
DrupalWebTestCase::drupalSetSettings protected function Sets the value of the Drupal.settings JavaScript variable for the currently loaded page.
DrupalWebTestCase::getAbsoluteUrl protected function Takes a path and returns an absolute path.
DrupalWebTestCase::getAllOptions protected function Get all option elements, including nested options, in a select.
DrupalWebTestCase::getSelectedItem protected function Get the selected value from a select field.
DrupalWebTestCase::getSetupCacheKey protected function Returns the cache key used for the setup caching.
DrupalWebTestCase::getUrl protected function Get the current URL from the cURL handler.
DrupalWebTestCase::handleForm protected function Handle form input related to drupalPost(). Ensure that the specified fields exist and attempt to create POST data in the correct manner for the particular field type.
DrupalWebTestCase::loadSetupCache protected function Copies the cached tables and files for a cached installation setup.
DrupalWebTestCase::parse protected function Parse content returned from curlExec using DOM and SimpleXML.
DrupalWebTestCase::preloadRegistry protected function Preload the registry from the testing site.
DrupalWebTestCase::prepareDatabasePrefix protected function Generates a database prefix for running tests.
DrupalWebTestCase::prepareEnvironment protected function Prepares the current environment for running the test.
DrupalWebTestCase::recursiveDirectoryCopy protected function Recursively copy one directory to another.
DrupalWebTestCase::refreshVariables protected function Refresh the in-memory set of variables. Useful after a page request is made that changes a variable in a different thread. 1
DrupalWebTestCase::resetAll protected function Reset all data structures after having enabled new modules.
DrupalWebTestCase::storeSetupCache protected function Store the installation setup to a cache.
DrupalWebTestCase::tearDown protected function Delete created files and temporary files directory, delete the tables created by setUp(), and reset the database prefix. 6
DrupalWebTestCase::verboseEmail protected function Outputs to verbose the most recent $count emails sent.
DrupalWebTestCase::xpath protected function Perform an xpath search on the contents of the internal browser. The search is relative to the root element (HTML tag normally) of the page.
DrupalWebTestCase::__construct function Constructor for DrupalWebTestCase. Overrides DrupalTestCase::__construct 1
RulesIntegrationTestCase::getInfo public static function Declares test metadata.
RulesIntegrationTestCase::setUp protected function Overrides DrupalWebTestCase::setUp(). Overrides DrupalWebTestCase::setUp
RulesIntegrationTestCase::testAccessCallbacks public function Just makes sure the access callback run without errors.
RulesIntegrationTestCase::testDataIntegration public function Tests data integration.
RulesIntegrationTestCase::testEntityIntegration public function Tests entity related integration.
RulesIntegrationTestCase::testNodeIntegration public function Tests integration for the node module.
RulesIntegrationTestCase::testPathIntegration public function Tests the path module integration.
RulesIntegrationTestCase::testPHPIntegration public function Tests integration for the php module.
RulesIntegrationTestCase::testRulesCoreIntegration public function Tests the "rules_core" integration.
RulesIntegrationTestCase::testSystemIntegration public function Tests site/system integration.
RulesIntegrationTestCase::testTaxonomyIntegration public function Tests integration for the taxonomy module.
RulesIntegrationTestCase::testUserIntegration public function Tests integration for the user module.