public function UserTest::testUserDeletion in Social Auth 3.x
Same name and namespace in other branches
- 8.2 tests/src/Functional/UserTest.php \Drupal\Tests\social_auth\Functional\UserTest::testUserDeletion()
Tests the case when Drupal user is deleted.
When a Drupal user is removed, the associated Social Auth accounts should also be removed.
File
- tests/
src/ Functional/ UserTest.php, line 68
Class
- UserTest
- Tests Social Auth user related tasks.
Namespace
Drupal\Tests\social_auth\FunctionalCode
public function testUserDeletion() {
$this
->drupalLogin($this->user);
$uid = $this->user
->id();
// Associates a provider.
$this->userAuthenticator
->setPluginId('social_auth_provider1');
$this->userAuthenticator
->associateNewProvider('provider_id_123', 'token123', NULL);
// Associates another provider.
$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,
]);
// Expects that the user has two associated providers.
$this
->assertEquals(2, count($social_auth_users), 'Number of associated providers should be 2');
// Deletes the Drupal user.
$this->entityTypeManager
->getStorage('user')
->delete([
$this->user,
]);
$social_auth_users = $social_auth_storage
->loadByProperties([
'user_id' => $uid,
]);
// Expects that the user has no associated providers now.
$this
->assertEquals(0, count($social_auth_users), 'Number of associated providers should be 0');
} catch (\Exception $e) {
$this
->fail($e
->getMessage());
}
}