-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathRulesDrupalTestBase.php
More file actions
97 lines (83 loc) · 2.3 KB
/
RulesDrupalTestBase.php
File metadata and controls
97 lines (83 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/**
* @file
* Contains \Drupal\rules\Tests\RulesDrupalTestBase.
*/
namespace Drupal\rules\Tests;
use Drupal\rules\Logger\RulesStubLogger;
use Drupal\simpletest\KernelTestBase;
/**
* Base class for Rules Drupal unit tests.
*/
abstract class RulesDrupalTestBase extends KernelTestBase {
/**
* The expression plugin manager.
*
* @var \Drupal\rules\Engine\ExpressionPluginManager
*/
protected $expressionManager;
/**
* The condition plugin manager.
*
* @var \Drupal\Core\Condition\ConditionManager
*/
protected $conditionManager;
/**
* The typed data manager.
*
* @var \Drupal\Core\TypedData\TypedDataManager
*/
protected $typedDataManager;
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['rules', 'rules_test', 'system'];
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
// Prepare Rules logging for testing.
$this->installConfig(array('rules'));
$logger = new RulesStubLogger();
$this->container->get('config.factory')
->getEditable('rules.settings')
->set('debug_log', 1)
->save();
$this->container->set('logger', $logger);
$this->container->get('logger')->cleanLogs();
$this->expressionManager = $this->container->get('plugin.manager.rules_expression');
$this->conditionManager = $this->container->get('plugin.manager.condition');
$this->typedDataManager = $this->container->get('typed_data_manager');
}
/**
* Creates a new condition.
*
* @param string $id
* The condition plugin id.
*
* @return \Drupal\rules\Core\RulesConditionInterface
* The created condition plugin.
*/
protected function createCondition($id) {
$condition = $this->expressionManager->createInstance('rules_condition', [
'condition_id' => $id,
]);
return $condition;
}
/**
* Checks if particular message is in the log with given delta.
*
* @param string $message
* Log message.
* @param int $log_item_index
* Log item's index in log entries stack.
*/
protected function assertRulesLogEntryExists($message, $log_item_index = 0) {
// Test that the action has logged something.
$logs = $this->container->get('logger')->getLogs();
$this->assertEqual($logs[$log_item_index]['message'], $message);
}
}