function RulesTestDataCase::testTypeMatching
Same name in other branches
- 8.x-3.x d7-tests/rules_test_data_case.test \RulesTestDataCase::testTypeMatching()
Tests type matching.
File
-
tests/
rules.test, line 1020
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.');
}