You are here

protected function ModerationStateTestBase::grantUserPermissionToCreateContentOfType in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/content_moderation/tests/src/Functional/ModerationStateTestBase.php \Drupal\Tests\content_moderation\Functional\ModerationStateTestBase::grantUserPermissionToCreateContentOfType()

Grants given user permission to create content of given type.

Parameters

\Drupal\Core\Session\AccountInterface $account: User to grant permission to.

string $content_type_id: Content type ID.

7 calls to ModerationStateTestBase::grantUserPermissionToCreateContentOfType()
DefaultModerationStateTest::setUp in core/modules/content_moderation/tests/src/Functional/DefaultModerationStateTest.php
Sets the test up.
ModerationFormTest::setUp in core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php
Sets the test up.
ModerationFormTest::testModerationFormSetsRevisionAuthor in core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php
Tests the revision author is updated when the moderation form is used.
ModerationStateNodeTest::setUp in core/modules/content_moderation/tests/src/Functional/ModerationStateNodeTest.php
Sets the test up.
ModerationStateNodeTypeTest::testEnablingOnExistingContent in core/modules/content_moderation/tests/src/Functional/ModerationStateNodeTypeTest.php
Tests enabling moderation on an existing node-type, with content.

... See full list

File

core/modules/content_moderation/tests/src/Functional/ModerationStateTestBase.php, line 160

Class

ModerationStateTestBase
Defines a base class for moderation state tests.

Namespace

Drupal\Tests\content_moderation\Functional

Code

protected function grantUserPermissionToCreateContentOfType(AccountInterface $account, $content_type_id) {
  $role_ids = $account
    ->getRoles(TRUE);

  /** @var \Drupal\user\RoleInterface $role */
  $role_id = reset($role_ids);
  $role = Role::load($role_id);
  $role
    ->grantPermission(sprintf('create %s content', $content_type_id));
  $role
    ->grantPermission(sprintf('edit any %s content', $content_type_id));
  $role
    ->grantPermission(sprintf('delete any %s content', $content_type_id));
  $role
    ->save();
}