function NodeActionsConfigurationTest::testAssignOwnerNodeActionConfiguration

Same name in other branches
  1. 9 core/modules/node/tests/src/Functional/NodeActionsConfigurationTest.php \Drupal\Tests\node\Functional\NodeActionsConfigurationTest::testAssignOwnerNodeActionConfiguration()
  2. 8.9.x core/modules/node/tests/src/Functional/NodeActionsConfigurationTest.php \Drupal\Tests\node\Functional\NodeActionsConfigurationTest::testAssignOwnerNodeActionConfiguration()
  3. 11.x core/modules/action/tests/src/Functional/Node/NodeActionsConfigurationTest.php \Drupal\Tests\action\Functional\Node\NodeActionsConfigurationTest::testAssignOwnerNodeActionConfiguration()

Tests configuration of the node_assign_owner_action action.

File

core/modules/action/tests/src/Functional/Node/NodeActionsConfigurationTest.php, line 35

Class

NodeActionsConfigurationTest
Tests configuration of actions provided by the Node module.

Namespace

Drupal\Tests\action\Functional\Node

Code

public function testAssignOwnerNodeActionConfiguration() : void {
    // Create a user with permission to view the actions administration pages.
    $user = $this->drupalCreateUser([
        'administer actions',
    ]);
    $this->drupalLogin($user);
    // Make a POST request to admin/config/system/actions.
    $edit = [];
    $edit['action'] = 'node_assign_owner_action';
    $this->drupalGet('admin/config/system/actions');
    $this->submitForm($edit, 'Create');
    $this->assertSession()
        ->statusCodeEquals(200);
    // Make a POST request to the individual action configuration page.
    $edit = [];
    $action_label = $this->randomMachineName();
    $edit['label'] = $action_label;
    $edit['id'] = strtolower($action_label);
    $edit['owner_uid'] = $user->id();
    $this->drupalGet('admin/config/system/actions/add/node_assign_owner_action');
    $this->submitForm($edit, 'Save');
    $this->assertSession()
        ->statusCodeEquals(200);
    $action_id = $edit['id'];
    $action_configure = sprintf('/admin/config/system/actions/configure/%s', $action_id);
    $action_delete = sprintf('/admin/config/system/actions/configure/%s/delete', $action_id);
    // Make sure that the new action was saved properly.
    $this->assertSession()
        ->pageTextContains('The action has been successfully saved.');
    // Check that the label of the node_assign_owner_action action appears on
    // the actions administration page after saving.
    $this->assertSession()
        ->pageTextContains($action_label);
    // Make another POST request to the action edit page.
    $this->assertSession()
        ->linkByHrefExists($action_configure);
    $this->drupalGet($action_configure);
    $edit = [];
    $new_action_label = $this->randomMachineName();
    $edit['label'] = $new_action_label;
    $edit['owner_uid'] = $user->id();
    $this->submitForm($edit, 'Save');
    $this->assertSession()
        ->statusCodeEquals(200);
    // Make sure that the action updated properly.
    $this->assertSession()
        ->pageTextContains('The action has been successfully saved.');
    // Check that the old label for the node_assign_owner_action action does not
    // appear on the actions administration page after updating.
    $this->assertSession()
        ->pageTextNotContains($action_label);
    // Check that the new label for the node_assign_owner_action action appears
    // on the actions administration page after updating.
    $this->assertSession()
        ->pageTextContains($new_action_label);
    // Make sure that deletions work properly.
    $this->drupalGet('admin/config/system/actions');
    $this->assertSession()
        ->linkByHrefExists($action_delete);
    $this->drupalGet($action_delete);
    $this->assertSession()
        ->statusCodeEquals(200);
    $edit = [];
    $this->submitForm($edit, 'Delete');
    $this->assertSession()
        ->statusCodeEquals(200);
    // Make sure that the action was actually deleted.
    $this->assertSession()
        ->pageTextContains("The action {$new_action_label} has been deleted.");
    $this->drupalGet('admin/config/system/actions');
    $this->assertSession()
        ->statusCodeEquals(200);
    // Check that the label for the node_assign_owner_action action does not
    // appear on the actions administration page after deleting.
    $this->assertSession()
        ->pageTextNotContains($new_action_label);
    $action = Action::load($action_id);
    $this->assertNull($action, 'The node_assign_owner_action action is not available after being deleted.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.