OAuth2Test.php 1012 Bytes
Newer Older
1 2 3 4
<?php

namespace yiiunit\extensions\authclient\oauth;

5
use yii\authclient\OAuth2;
6 7
use yiiunit\extensions\authclient\TestCase;

8
class OAuth2Test extends TestCase
9 10 11
{
	protected function setUp()
	{
Qiang Xue committed
12 13 14 15 16 17 18 19 20
		$config = [
			'components' => [
				'request' => [
					'hostInfo' => 'http://testdomain.com',
					'scriptUrl' => '/index.php',
				],
			]
		];
		$this->mockApplication($config, '\yii\web\Application');
21 22 23 24 25 26
	}

	// Tests :

	public function testBuildAuthUrl()
	{
27
		$oauthClient = new OAuth2();
28 29 30 31 32 33 34 35 36 37 38 39 40
		$authUrl = 'http://test.auth.url';
		$oauthClient->authUrl = $authUrl;
		$clientId = 'test_client_id';
		$oauthClient->clientId = $clientId;
		$returnUrl = 'http://test.return.url';
		$oauthClient->setReturnUrl($returnUrl);

		$builtAuthUrl = $oauthClient->buildAuthUrl();

		$this->assertContains($authUrl, $builtAuthUrl, 'No auth URL present!');
		$this->assertContains($clientId, $builtAuthUrl, 'No client id present!');
		$this->assertContains(rawurlencode($returnUrl), $builtAuthUrl, 'No return URL present!');
	}
Qiang Xue committed
41
}