NodeActionsConfigurationTest.php 3.4 KB

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