BaseClientTest.php 2.41 KB
Newer Older
1 2 3 4
<?php

namespace yiiunit\extensions\authclient;

5
use yii\authclient\BaseClient;
6

7
class BaseClientTest extends TestCase
8 9 10
{
	public function testSetGet()
	{
11
		$client = new Client();
12 13

		$id = 'test_id';
14 15
		$client->setId($id);
		$this->assertEquals($id, $client->getId(), 'Unable to setup id!');
16 17

		$name = 'test_name';
18 19
		$client->setName($name);
		$this->assertEquals($name, $client->getName(), 'Unable to setup name!');
20 21

		$title = 'test_title';
22 23 24 25 26 27 28 29 30 31
		$client->setTitle($title);
		$this->assertEquals($title, $client->getTitle(), 'Unable to setup title!');

		$userAttributes = [
			'attribute1' => 'value1',
			'attribute2' => 'value2',
		];
		$client->setUserAttributes($userAttributes);
		$this->assertEquals($userAttributes, $client->getUserAttributes(), 'Unable to setup user attributes!');

32 33 34 35 36 37 38
		$normalizeUserAttributeMap = [
			'name' => 'some/name',
			'email' => 'some/email',
		];
		$client->setNormalizeUserAttributeMap($normalizeUserAttributeMap);
		$this->assertEquals($normalizeUserAttributeMap, $client->getNormalizeUserAttributeMap(), 'Unable to setup normalize user attribute map!');

39 40 41 42 43 44
		$viewOptions = [
			'option1' => 'value1',
			'option2' => 'value2',
		];
		$client->setViewOptions($viewOptions);
		$this->assertEquals($viewOptions, $client->getViewOptions(), 'Unable to setup view options!');
45 46
	}

47
	public function testGetDefaults()
48
	{
49 50 51 52 53 54 55 56 57 58 59 60 61 62
		$client = new Client();

		$this->assertNotEmpty($client->getName(), 'Unable to get default name!');
		$this->assertNotEmpty($client->getTitle(), 'Unable to get default title!');
		$this->assertNotNull($client->getViewOptions(), 'Unable to get default view options!');
		$this->assertNotNull($client->getNormalizeUserAttributeMap(), 'Unable to get default normalize user attribute map!');
	}

	/**
	 * @depends testSetGet
	 */
	public function testNormalizeUserAttributes()
	{
		$client = new Client();
63

64 65 66 67 68 69 70 71 72 73 74 75 76
		$normalizeUserAttributeMap = [
			'raw/name' => 'name',
			'raw/email' => 'email',
		];
		$client->setNormalizeUserAttributeMap($normalizeUserAttributeMap);
		$rawUserAttributes = [
			'raw/name' => 'name value',
			'raw/email' => 'email value',
		];
		$client->setUserAttributes($rawUserAttributes);
		$normalizedUserAttributes = $client->getUserAttributes();
		$expectedNormalizedUserAttributes = array_combine(array_keys($normalizeUserAttributeMap), array_values($rawUserAttributes));
		$this->assertEquals($expectedNormalizedUserAttributes, $normalizedUserAttributes);
77 78 79
	}
}

80
class Client extends BaseClient
81 82
{
}