UserTest.php in Social Auth 3.x
File
tests/src/Functional/UserTest.php
View source
<?php
namespace Drupal\Tests\social_auth\Functional;
use Drupal\Tests\BrowserTestBase;
class UserTest extends BrowserTestBase {
protected $defaultTheme = 'stark';
protected static $modules = [
'social_auth',
];
protected $user;
protected $userAuthenticator;
protected $entityTypeManager;
protected function setUp() : void {
parent::setUp();
$this->user = $this
->drupalCreateUser();
$this->userAuthenticator = \Drupal::getContainer()
->get('social_auth.user_authenticator');
$this->entityTypeManager = \Drupal::entityTypeManager();
}
public function testUserDeletion() {
$this
->drupalLogin($this->user);
$uid = $this->user
->id();
$this->userAuthenticator
->setPluginId('social_auth_provider1');
$this->userAuthenticator
->associateNewProvider('provider_id_123', 'token123', NULL);
$this->userAuthenticator
->setPluginId('social_auth_provider2');
$this->userAuthenticator
->associateNewProvider('provider_id_123', 'token123', NULL);
try {
$social_auth_storage = $this->entityTypeManager
->getStorage('social_auth');
$social_auth_users = $social_auth_storage
->loadByProperties([
'user_id' => $uid,
]);
$this
->assertEquals(2, count($social_auth_users), 'Number of associated providers should be 2');
$this->entityTypeManager
->getStorage('user')
->delete([
$this->user,
]);
$social_auth_users = $social_auth_storage
->loadByProperties([
'user_id' => $uid,
]);
$this
->assertEquals(0, count($social_auth_users), 'Number of associated providers should be 0');
} catch (\Exception $e) {
$this
->fail($e
->getMessage());
}
}
}
Classes
Name |
Description |
UserTest |
Tests Social Auth user related tasks. |