You are here

public function RulesTestDataCase::testTypeMatching in Rules 7.2

Same name and namespace in other branches
  1. 8.3 d7-tests/rules_test_data_case.test \RulesTestDataCase::testTypeMatching()

Tests type matching.

File

tests/rules.test, line 1019
Rules tests.

Class

RulesTestDataCase
Test rules data wrappers.

Code

public function testTypeMatching() {
  $entity = array(
    'type' => 'entity',
  );
  $node = array(
    'type' => 'node',
  );
  $this
    ->assertTrue(RulesData::typesMatch($node, $entity), 'Types match.');
  $this
    ->assertFalse(RulesData::typesMatch($entity, $node), 'Types don\'t match.');
  $this
    ->assertTrue(RulesData::typesMatch($node + array(
    'bundle' => 'page',
  ), $node), 'Types match.');
  $this
    ->assertTrue(RulesData::typesMatch($node + array(
    'bundle' => 'page',
  ), $entity), 'Types match.');
  $this
    ->assertTrue(RulesData::typesMatch(array(
    'type' => 'list<node>',
  ), array(
    'type' => 'list',
  )), 'Types match.');
  $this
    ->assertTrue(RulesData::typesMatch($node + array(
    'bundle' => 'page',
  ), $node + array(
    'bundles' => array(
      'page',
      'story',
    ),
  )), 'Types match.');
  $this
    ->assertFalse(RulesData::typesMatch($node, $node + array(
    'bundles' => array(
      'page',
      'story',
    ),
  )), 'Types don\'t match.');

  // Test that a type matches its grand-parent type (text > decimal > integer)
  $this
    ->assertTrue(RulesData::typesMatch(array(
    'type' => 'integer',
  ), array(
    'type' => 'text',
  )), 'Types match.');
  $this
    ->assertFalse(RulesData::typesMatch(array(
    'type' => 'text',
  ), array(
    'type' => 'integer',
  )), 'Types don\'t match.');
}