ConfigurationTest.php 3.56 KB
Newer Older
1 2
<?php

3
namespace Drupal\Tests\action\Functional;
4

5
use Drupal\system\Entity\Action;
6
use Drupal\Tests\BrowserTestBase;
7

8
/**
9 10 11 12
 * Tests complex actions configuration by adding, editing, and deleting a
 * complex action.
 *
 * @group action
13
 */
14
class ConfigurationTest extends BrowserTestBase {
15 16

  /**
17
   * Modules to install.
18 19 20
   *
   * @var array
   */
21
  public static $modules = ['action'];
22

23 24 25 26 27 28

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';

29
  /**
30
   * Tests configuration of advanced actions through administration interface.
31
   */
32
  public function testActionConfiguration() {
33
    // Create a user with permission to view the actions administration pages.
34
    $user = $this->drupalCreateUser(['administer actions']);
35 36
    $this->drupalLogin($user);

37
    // Make a POST request to admin/config/system/actions.
38
    $edit = [];
39
    $edit['action'] = 'action_goto_action';
40
    $this->drupalPostForm('admin/config/system/actions', $edit, t('Create'));
41
    $this->assertResponse(200);
42 43

    // Make a POST request to the individual action configuration page.
44
    $edit = [];
45
    $action_label = $this->randomMachineName();
46 47
    $edit['label'] = $action_label;
    $edit['id'] = strtolower($action_label);
48
    $edit['url'] = 'admin';
49
    $this->drupalPostForm('admin/config/system/actions/add/action_goto_action', $edit, t('Save'));
50
    $this->assertResponse(200);
51

52 53
    $action_id = $edit['id'];

54
    // Make sure that the new complex action was saved properly.
55 56
    $this->assertText(t('The action has been successfully saved.'), "Make sure we get a confirmation that we've successfully saved the complex action.");
    $this->assertText($action_label, "Make sure the action label appears on the configuration page after we've saved the complex action.");
57 58

    // Make another POST request to the action edit page.
59
    $this->clickLink(t('Configure'));
60

61
    $edit = [];
62
    $new_action_label = $this->randomMachineName();
63
    $edit['label'] = $new_action_label;
64
    $edit['url'] = 'admin';
65
    $this->drupalPostForm(NULL, $edit, t('Save'));
66
    $this->assertResponse(200);
67 68

    // Make sure that the action updated properly.
69 70 71
    $this->assertText(t('The action has been successfully saved.'), "Make sure we get a confirmation that we've successfully updated the complex action.");
    $this->assertNoText($action_label, "Make sure the old action label does NOT appear on the configuration page after we've updated the complex action.");
    $this->assertText($new_action_label, "Make sure the action label appears on the configuration page after we've updated the complex action.");
72

73 74 75 76
    $this->clickLink(t('Configure'));
    $element = $this->xpath('//input[@type="text" and @value="admin"]');
    $this->assertTrue(!empty($element), 'Make sure the URL appears when re-editing the action.');

77
    // Make sure that deletions work properly.
78 79 80
    $this->drupalGet('admin/config/system/actions');
    $this->clickLink(t('Delete'));
    $this->assertResponse(200);
81
    $edit = [];
82
    $this->drupalPostForm(NULL, $edit, t('Delete'));
83
    $this->assertResponse(200);
84 85

    // Make sure that the action was actually deleted.
86
    $this->assertRaw(t('The action %action has been deleted.', ['%action' => $new_action_label]), 'Make sure that we get a delete confirmation message.');
87
    $this->drupalGet('admin/config/system/actions');
88
    $this->assertResponse(200);
89
    $this->assertNoText($new_action_label, "Make sure the action label does not appear on the overview page after we've deleted the action.");
90

91
    $action = Action::load($action_id);
92
    $this->assertFalse($action, 'Make sure the action is gone after being deleted.');
93
  }
94

95
}