InactiveDeleteTest.php in Auto Purge Users 8.3
File
tests/src/Functional/InactiveDeleteTest.php
View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\purge_users\Functional;
class InactiveDeleteTest extends SettingsBase {
public function setUp() : void {
parent::setUp();
$this->userStorage = $this->container
->get('entity_type.manager')
->getStorage('user');
$this
->addAdminUser();
$this
->createTestUser();
$this
->setBasicConfig();
$this
->config('purge_users.settings')
->set('user_inactive_value', '1')
->set('user_inactive_period', 'year')
->set('enabled_inactive_users', TRUE)
->save();
}
protected function checkConfirmFormResults() : void {
$this
->checkTestResults();
}
protected function checkCronResults() : void {
$this
->checkTestResults();
}
protected function checkTestResults() : void {
$account = $this->userStorage
->load($this->admin
->id());
$this
->assertNotNull($account);
$account = $this->userStorage
->load($this->blockedUser
->id());
$this
->assertNotNull($account);
$account = $this->userStorage
->load($this->blockedUserToDelete
->id());
$this
->assertNull($account);
$account = $this->userStorage
->load($this->activeUser
->id());
$this
->assertNotNull($account);
}
protected function createTestUser() : void {
$this->blockedUser = $this
->createUser([], NULL, FALSE, [
'created' => strtotime('-6 days'),
'login' => 0,
]);
$this->blockedUser->status = 0;
$this->blockedUser
->save();
$this->blockedUserToDelete = $this
->createUser([], NULL, FALSE, [
'created' => strtotime('-3 year'),
'login' => 0,
]);
$this->blockedUserToDelete->status = 0;
$this->blockedUserToDelete
->save();
$this->activeUser = $this
->createUser([], NULL, FALSE, [
'created' => strtotime('20 month'),
'login' => strtotime('-3 day'),
]);
}
}