You are here

public function SocialApiTestBase::checkPermissionForSettingsPage in Social API 3.x

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/SocialApiTestBase.php \Drupal\Tests\social_api\Functional\SocialApiTestBase::checkPermissionForSettingsPage()

Test for configuration page.

Throws

\Behat\Mink\Exception\ElementNotFoundException

\Behat\Mink\Exception\ExpectationException

File

tests/src/Functional/SocialApiTestBase.php, line 122

Class

SocialApiTestBase
Defines a base class for testing Social Auth implementers.

Namespace

Drupal\Tests\social_api\Functional

Code

public function checkPermissionForSettingsPage() {
  $assert = $this
    ->assertSession();

  // Verifies that permissions are applied to the defined paths.
  $forbidden_paths = [
    '/admin/config/social-api/' . $this->moduleType . '/' . $this->provider,
  ];

  // Checks each of the paths to make sure we don't have access. At this point
  // we haven't logged in any users, so the client is anonymous.
  foreach ($forbidden_paths as $path) {
    $this
      ->drupalGet($path);
    $assert
      ->statusCodeEquals(403);
  }

  // Logs in user with no permissions.
  $this
    ->drupalLogin($this->noPermsUser);

  // Should be the same result for forbidden paths, since the user needs
  // special permissions for these paths.
  foreach ($forbidden_paths as $path) {
    $this
      ->drupalGet($path);
    $assert
      ->statusCodeEquals(403);
  }

  // Logs in user with permissions.
  $this
    ->drupalLogin($this->adminUser);

  // Forbidden paths aren't forbidden any more.
  foreach ($forbidden_paths as $unforbidden) {
    $this
      ->drupalGet($unforbidden);
    $assert
      ->statusCodeEquals(200);
  }

  // Now that we have the admin user logged in, check the menu links.
  $this
    ->drupalGet('/admin/config/social-api/' . $this->moduleType . '/' . $this->provider);
  foreach ($this->fields as $field) {
    $assert
      ->fieldExists($field);
  }
}