You are here

public function PermissionsTest::testUserPerms in Metatag 8

Confirm that the node form is affected for a limited-access user.

File

metatag_extended_perms/tests/src/Functional/PermissionsTest.php, line 148

Class

PermissionsTest
Verify the new permissions are added.

Namespace

Drupal\Tests\metatag_extended_perms\Functional

Code

public function testUserPerms() {

  // Split up the permissions into ones that will be granted and ones that
  // will not.
  $group_yes = 'basic';
  $group_no = 'advanced';

  // Work out a list of permissions to grant the user. These are base perms.
  $perms_yes = [
    'access administration pages',
    'access content',
    'administer meta tags',
    'administer nodes',
    'create page content',
  ];

  // Grant each of the "yes" tag's permissions.
  foreach ($this->permissions[$group_yes] as $tag_name => $tag_label) {
    $perms_yes[] = "access metatag {$group_yes}__{$tag_name}";
  }
  $this
    ->verbose($perms_yes);

  // Create a user account with the above permissions.
  $user = $this
    ->createUser($perms_yes);
  $this
    ->drupalLogin($user);

  // Load the node form.
  $this
    ->drupalGet('node/add/page');

  // Confirm that the site didn't throw a server error or something else.
  $session = $this
    ->assertSession();
  $session
    ->statusCodeEquals(200);

  // Look for each of the "yes" meta tags.
  foreach ($this->permissions[$group_yes] as $tag_name => $tag_label) {

    // Look for the checkbox.
    $session
      ->fieldExists("field_metatag[0][{$group_yes}][{$tag_name}]");
  }

  // Make sure each of the "no" meta tags is not present.
  foreach ($this->permissions[$group_no] as $tag_name => $tag_label) {

    // Look for the checkbox.
    $session
      ->fieldNotExists("field_metatag[0][{$group_no}][{$tag_name}]");
  }
}