public function ConfigEntityCalculateDependencyTest::testConditionCalculateDependencies in Business Rules 2.x
Same name and namespace in other branches
- 8 tests/src/Unit/ConfigEntityCalculateDependencyTest.php \Drupal\Tests\business_rules\Unit\ConfigEntityCalculateDependencyTest::testConditionCalculateDependencies()
@covers \Drupal\business_rules\Entity\Condition::calculateDependencies
File
- tests/
src/ Unit/ ConfigEntityCalculateDependencyTest.php, line 179
Class
- ConfigEntityCalculateDependencyTest
- Test dependencies calculation.
Namespace
Drupal\Tests\business_rules\UnitCode
public function testConditionCalculateDependencies() {
$this->businessRulesConditionManager
->expects($this
->any())
->method('getDefinition')
->willReturnMap([
[
'user_has_role',
TRUE,
[
'class' => UserHasRole::class,
'id' => 'user_has_role',
],
],
[
'logical_and',
TRUE,
[
'class' => LogicalAnd::class,
'id' => 'logical_and',
],
],
]);
$condition = new Condition([
'type' => 'user_has_role',
]);
$dependencies = $condition
->calculateDependencies()
->getDependencies();
$this
->assertArrayNotHasKey('config', $dependencies);
$dependencyA = new BusinessRulesItemObject('test_action_a', 'action', 0);
$condition
->addSuccessItem($dependencyA);
$dependencies = $condition
->calculateDependencies()
->getDependencies();
$this
->assertEquals([
'business_rules.action.test_action_a',
], $dependencies['config']);
$dependencyB = new BusinessRulesItemObject('test_condition_a', 'condition', 0);
$condition
->addFailItem($dependencyB);
$dependencies = $condition
->calculateDependencies()
->getDependencies();
$this
->assertEquals([
'business_rules.action.test_action_a',
'business_rules.condition.test_condition_a',
], $dependencies['config']);
$condition = new Condition([
'type' => 'logical_and',
]);
$dependencies = $condition
->calculateDependencies()
->getDependencies();
$this
->assertArrayNotHasKey('config', $dependencies);
$condition
->setSetting('items', [
'test_condition_a' => [
'weight' => 0,
'type' => 'condition',
'id' => 'test_condition_a',
],
]);
$dependencies = $condition
->calculateDependencies()
->getDependencies();
$this
->assertEquals([
'business_rules.condition.test_condition_a',
], $dependencies['config']);
$condition
->setSetting('items', [
'test_condition_a' => [
'weight' => 0,
'type' => 'condition',
'id' => 'test_condition_a',
],
'test_condition_b' => [
'weight' => 0,
'type' => 'condition',
'id' => 'test_condition_b',
],
]);
$dependencies = $condition
->calculateDependencies()
->getDependencies();
$this
->assertEquals([
'business_rules.condition.test_condition_a',
'business_rules.condition.test_condition_b',
], $dependencies['config']);
}