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