RngScheduledRuleTest.php in RNG - Events and Registrations 8
File
tests/src/Kernel/RngScheduledRuleTest.php
View source
<?php
namespace Drupal\Tests\rng\Kernel;
use Drupal\rng\Entity\Rule;
use Drupal\rng\Entity\RuleComponent;
use Drupal\rng\Entity\RuleSchedule;
class RngScheduledRuleTest extends RngKernelTestBase {
public static $modules = [
'system',
'entity_test',
];
protected $rule;
protected $condition;
protected $registrationType;
protected $eventType;
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('entity_test');
$this
->installEntitySchema('rng_rule');
$this
->installEntitySchema('rng_rule_component');
$this
->installEntitySchema('rng_rule_scheduler');
$this
->installEntitySchema('courier_template_collection');
$this
->installSchema('system', [
'sequences',
]);
$this->registrationType = $this
->createRegistrationType();
$this->eventType = $this
->createEventType('entity_test', 'entity_test');
$action_manager = $this->container
->get('plugin.manager.action');
$condition_manager = $this->container
->get('plugin.manager.condition');
$event_meta = $this
->createEvent();
$this->rule = Rule::create([
'event' => array(
'entity' => $event_meta
->getEvent(),
),
'trigger_id' => 'rng:custom:date',
]);
$actionPlugin = $action_manager
->createInstance('rng_courier_message');
$action = RuleComponent::create([])
->setPluginId($actionPlugin
->getPluginId())
->setConfiguration($actionPlugin
->getConfiguration())
->setType('action');
$this->rule
->addComponent($action);
$conditionPlugin = $condition_manager
->createInstance('rng_rule_scheduler');
$condition = RuleComponent::create()
->setPluginId($conditionPlugin
->getPluginId())
->setConfiguration($conditionPlugin
->getConfiguration())
->setType('condition');
$condition
->save();
$condition
->setConfiguration([
'rng_rule_component' => $condition
->id(),
'date' => 1234,
]);
$condition
->save();
$this->condition = $condition;
}
public function testRuleScheduleCreated() {
$this->rule
->setIsActive(TRUE)
->addComponent($this->condition)
->save();
$this
->assertEquals(1, count(RuleSchedule::loadMultiple()));
}
public function testRuleScheduleNotCreated() {
$this->rule
->setIsActive(FALSE)
->addComponent($this->condition)
->save();
$this
->assertEquals(0, count(RuleSchedule::loadMultiple()));
}
public function testRuleScheduleDeleted() {
$this->rule
->setIsActive(TRUE)
->addComponent($this->condition)
->save();
$this
->assertEquals(1, count(RuleSchedule::loadMultiple()));
$this->rule
->setIsActive(FALSE)
->save();
$this
->assertEquals(0, count(RuleSchedule::loadMultiple()));
}
}