You are here

function OAuthTest::testConsumers in OAuth 1.0 8.2

Same name and namespace in other branches
  1. 8 src/Tests/OAuthTest.php \Drupal\oauth\Tests\OAuthTest::testConsumers()

Tests consumer generation and deletion.

File

src/Tests/OAuthTest.php, line 29
Contains \Drupal\oauth\Tests\OAuthTest.

Class

OAuthTest
Tests oauth functionality.

Namespace

Drupal\oauth\Tests

Code

function testConsumers() {

  // Create a user with permissions to manage its own consumers.
  $permissions = array(
    'access own consumers',
  );
  $account = $this
    ->drupalCreateUser($permissions);

  // Initiate user session.
  $this
    ->drupalLogin($account);

  // Check that OAuth menu tab is visible at user profile.
  $this
    ->drupalGet('user/' . $account
    ->id() . '/oauth/consumer');
  $this
    ->assertResponse(200);

  // Generate a set of consumer keys.
  $this
    ->drupalPostForm('oauth/consumer/add/' . $account
    ->id(), array(), 'Add');
  $this
    ->assertText(t('Added a new consumer.'));

  // Delete the set of consumer keys.
  $user_data = \Drupal::service('user.data')
    ->get('oauth', $account
    ->id());
  $this
    ->drupalPostForm('oauth/consumer/delete/' . $account
    ->id() . '/' . key($user_data), array(), 'Delete');
  $this
    ->assertText(t('OAuth consumer deleted.'));
  $this
    ->drupalLogout();

  // Test administer consumer permissions
  $admin_account = $this
    ->drupalCreateUser(array(
    'administer consumers',
  ));
  $this
    ->drupalLogin($admin_account);
  $this
    ->drupalGet('user/' . $account
    ->id() . '/oauth/consumer');
  $this
    ->assertResponse(200);

  // Generate a set of consumer keys.
  $this
    ->drupalPostForm('oauth/consumer/add/' . $account
    ->id(), array(), 'Add');
  $this
    ->assertText(t('Added a new consumer.'));

  // Delete the set of consumer keys.
  $user_data = \Drupal::service('user.data')
    ->get('oauth', $account
    ->id());
  $this
    ->drupalPostForm('oauth/consumer/delete/' . $account
    ->id() . '/' . key($user_data), array(), 'Delete');
  $this
    ->assertText(t('OAuth consumer deleted.'));
  $this
    ->drupalLogout();
}