Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\node\Functional;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Component\Utility\Crypt;
|
Chris@0
|
6 use Drupal\Tests\BrowserTestBase;
|
Chris@0
|
7 use Drupal\system\Entity\Action;
|
Chris@0
|
8
|
Chris@0
|
9 /**
|
Chris@0
|
10 * Tests configuration of actions provided by the Node module.
|
Chris@0
|
11 *
|
Chris@0
|
12 * @group node
|
Chris@0
|
13 */
|
Chris@0
|
14 class NodeActionsConfigurationTest extends BrowserTestBase {
|
Chris@0
|
15
|
Chris@0
|
16 /**
|
Chris@0
|
17 * Modules to install.
|
Chris@0
|
18 *
|
Chris@0
|
19 * @var array
|
Chris@0
|
20 */
|
Chris@0
|
21 public static $modules = ['action', 'node'];
|
Chris@0
|
22
|
Chris@0
|
23 /**
|
Chris@0
|
24 * Tests configuration of the node_assign_owner_action action.
|
Chris@0
|
25 */
|
Chris@0
|
26 public function testAssignOwnerNodeActionConfiguration() {
|
Chris@0
|
27 // Create a user with permission to view the actions administration pages.
|
Chris@0
|
28 $user = $this->drupalCreateUser(['administer actions']);
|
Chris@0
|
29 $this->drupalLogin($user);
|
Chris@0
|
30
|
Chris@0
|
31 // Make a POST request to admin/config/system/actions.
|
Chris@0
|
32 $edit = [];
|
Chris@0
|
33 $edit['action'] = Crypt::hashBase64('node_assign_owner_action');
|
Chris@0
|
34 $this->drupalPostForm('admin/config/system/actions', $edit, t('Create'));
|
Chris@0
|
35 $this->assertResponse(200);
|
Chris@0
|
36
|
Chris@0
|
37 // Make a POST request to the individual action configuration page.
|
Chris@0
|
38 $edit = [];
|
Chris@0
|
39 $action_label = $this->randomMachineName();
|
Chris@0
|
40 $edit['label'] = $action_label;
|
Chris@0
|
41 $edit['id'] = strtolower($action_label);
|
Chris@0
|
42 $edit['owner_uid'] = $user->id();
|
Chris@0
|
43 $this->drupalPostForm('admin/config/system/actions/add/' . Crypt::hashBase64('node_assign_owner_action'), $edit, t('Save'));
|
Chris@0
|
44 $this->assertResponse(200);
|
Chris@0
|
45
|
Chris@0
|
46 // Make sure that the new action was saved properly.
|
Chris@0
|
47 $this->assertText(t('The action has been successfully saved.'), 'The node_assign_owner_action action has been successfully saved.');
|
Chris@0
|
48 $this->assertText($action_label, 'The label of the node_assign_owner_action action appears on the actions administration page after saving.');
|
Chris@0
|
49
|
Chris@0
|
50 // Make another POST request to the action edit page.
|
Chris@0
|
51 $this->clickLink(t('Configure'));
|
Chris@0
|
52 preg_match('|admin/config/system/actions/configure/(.+)|', $this->getUrl(), $matches);
|
Chris@0
|
53 $aid = $matches[1];
|
Chris@0
|
54 $edit = [];
|
Chris@0
|
55 $new_action_label = $this->randomMachineName();
|
Chris@0
|
56 $edit['label'] = $new_action_label;
|
Chris@0
|
57 $edit['owner_uid'] = $user->id();
|
Chris@0
|
58 $this->drupalPostForm(NULL, $edit, t('Save'));
|
Chris@0
|
59 $this->assertResponse(200);
|
Chris@0
|
60
|
Chris@0
|
61 // Make sure that the action updated properly.
|
Chris@0
|
62 $this->assertText(t('The action has been successfully saved.'), 'The node_assign_owner_action action has been successfully updated.');
|
Chris@0
|
63 $this->assertNoText($action_label, 'The old label for the node_assign_owner_action action does not appear on the actions administration page after updating.');
|
Chris@0
|
64 $this->assertText($new_action_label, 'The new label for the node_assign_owner_action action appears on the actions administration page after updating.');
|
Chris@0
|
65
|
Chris@0
|
66 // Make sure that deletions work properly.
|
Chris@0
|
67 $this->drupalGet('admin/config/system/actions');
|
Chris@0
|
68 $this->clickLink(t('Delete'));
|
Chris@0
|
69 $this->assertResponse(200);
|
Chris@0
|
70 $edit = [];
|
Chris@0
|
71 $this->drupalPostForm("admin/config/system/actions/configure/$aid/delete", $edit, t('Delete'));
|
Chris@0
|
72 $this->assertResponse(200);
|
Chris@0
|
73
|
Chris@0
|
74 // Make sure that the action was actually deleted.
|
Chris@0
|
75 $this->assertRaw(t('The action %action has been deleted.', ['%action' => $new_action_label]), 'The delete confirmation message appears after deleting the node_assign_owner_action action.');
|
Chris@0
|
76 $this->drupalGet('admin/config/system/actions');
|
Chris@0
|
77 $this->assertResponse(200);
|
Chris@0
|
78 $this->assertNoText($new_action_label, 'The label for the node_assign_owner_action action does not appear on the actions administration page after deleting.');
|
Chris@0
|
79
|
Chris@0
|
80 $action = Action::load($aid);
|
Chris@0
|
81 $this->assertFalse($action, 'The node_assign_owner_action action is not available after being deleted.');
|
Chris@0
|
82 }
|
Chris@0
|
83
|
Chris@0
|
84 }
|