class RulesConditionalTestCase in Conditional Rules 8
Same name and namespace in other branches
- 7 tests/rules_conditional.test \RulesConditionalTestCase
Default if-else tests.
Hierarchy
- class \RulesConditionalBaseTestCase extends \DrupalWebTestCase
- class \RulesConditionalTestCase
Expanded class hierarchy of RulesConditionalTestCase
File
- tests/
rules_conditional.test, line 304 - SimpleTest testing suites.
View source
class RulesConditionalTestCase extends RulesConditionalBaseTestCase {
/**
* Returns test info.
*/
public static function getInfo() {
return array(
'name' => 'Conditional',
'description' => 'Test the if-else plugins.',
'group' => 'Conditional Rules',
);
}
/**
* Sets up test case.
*/
protected function setUp() {
parent::setUp('rules_conditional_test');
}
/**
* Tests evaluation.
*/
public function testEvaluate() {
// Create test objects.
$comp = $this
->createTestComponent();
$this
->assert($this
->doTestEvaluate($comp), 'Conditional correctly evaluates.');
}
/**
* Tests exporting.
*/
public function testExport() {
$comp = $this
->createTestComponent();
$comp->name = 'conditional_test';
$export = $this
->getFileContents('conditional_test_export.txt');
$this
->assertEqual($export, $comp
->export(), 'Conditional is correctly exported.');
}
/**
* Tests importing.
*/
public function testImport() {
$export = $this
->getFileContents('conditional_test_export.txt');
$comp = entity_import('rules_config', $export);
$this
->assert($this
->doTestEvaluate($comp), 'Imported conditional correctly evaluates.');
}
/**
* Creates an action set to test a conditional.
*/
protected function createTestComponent() {
return rules_action_set(array(
'node' => array(
'type' => 'node',
'label' => 'Node',
),
))
->action(rules_conditional()
->if('data_is', array(
'data:select' => 'node:title',
'value' => 'if',
))
->action('rules_conditional_test_throw', array(
'message' => 'if',
))
->elseIf('data_is', array(
'data:select' => 'node:title',
'value' => 'else if',
))
->action('rules_conditional_test_throw', array(
'message' => 'else if',
))
->else()
->action('rules_conditional_test_throw', array(
'message' => 'else',
)));
}
/**
* Tests evaluating a conditional.
*/
public function doTestEvaluate($comp) {
$node = $this
->drupalCreateNode();
$result = TRUE;
// Test "if".
$node->title = 'if';
$result = $this
->assertExecution('if', $comp, array(
$node,
)) && $result;
// Test "else if".
$node->title = 'else if';
$result = $this
->assertExecution('else if', $comp, array(
$node,
)) && $result;
// Test "else".
$node->title = 'else';
$result = $this
->assertExecution('else', $comp, array(
$node,
)) && $result;
return $result;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RulesConditionalBaseTestCase:: |
protected | function | Asserts a test message from the execution of a rule configuration. | |
RulesConditionalBaseTestCase:: |
protected | function | Retrieves a file in the test directory. | |
RulesConditionalTestCase:: |
protected | function | Creates an action set to test a conditional. | |
RulesConditionalTestCase:: |
public | function | Tests evaluating a conditional. | |
RulesConditionalTestCase:: |
public static | function | Returns test info. | |
RulesConditionalTestCase:: |
protected | function | Sets up test case. | |
RulesConditionalTestCase:: |
public | function | Tests evaluation. | |
RulesConditionalTestCase:: |
public | function | Tests exporting. | |
RulesConditionalTestCase:: |
public | function | Tests importing. |