You are here

trait LoginAdminTrait in Paragraphs 8

Test trait for logging admin in JS tests.

Hierarchy

1 file declares its use of LoginAdminTrait
ParagraphsLibraryItemTranslationTest.php in modules/paragraphs_library/tests/src/Functional/ParagraphsLibraryItemTranslationTest.php

File

tests/src/FunctionalJavascript/LoginAdminTrait.php, line 8

Namespace

Drupal\Tests\paragraphs\FunctionalJavascript
View source
trait LoginAdminTrait {

  /**
   * Creates an user with admin permissions and log in.
   *
   * @param array $additional_permissions
   *   Additional permissions that will be granted to admin user.
   * @param bool $reset_permissions
   *   Flag to determine if default admin permissions will be replaced by
   *   $additional_permissions.
   *
   * @return object
   *   Newly created and logged in user object.
   */
  public function loginAsAdmin($additional_permissions = [], $reset_permissions = FALSE) {
    $permissions = [
      'administer content types',
      'administer node fields',
      'administer paragraphs types',
      'administer node form display',
      'administer paragraph fields',
      'administer paragraph form display',
    ];
    if ($reset_permissions) {
      $permissions = $additional_permissions;
    }
    elseif (!empty($additional_permissions)) {
      $permissions = array_merge($permissions, $additional_permissions);
    }
    $this->admin_user = $this
      ->drupalCreateUser($permissions);
    $this
      ->drupalLogin($this->admin_user);
    return $this->admin_user;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LoginAdminTrait::loginAsAdmin public function Creates an user with admin permissions and log in.