OpenIdTest.php 1.45 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
<?php

namespace yiiunit\extensions\authclient;

use yii\authclient\OpenId;

class OpenIdTest extends TestCase
{
	protected function setUp()
	{
		$config = [
			'components' => [
				'request' => [
					'hostInfo' => 'http://testdomain.com',
					'scriptUrl' => '/index.php',
				],
			]
		];
		$this->mockApplication($config, '\yii\web\Application');
	}

	// Tests :

	public function testSetGet()
	{
		$client = new OpenId();

		$trustRoot = 'http://trust.root';
		$client->setTrustRoot($trustRoot);
		$this->assertEquals($trustRoot, $client->getTrustRoot(), 'Unable to setup trust root!');

		$returnUrl = 'http://return.url';
		$client->setReturnUrl($returnUrl);
		$this->assertEquals($returnUrl, $client->getReturnUrl(), 'Unable to setup return URL!');
	}

	/**
	 * @depends testSetGet
	 */
	public function testGetDefaults()
	{
		$client = new OpenId();

		$this->assertNotEmpty($client->getTrustRoot(), 'Unable to get default trust root!');
		$this->assertNotEmpty($client->getReturnUrl(), 'Unable to get default return URL!');
	}
47 48 49 50 51 52 53 54

	public function testDiscover()
	{
		$url = 'https://www.google.com/accounts/o8/id';
		$client = new OpenId();
		$info = $client->discover($url);
		$this->assertNotEmpty($info);
		$this->assertNotEmpty($info['url']);
55
		$this->assertNotEmpty($info['identity']);
56
		$this->assertEquals(2, $info['version']);
57
		$this->assertArrayHasKey('identifier_select', $info);
58 59 60
		$this->assertArrayHasKey('ax', $info);
		$this->assertArrayHasKey('sreg', $info);
	}
61
}