3 namespace Drupal\Tests\node\Functional;
5 use Drupal\Component\Utility\Crypt;
6 use Drupal\Tests\BrowserTestBase;
7 use Drupal\system\Entity\Action;
10 * Tests configuration of actions provided by the Node module.
14 class NodeActionsConfigurationTest extends BrowserTestBase {
21 public static $modules = ['action', 'node'];
24 * Tests configuration of the node_assign_owner_action action.
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);
31 // Make a POST request to admin/config/system/actions.
33 $edit['action'] = Crypt::hashBase64('node_assign_owner_action');
34 $this->drupalPostForm('admin/config/system/actions', $edit, t('Create'));
35 $this->assertResponse(200);
37 // Make a POST request to the individual action configuration page.
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);
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.');
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);
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);
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.');
66 // Make sure that deletions work properly.
67 $this->drupalGet('admin/config/system/actions');
68 $this->clickLink(t('Delete'));
69 $this->assertResponse(200);
71 $this->drupalPostForm("admin/config/system/actions/configure/$aid/delete", $edit, t('Delete'));
72 $this->assertResponse(200);
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.');
80 $action = Action::load($aid);
81 $this->assertFalse($action, 'The node_assign_owner_action action is not available after being deleted.');