You are here

protected function AuthCodeFunctionalTest::setUp in Simple OAuth (OAuth2) & OpenID Connect 8.3

Same name and namespace in other branches
  1. 8.2 simple_oauth_extras/tests/src/Functional/AuthCodeFunctionalTest.php \Drupal\Tests\simple_oauth_extras\Functional\AuthCodeFunctionalTest::setUp()

Overrides TokenBearerFunctionalTestBase::setUp

File

simple_oauth_extras/tests/src/Functional/AuthCodeFunctionalTest.php, line 38

Class

AuthCodeFunctionalTest
@group simple_oauth_extras

Namespace

Drupal\Tests\simple_oauth_extras\Functional

Code

protected function setUp() {
  parent::setUp();
  $this->redirectUri = Url::fromRoute('oauth2_token_extras.test_token', [], [
    'absolute' => TRUE,
  ])
    ->toString();
  $this->client
    ->set('redirect', $this->redirectUri);
  $this->client
    ->set('description', $this
    ->getRandomGenerator()
    ->paragraphs());
  $this->client
    ->save();
  $this->authorizeUrl = Url::fromRoute('oauth2_token_extras.authorize');
  $this
    ->grantPermissions(Role::load(RoleInterface::AUTHENTICATED_ID), [
    'grant simple_oauth codes',
  ]);

  // Add a scope so we can ensure all tests have at least 2 roles. That way we
  // can test dropping a scope and still have at least one scope.
  $additional_scope = $this
    ->getRandomGenerator()
    ->name(8, TRUE);
  Role::create([
    'id' => $additional_scope,
    'label' => $this
      ->getRandomGenerator()
      ->word(5),
    'is_admin' => FALSE,
  ])
    ->save();
  $this->scope = $this->scope . ' ' . $additional_scope;

  // Add a random scope that is not in the base scopes list to request so we
  // can make extra checks on it.
  $this->extraRole = Role::create([
    'id' => $this
      ->getRandomGenerator()
      ->name(8, TRUE),
    'label' => $this
      ->getRandomGenerator()
      ->word(5),
    'is_admin' => FALSE,
  ]);
  $this->extraRole
    ->save();
}