-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathConfigureAndExecuteTest.php
More file actions
107 lines (83 loc) · 2.96 KB
/
ConfigureAndExecuteTest.php
File metadata and controls
107 lines (83 loc) · 2.96 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
98
99
100
101
102
103
104
105
106
107
<?php
namespace Drupal\Tests\rules\Functional;
/**
* Tests that a rule can be configured and triggered when a node is edited.
*
* @group rules_ui
*/
class ConfigureAndExecuteTest extends RulesBrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['node', 'rules'];
/**
* We use the minimal profile because we want to test local action links.
*
* @var string
*/
protected $profile = 'minimal';
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
// Create an article content type that we will use for testing.
$type = $this->container->get('entity_type.manager')->getStorage('node_type')
->create([
'type' => 'article',
'name' => 'Article',
]);
$type->save();
$this->container->get('router.builder')->rebuild();
}
/**
* Tests creation of a rule and then triggering its execution.
*/
public function testConfigureAndExecute() {
$account = $this->drupalCreateUser([
'create article content',
'administer rules',
'administer site configuration',
]);
$this->drupalLogin($account);
$this->drupalGet('admin/config/workflow/rules');
// Set up a rule that will show a system message if the title of a node
// matches "Test title".
$this->clickLink('Add reaction rule');
$this->fillField('Label', 'Test rule');
$this->fillField('Machine-readable name', 'test_rule');
$this->fillField('React on event', 'rules_entity_presave:node');
$this->pressButton('Save');
$this->clickLink('Add condition');
$this->fillField('Condition', 'rules_data_comparison');
$this->pressButton('Continue');
// @todo this should not be necessary once the data context is set to
// selector by default anyway.
$this->pressButton('Switch to data selection');
$this->fillField('context[data][setting]', 'node.title.0.value');
$this->fillField('context[value][setting]', 'Test title');
$this->pressButton('Save');
$this->clickLink('Add action');
$this->fillField('Action', 'rules_system_message');
$this->pressButton('Continue');
$this->fillField('context[message][setting]', 'Title matched "Test title"!');
$this->fillField('context[type][setting]', 'status');
$this->pressButton('Save');
// One more save to permanently store the rule.
$this->pressButton('Save');
// Add a node now and check if our rule triggers.
$this->drupalGet('node/add/article');
$this->fillField('Title', 'Test title');
$this->pressButton('Save');
$this->assertSession()->pageTextContains('Title matched "Test title"!');
// Disable rule and make sure it doesn't get triggered.
$this->drupalGet('admin/config/workflow/rules');
$this->clickLink('Disable');
$this->drupalGet('node/add/article');
$this->fillField('Title', 'Test title');
$this->pressButton('Save');
$this->assertSession()->pageTextNotContains('Title matched "Test title"!');
}
}