class RulesConditionalWhileTestCase in Conditional Rules 8
Same name and namespace in other branches
- 7 tests/rules_conditional.test \RulesConditionalWhileTestCase
While tests.
Hierarchy
- class \RulesConditionalBaseTestCase extends \DrupalWebTestCase
Expanded class hierarchy of RulesConditionalWhileTestCase
File
- tests/
rules_conditional.test, line 480 - SimpleTest testing suites.
View source
class RulesConditionalWhileTestCase extends RulesConditionalBaseTestCase {
/**
* Returns test info.
*/
public static function getInfo() {
return array(
'name' => 'While loop',
'description' => 'Test the while loop plugin.',
'group' => 'Conditional Rules',
);
}
/**
* Sets up test case.
*/
protected function setUp() {
parent::setUp('rules_conditional_test');
}
/**
* Tests evaluation.
*/
public function testEvaluate() {
// Cap iteration limit to prevent long-running tests.
variable_set('rules_conditional_max_iterations', 100);
$comp = $this
->createTestComponent();
$this
->assert($this
->doTestEvaluate($comp), 'While loop correctly evaluates.');
// Constrain iteration limit and test again.
variable_set('rules_conditional_max_iterations', 5);
$this
->assert($this
->doTestEvaluate($comp, 5), 'While loop correctly evaluates with limited number of iterations.');
}
/**
* Tests exporting.
*/
public function testExport() {
$comp = $this
->createTestComponent();
$comp->name = 'while_test';
$export = $this
->getFileContents('while_test_export.txt');
$this
->assertEqual($export, $comp
->export(), 'While loop is correctly exported.');
}
/**
* Tests importing.
*/
public function testImport() {
// Cap iteration limit to prevent long-running tests.
variable_set('rules_conditional_max_iterations', 100);
$export = $this
->getFileContents('while_test_export.txt');
$comp = entity_import('rules_config', $export);
$this
->assert($this
->doTestEvaluate($comp), 'Imported while loop correctly evaluates.');
}
/**
* Creates an action set to test a conditional.
*/
protected function createTestComponent() {
return rules_action_set(array())
->action('variable_add', array(
'type' => 'integer',
'value' => 0,
'variable_added:var' => 'count',
'variable_added:label' => 'Count',
))
->action(rules_conditional_while('data_is', array(
'data:select' => 'count',
'op' => '>',
'value' => 10,
))
->negate()
->action('data_set', array(
'data:select' => 'count',
'value:select' => 'count',
'value:process' => array(
'num_offset' => array(
'value' => 1,
),
),
)))
->action('rules_conditional_test_throw', array(
'message:select' => 'count',
));
}
/**
* Tests evaluating a conditional.
*/
public function doTestEvaluate($comp, $expectedCount = 11) {
return $this
->assertExecution($expectedCount, $comp);
}
}
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. | |
RulesConditionalWhileTestCase:: |
protected | function | Creates an action set to test a conditional. | |
RulesConditionalWhileTestCase:: |
public | function | Tests evaluating a conditional. | |
RulesConditionalWhileTestCase:: |
public static | function | Returns test info. | |
RulesConditionalWhileTestCase:: |
protected | function | Sets up test case. | |
RulesConditionalWhileTestCase:: |
public | function | Tests evaluation. | |
RulesConditionalWhileTestCase:: |
public | function | Tests exporting. | |
RulesConditionalWhileTestCase:: |
public | function | Tests importing. |