You are here

function OAuthTest::testConsumers in OAuth 1.0 8

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

Tests consumer generation and deletion.

File

src/Tests/OAuthTest.php, line 28
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', array(), 'Add');
  $this
    ->assertText(t('Added a new consumer.'));

  // Delete the set of consumer keys.
  $consumer = db_query('select * from {oauth_consumer} where uid = :uid', array(
    ':uid' => $account
      ->id(),
  ))
    ->fetchObject();
  $this
    ->drupalPostForm('oauth/consumer/delete/' . $consumer->cid, array(), 'Delete');
  $this
    ->assertText(t('OAuth consumer deleted.'));
  $this
    ->drupalLogout();
}