CollectionTest.php 1.84 KB
Newer Older
1 2 3 4 5
<?php

namespace yiiunit\extensions\authclient;

use yii\authclient\Collection;
6
use yii\authclient\BaseClient;
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
use yiiunit\extensions\authclient\TestCase;

class CollectionTest extends TestCase
{
	// Tests :

	public function testSetGet()
	{
		$collection = new Collection();

		$clients = [
			'testClient1' => new TestClient(),
			'testClient2' => new TestClient(),
		];
		$collection->setClients($clients);
		$this->assertEquals($clients, $collection->getClients(), 'Unable to setup clients!');
	}

	/**
	 * @depends testSetGet
	 */
	public function testGetProviderById()
	{
		$collection = new Collection();

		$clientId = 'testClientId';
		$client = new TestClient();
		$clients = [
			$clientId => $client
		];
		$collection->setClients($clients);

		$this->assertEquals($client, $collection->getClient($clientId), 'Unable to get client by id!');
	}

	/**
	 * @depends testGetProviderById
	 */
	public function testCreateProvider()
	{
		$collection = new Collection();

		$clientId = 'testClientId';
		$clientClassName = TestClient::className();
		$clients = [
			$clientId => [
				'class' => $clientClassName
			]
		];
		$collection->setClients($clients);

		$provider = $collection->getClient($clientId);
		$this->assertTrue(is_object($provider), 'Unable to create client by config!');
		$this->assertTrue(is_a($provider, $clientClassName), 'Client has wrong class name!');
	}

	/**
	 * @depends testSetGet
	 */
	public function testHasProvider()
	{
		$collection = new Collection();

		$clientName = 'testClientName';
		$clients = [
			$clientName => [
				'class' => 'TestClient1'
			],
		];
		$collection->setClients($clients);

		$this->assertTrue($collection->hasClient($clientName), 'Existing client check fails!');
		$this->assertFalse($collection->hasClient('unExistingClientName'), 'Not existing client check fails!');
	}
}

83
class TestClient extends BaseClient
84 85
{
}