You are here

public function OAuth2LoginTestCase::setUp in OAuth2 Login 8

Same name and namespace in other branches
  1. 7.2 tests/oauth2_login.test \OAuth2LoginTestCase::setUp()
  2. 7 tests/oauth2_login.test \OAuth2LoginTestCase::setUp()

File

tests/oauth2_login.test, line 22
OAuth2 Login tests.

Class

OAuth2LoginTestCase
Test OAuth2 Login.

Code

public function setUp() {
  parent::setUp([
    'oauth2_login',
    'oauth2_loginprovider',
  ]);

  // Create a test user.
  user_save('', [
    'name' => 'user1',
    'pass' => 'pass1',
    'status' => 1,
  ]);

  // Create an admin user and login.
  $admin = $this
    ->drupalCreateUser([
    'administer oauth2 server',
    'administer site configuration',
  ]);
  $this
    ->drupalLogin($admin);

  // On the server side create a client.
  $this
    ->drupalPost('admin/structure/oauth2-servers/manage/oauth2/clients/add', [
    'label' => 'Test client',
    'client_key' => 'client1',
    'client_secret' => 'secret1',
    'redirect_uri' => url('oauth2/authorized', [
      'absolute' => TRUE,
    ]),
    'automatic_authorization' => TRUE,
  ], 'Save client');

  // On the client side enable oauth2 login and set the settings.
  $this
    ->drupalPost('admin/config/people/oauth2_login', [
    'oauth2_login_enabled' => TRUE,
    'oauth2_login_oauth2_server' => $GLOBALS['base_url'],
    'oauth2_login_client_id' => 'client1',
    'oauth2_login_client_secret' => 'secret1',
    'oauth2_login_skipssl' => TRUE,
    'oauth2_login_proxy' => '',
  ], 'Save configuration');
  $this
    ->drupalLogout();
}