3 namespace Drupal\Tests\action\Functional;
5 use Drupal\system\Entity\Action;
6 use Drupal\Tests\BrowserTestBase;
9 * Tests complex actions configuration by adding, editing, and deleting a
14 class ConfigurationTest extends BrowserTestBase {
21 public static $modules = ['action'];
24 * Tests configuration of advanced actions through administration interface.
26 public function testActionConfiguration() {
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'] = 'action_goto_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['url'] = 'admin';
43 $this->drupalPostForm('admin/config/system/actions/add/action_goto_action', $edit, t('Save'));
44 $this->assertResponse(200);
46 $action_id = $edit['id'];
48 // Make sure that the new complex action was saved properly.
49 $this->assertText(t('The action has been successfully saved.'), "Make sure we get a confirmation that we've successfully saved the complex action.");
50 $this->assertText($action_label, "Make sure the action label appears on the configuration page after we've saved the complex action.");
52 // Make another POST request to the action edit page.
53 $this->clickLink(t('Configure'));
56 $new_action_label = $this->randomMachineName();
57 $edit['label'] = $new_action_label;
58 $edit['url'] = 'admin';
59 $this->drupalPostForm(NULL, $edit, t('Save'));
60 $this->assertResponse(200);
62 // Make sure that the action updated properly.
63 $this->assertText(t('The action has been successfully saved.'), "Make sure we get a confirmation that we've successfully updated the complex action.");
64 $this->assertNoText($action_label, "Make sure the old action label does NOT appear on the configuration page after we've updated the complex action.");
65 $this->assertText($new_action_label, "Make sure the action label appears on the configuration page after we've updated the complex action.");
67 $this->clickLink(t('Configure'));
68 $element = $this->xpath('//input[@type="text" and @value="admin"]');
69 $this->assertTrue(!empty($element), 'Make sure the URL appears when re-editing the action.');
71 // Make sure that deletions work properly.
72 $this->drupalGet('admin/config/system/actions');
73 $this->clickLink(t('Delete'));
74 $this->assertResponse(200);
76 $this->drupalPostForm(NULL, $edit, t('Delete'));
77 $this->assertResponse(200);
79 // Make sure that the action was actually deleted.
80 $this->assertRaw(t('The action %action has been deleted.', ['%action' => $new_action_label]), 'Make sure that we get a delete confirmation message.');
81 $this->drupalGet('admin/config/system/actions');
82 $this->assertResponse(200);
83 $this->assertNoText($new_action_label, "Make sure the action label does not appear on the overview page after we've deleted the action.");
85 $action = Action::load($action_id);
86 $this->assertFalse($action, 'Make sure the action is gone after being deleted.');