You are here

oauth2_login.test in OAuth2 Login 7.2

Same filename and directory in other branches
  1. 8 tests/oauth2_login.test
  2. 7 tests/oauth2_login.test

OAuth2 Login tests.

File

tests/oauth2_login.test
View source
<?php

/**
 * @file
 * OAuth2 Login tests.
 */

/**
 * Test OAuth2 Login.
 */
class OAuth2LoginTestCase extends DrupalWebTestCase {
  protected $profile = 'testing';
  public static function getInfo() {
    return [
      'name' => 'OAuth2 Login',
      'description' => 'Tests OAuth2 Login.',
      'group' => 'OAuth2',
    ];
  }
  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();
  }
  public function testOAuth2Login() {
    $this
      ->drupalGet('');
    $this
      ->assertLinkByHref('user/oauth2_login', 0, 'There is a user/oauth2_login link on the home page.');

    //$this->clickLink(t('Login'));
    $this
      ->drupalPost('user/oauth2_login', [
      'name' => 'user1',
      'pass' => 'pass1',
    ], 'Log in');
  }

}

Classes

Namesort descending Description
OAuth2LoginTestCase Test OAuth2 Login.