You are here

public function OAuth2LoginTestCase::setUp in OAuth2 Login 7

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

Sets up a Drupal site for running functional and integration tests.

Generates a random database prefix and installs Drupal with the specified installation profile in DrupalWebTestCase::$profile into the prefixed database. Afterwards, installs any additional modules specified by the test.

After installation all caches are flushed and several configuration values are reset to the values of the parent site executing the test, since the default values may be incompatible with the environment in which tests are being executed.

Parameters

...: List of modules to enable for the duration of the test. This can be either a single array or a variable number of string arguments.

Overrides DrupalWebTestCase::setUp

See also

DrupalWebTestCase::prepareDatabasePrefix()

DrupalWebTestCase::changeDatabasePrefix()

DrupalWebTestCase::prepareEnvironment()

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();
}