You are here

protected function AuthenticationOAuthTest::setUp in Entity Share 8.3

Overrides EntityShareClientFunctionalTestBase::setUp

File

modules/entity_share_client/tests/src/Functional/AuthenticationOAuthTest.php, line 81

Class

AuthenticationOAuthTest
Functional test class for import with "OAuth" authorization.

Namespace

Drupal\Tests\entity_share_client\Functional

Code

protected function setUp() : void {
  parent::setUp();
  $this->keyService = $this->container
    ->get('entity_share_client.key_provider');

  // Give admin user access to all channels (channel user already has it).
  foreach ($this->channels as $channel) {
    $authorized_users = $channel
      ->get('authorized_users');
    $authorized_users = array_merge($authorized_users, [
      $this->adminUser
        ->uuid(),
    ]);
    $channel
      ->set('authorized_users', $authorized_users);
    $channel
      ->save();
  }

  // Create Keys with users' credentials.
  $this
    ->createKey($this->adminUser);
  $this
    ->createKey($this->channelUser);
  $this->configFactory = $this->container
    ->get('config.factory');
  $simple_oauth_settings = $this->configFactory
    ->getEditable('simple_oauth.settings');
  $simple_oauth_settings
    ->set('access_token_expiration', 10);
  $simple_oauth_settings
    ->set('refresh_token_expiration', 30);
  $simple_oauth_settings
    ->save();

  // Change the initial remote configuration: it will use the admin user
  // to authenticate. We first test as administrative user because they have
  // access to all nodes, so we can in the beginning of the test pull the
  // channel and use `checkCreatedEntities()`.
  $plugin = $this
    ->createAuthenticationPlugin($this->adminUser, $this->remote);
  $this->remote
    ->mergePluginConfig($plugin);
  $this->remote
    ->save();
  $this
    ->postSetupFixture();
}