You are here

class OAuth2LoginTestCase in OAuth2 Login 8

Same name and namespace in other branches
  1. 7.2 tests/oauth2_login.test \OAuth2LoginTestCase
  2. 7 tests/oauth2_login.test \OAuth2LoginTestCase

Test OAuth2 Login.

Hierarchy

Expanded class hierarchy of OAuth2LoginTestCase

File

tests/oauth2_login.test, line 11
OAuth2 Login tests.

View source
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');
  }

}

Members