You are here

public function OAuth2ServerStorageTest::setUp in OAuth2 Server 8

Same name and namespace in other branches
  1. 2.0.x tests/src/Functional/OAuth2ServerStorageTest.php \Drupal\Tests\oauth2_server\Functional\OAuth2ServerStorageTest::setUp()

Overrides BrowserTestBase::setUp

File

tests/src/Functional/OAuth2ServerStorageTest.php, line 62

Class

OAuth2ServerStorageTest
The OAuth2 Server admin test case.

Namespace

Drupal\Tests\oauth2_server\Functional

Code

public function setUp() {
  parent::setUp();
  $this->redirectUri = $this
    ->buildUrl('authorized', [
    'absolute' => TRUE,
  ]);

  /** @var \Drupal\oauth2_server\ServerInterface $server */
  $server = $this->container
    ->get('entity_type.manager')
    ->getStorage('oauth2_server')
    ->create([
    'server_id' => 'test_server',
    'name' => 'Test Server',
    'settings' => [
      'default_scope' => '',
      'allow_implicit' => TRUE,
      'grant_types' => [
        'authorization_code' => 'authorization_code',
        'client_credentials' => 'client_credentials',
        'refresh_token' => 'refresh_token',
        'password' => 'password',
      ],
      'always_issue_new_refresh_token' => TRUE,
      'advanced_settings' => [
        'require_exact_redirect_uri' => TRUE,
      ],
    ],
  ]);
  $server
    ->save();

  /** @var \Drupal\oauth2_server\ClientInterface $client */
  $this->client = $this->container
    ->get('entity_type.manager')
    ->getStorage('oauth2_server_client')
    ->create([
    'client_id' => $this->clientId,
    'server_id' => $server
      ->id(),
    'name' => 'Test client',
    'unhashed_client_secret' => $this->clientSecret,
    'redirect_uri' => $this->redirectUri,
    'automatic_authorization' => TRUE,
  ]);
  $this->client
    ->save();
  $this->storage = $this->container
    ->get('oauth2_server.storage');
}