public function OAuth2ServerTestCase::setUp in OAuth2 Server 7
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_server.test, line 84 - OAuth2 tests.
Class
- OAuth2ServerTestCase
- Test basic API.
Code
public function setUp() {
parent::setUp('oauth2_server', 'oauth2_server_test');
// Set the keys so that the module can see them.
$keys = array(
'public_key' => $this->public_key,
'private_key' => $this->private_key,
);
variable_set('oauth2_server_keys', $keys);
variable_set('oauth2_server_keys_last_generated', REQUEST_TIME);
// Create the server and client.
$server = entity_create('oauth2_server', array());
$server->name = 'test';
$server->label = 'Test';
$server->settings = array(
'default_scope' => 'basic',
'enforce_state' => TRUE,
'allow_implicit' => TRUE,
'use_openid_connect' => TRUE,
'use_crypto_tokens' => FALSE,
'store_encrypted_token_string' => FALSE,
'require_exact_redirect_uri' => TRUE,
'grant_types' => array(
'authorization_code' => 'authorization_code',
'client_credentials' => 'client_credentials',
'urn:ietf:params:oauth:grant-type:jwt-bearer' => 'urn:ietf:params:oauth:grant-type:jwt-bearer',
'refresh_token' => 'refresh_token',
'password' => 'password',
),
'always_issue_new_refresh_token' => TRUE,
'access_lifetime' => 3600,
'id_lifetime' => 3600,
'refresh_token_lifetime' => 1209600,
);
$server
->save();
$client = entity_create('oauth2_server_client', array());
$client->server = $server->name;
$client->label = 'Test client';
$client->client_key = $this->client_key;
$client->client_secret = oauth2_server_hash_client_secret($this->client_secret);
$client->public_key = $this->public_key;
// The module supports entering multiple redirect uris separated by a
// newline. Both a dummy and the real uri are specified to confirm that
// validation passes.
$client->redirect_uri = 'https://google.com' . "\n" . url('authorized', array(
'absolute' => TRUE,
));
$client->automatic_authorization = TRUE;
$client
->save();
$scopes = array(
'basic' => 'Basic',
'admin' => 'Admin',
'forbidden' => 'Forbidden',
'openid' => 'OpenID Connect',
'email' => 'email',
'phone' => 'phone',
'profile' => 'Profile',
'offline_access' => 'Offline Access',
);
foreach ($scopes as $scope_name => $scope_label) {
$scope = entity_create('oauth2_server_scope', array());
$scope->server = $server->name;
$scope->name = $scope_name;
$scope->description = '';
$scope
->save();
}
}