ExternalAuthTest.php in External Authentication 8
File
tests/src/Kernel/ExternalAuthTest.php
View source
<?php
namespace Drupal\Tests\externalauth\Kernel;
use Drupal\KernelTests\KernelTestBase;
class ExternalAuthTest extends KernelTestBase {
public static $modules = [
'externalauth',
'system',
'user',
];
public function testRegisterDrupalUsername() {
$this
->installSchema('system', [
'sequences',
]);
$this
->installEntitySchema('user');
$this
->installSchema('user', [
'users_data',
]);
$this
->installSchema('externalauth', [
'authmap',
]);
$externalauth = $this->container
->get('externalauth.externalauth');
$authmap = $this->container
->get('externalauth.authmap');
$provider = 'arbitrary_provider';
$externalauth
->register('external_name', $provider);
$account = user_load_by_name("{$provider}_external_name");
$this
->assertNotFalse($account);
$this
->assertSame('external_name', $authmap
->get($account
->id(), $provider));
$account
->delete();
$externalauth
->register('external_name', $provider, [
'name' => 'enforced_name',
]);
$account = user_load_by_name('enforced_name');
$this
->assertNotFalse($account);
$this
->assertSame('external_name', $authmap
->get($account
->id(), $provider));
}
}