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