View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\purge_users\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\Traits\Core\CronRunTrait;
abstract class SettingsBase extends BrowserTestBase {
use CronRunTrait;
protected static $modules = [
'node',
'purge_users',
];
protected $defaultTheme = 'stark';
protected $admin;
protected $activeUser;
protected $blockedUser;
protected $blockedUserToDelete;
protected $neverLoggedUser;
protected $activeUserToDelete;
protected $activeUserToBlock;
protected $node;
protected $nodeStorage;
protected $userStorage;
protected function addAdminUser() : void {
$this->admin = $this
->createUser([
'administer site configuration',
'administer permissions',
'administer account settings',
'administer users',
], NULL, TRUE);
$this->admin
->save();
}
protected function setBasicConfig() : void {
$this
->config('purge_users.settings')
->set('enabled_inactive_users', FALSE)
->set('enabled_loggedin_users', FALSE)
->set('enabled_never_loggedin_users', FALSE)
->set('enabled_blocked_users', FALSE)
->set('purge_excluded_users_roles', [
'administrator',
])
->set('purge_included_users_roles', [
'authenticated',
])
->set('purge_user_cancel_method', 'user_cancel_delete')
->set('send_email_notification', FALSE)
->set('inactive_user_notify_subject', 'Dear user')
->set('inactive_user_notify_text', 'Dear User, Your account has been deleted due the website’s policy to automatically remove users who match certain criteria. If you have concerns regarding the deletion, please talk to the administrator of the website. Thank you')
->set('user_before_deletion_subject', 'Dear user')
->set('send_email_user_before_notification', FALSE)
->set('user_before_deletion_text', 'Dear User, Your account will be deleted soon due the website’s policy to automatically remove users who match certain criteria. If you have concerns regarding the deletion, please talk to the administrator of the website. Thank you')
->save();
}
public function testConfirmForm() : void {
$this
->drupalLogin($this->admin);
$this
->drupalGet('admin/people/purge-rule/confirm');
$this
->assertSession()
->statusCodeEquals(200);
$this
->submitForm([], 'Confirm');
$this
->assertSession()
->statusCodeEquals(200);
$this
->checkConfirmFormResults();
}
public function testCron() : void {
$this
->config('purge_users.settings')
->set('purge_on_cron', TRUE)
->save();
$this
->cronRun();
$this
->checkCronResults();
}
protected abstract function createTestUser() : void;
protected abstract function checkConfirmFormResults() : void;
protected abstract function checkCronResults() : void;
protected static function getDeletionExpectedEmail() : array {
return [
'id' => 'purge_users_delete_users',
'module' => 'purge_users',
'key' => 'delete_users',
'to' => 'testemail@test.test',
'from' => 'simpletest@example.com',
'reply-to' => NULL,
'langcode' => 'en',
'params' => [
'subject' => 'Dear user',
'body' => 'Dear User, Your account has been deleted due the website’s policy to automatically remove users who match certain criteria. If you have concerns regarding the deletion, please talk to the administrator of the website. Thank you',
],
'send' => TRUE,
'subject' => 'Dear user',
'body' => "Dear User, Your account has been deleted due the website’s policy to\nautomatically remove users who match certain criteria. If you have concerns\nregarding the deletion, please talk to the administrator of the website.\nThank you\n",
'headers' => [
'MIME-Version' => '1.0',
'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
'X-Mailer' => 'Drupal',
'Return-Path' => 'simpletest@example.com',
'Sender' => 'simpletest@example.com',
'From' => 'Drupal <simpletest@example.com>',
'Content-Transfer-Encoding' => '8Bit',
],
];
}
protected static function getCancellationExpectedEmail() : array {
return [
'id' => 'purge_users_cancel_users',
'module' => 'purge_users',
'key' => 'cancel_users',
'to' => 'testemail@test.test',
'from' => 'simpletest@example.com',
'reply-to' => NULL,
'langcode' => 'en',
'params' => [
'subject' => 'Dear user',
'body' => 'Dear User, Your account will be deleted soon due the website’s policy to automatically remove users who match certain criteria. If you have concerns regarding the deletion, please talk to the administrator of the website. Thank you',
],
'send' => TRUE,
'subject' => 'Dear user',
'body' => "Dear User, Your account will be deleted soon due the website’s policy to\nautomatically remove users who match certain criteria. If you have concerns\nregarding the deletion, please talk to the administrator of the website.\nThank you\n",
'headers' => [
'MIME-Version' => '1.0',
'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
'X-Mailer' => 'Drupal',
'Return-Path' => 'simpletest@example.com',
'Sender' => 'simpletest@example.com',
'From' => 'Drupal <simpletest@example.com>',
'Content-Transfer-Encoding' => '8Bit',
],
];
}
}