You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
2.4 KiB
82 lines
2.4 KiB
11 years ago
|
<?php
|
||
|
|
||
|
namespace yiiunit\extensions\authclient;
|
||
|
|
||
11 years ago
|
use yii\authclient\BaseClient;
|
||
11 years ago
|
|
||
11 years ago
|
class BaseClientTest extends TestCase
|
||
11 years ago
|
{
|
||
|
public function testSetGet()
|
||
|
{
|
||
11 years ago
|
$client = new Client();
|
||
11 years ago
|
|
||
|
$id = 'test_id';
|
||
11 years ago
|
$client->setId($id);
|
||
|
$this->assertEquals($id, $client->getId(), 'Unable to setup id!');
|
||
11 years ago
|
|
||
|
$name = 'test_name';
|
||
11 years ago
|
$client->setName($name);
|
||
|
$this->assertEquals($name, $client->getName(), 'Unable to setup name!');
|
||
11 years ago
|
|
||
|
$title = 'test_title';
|
||
11 years ago
|
$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!');
|
||
|
|
||
11 years ago
|
$normalizeUserAttributeMap = [
|
||
|
'name' => 'some/name',
|
||
|
'email' => 'some/email',
|
||
|
];
|
||
|
$client->setNormalizeUserAttributeMap($normalizeUserAttributeMap);
|
||
|
$this->assertEquals($normalizeUserAttributeMap, $client->getNormalizeUserAttributeMap(), 'Unable to setup normalize user attribute map!');
|
||
|
|
||
11 years ago
|
$viewOptions = [
|
||
|
'option1' => 'value1',
|
||
|
'option2' => 'value2',
|
||
|
];
|
||
|
$client->setViewOptions($viewOptions);
|
||
|
$this->assertEquals($viewOptions, $client->getViewOptions(), 'Unable to setup view options!');
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
public function testGetDefaults()
|
||
11 years ago
|
{
|
||
11 years ago
|
$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();
|
||
11 years ago
|
|
||
11 years ago
|
$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);
|
||
11 years ago
|
}
|
||
|
}
|
||
|
|
||
11 years ago
|
class Client extends BaseClient
|
||
11 years ago
|
{
|
||
|
}
|