ForcePasswordChangeAdminUiTest.php in Force Password Change 2.0.x
File
tests/src/Functional/ForcePasswordChangeAdminUiTest.php
View source
<?php
namespace Drupal\Tests\force_password_change\Functional;
class ForcePasswordChangeAdminUiTest extends ForcePasswordChangeBrowserTestBase {
protected $defaultTheme = 'stark';
protected static $modules = [
'force_password_change',
];
public function testForcePasswordChangeAdminPage() {
$admin_user = $this
->drupalCreateUser([
'administer force password change',
'access administration pages',
]);
$this
->drupalLogin($admin_user);
$this
->drupalGet('admin/config');
$this
->assertStatusCodeEquals(200);
$this
->assertSession()
->pageTextContains('Force Password Change');
$this
->assertSession()
->pageTextContains('Settings related to forcing password changes');
$this
->clickLink('Force Password Change');
$this
->assertSession()
->addressMatches('/\\/admin\\/config\\/people\\/force_password_change$/');
$this
->assertStatusCodeEquals(200);
$this
->assertCheckboxExists('edit-first-time-login-password-change');
$this
->assertRadioExists('edit-login-only-0');
$this
->assertRadioExists('edit-login-only-1');
$this
->assertCheckboxExists('edit-roles-authenticated');
$this
->assertElementExistsXpath('//div[@id="edit-roles"]//label[@for="edit-roles-authenticated"]/text()[contains(., "Authenticated user (Users in role: 2 | Users with pending forced password change: 0 | ")]');
$this
->assertElementExistsXpath('//div[@id="edit-roles"]//label[@for="edit-roles-authenticated"]/a[@href="/admin/config/people/force_password_change/list/authenticated" and text()="Details"]');
$new_role = $this
->createRole([], 'admin', 'Admin');
$this
->drupalGet('admin/config/people/force_password_change');
$this
->assertSession()
->addressMatches('/\\/admin\\/config\\/people\\/force_password_change$/');
$this
->assertStatusCodeEquals(200);
$this
->assertCheckboxExists('edit-roles-admin');
$this
->assertElementExistsXpath('//div[@id="edit-roles"]//label[@for="edit-roles-admin"]/text()[contains(., "Admin (Users in role: 0 | Users with pending forced password change: 0 |")]');
$this
->assertElementExistsXpath('//div[@id="edit-roles"]//label[@for="edit-roles-admin"]/a[@href="/admin/config/people/force_password_change/list/admin" and text()="Details"]');
$admin_user
->addRole($new_role);
$admin_user
->save();
$this
->drupalGet('admin/config/people/force_password_change');
$this
->assertSession()
->addressMatches('/\\/admin\\/config\\/people\\/force_password_change$/');
$this
->assertStatusCodeEquals(200);
$this
->assertElementExistsXpath('//div[@id="edit-roles"]//label[@for="edit-roles-admin"]/text()[contains(., "Admin (Users in role: 1 | Users with pending forced password change: 0 |")]');
$this
->assertCheckboxExists('edit-expire-password');
$this
->assertElementExists('#force_password_change_role_expiry_table');
$this
->assertElementExistsXpath('//table[@id="force_password_change_role_expiry_table"]//tr[@data-drupal-selector="edit-table-authenticated"]//td/text()[contains(., "Authenticated user (Users in role: 2 | Users with pending forced password change: 0")]');
$this
->assertElementExistsXpath('//table[@id="force_password_change_role_expiry_table"]//tr[@data-drupal-selector="edit-table-authenticated"]//td/a[@href="/admin/config/people/force_password_change/list/authenticated" and text()="Details"]');
$this
->assertElementExistsXpath('//table[@id="force_password_change_role_expiry_table"]//tr[@data-drupal-selector="edit-table-admin"]//td/text()[contains(., "Admin (Users in role: 1 | Users with pending forced password change: 0")]');
$this
->assertElementExistsXpath('//table[@id="force_password_change_role_expiry_table"]//tr[@data-drupal-selector="edit-table-admin"]//td/a[@href="/admin/config/people/force_password_change/list/admin" and text()="Details"]');
$this
->assertElementExists('#edit-table-authenticated-time-time-quantity');
$this
->assertElementExists('#edit-table-authenticated-time-time-period');
$this
->assertElementExists('#edit-table-authenticated-weight');
$this
->assertElementExists('#edit-table-admin-time-time-quantity');
$this
->assertElementExists('#edit-table-admin-time-time-period');
$this
->assertElementExists('#edit-table-admin-weight');
$this
->assertElementExists('#edit-actions #edit-submit');
$this
->checkCheckbox('#edit-first-time-login-password-change');
$this
->selectRadio('#edit-login-only-1');
$this
->checkCheckbox('#edit-expire-password');
$this
->fillTextValue('#edit-table-authenticated-time-time-quantity', '3');
$this
->selectSelectOption('#edit-table-authenticated-time-time-period', 'hour');
$this
->selectSelectOption('#edit-table-authenticated-weight', '-1');
$this
->fillTextValue('#edit-table-admin-time-time-quantity', '5');
$this
->selectSelectOption('#edit-table-admin-time-time-period', 'week');
$this
->selectSelectOption('#edit-table-admin-weight', '-5');
$this
->click('#edit-submit');
$this
->assertCheckboxChecked('#edit-first-time-login-password-change');
$this
->assertRadioSelected('#edit-login-only-1');
$this
->assertCheckboxChecked('#edit-expire-password');
$this
->assertTextValue('#edit-table-authenticated-time-time-quantity', '3');
$this
->assertSelectOption('#edit-table-authenticated-time-time-period', 'hour');
$this
->assertSelectOption('#edit-table-authenticated-weight', '-1');
$this
->assertTextValue('#edit-table-admin-time-time-quantity', '5');
$this
->assertSelectOption('#edit-table-admin-time-time-period', 'week');
$this
->assertSelectOption('#edit-table-admin-weight', '-5');
}
}