View source
<?php
namespace Drupal\Tests\role_expire\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\role_expire\Traits\AssertRoleExpireTrait;
class UiRoleExpireTest extends BrowserTestBase {
use AssertRoleExpireTrait;
public static $modules = [
'role_expire',
];
protected $defaultTheme = 'stark';
public function testRoleExpireAdminPage() {
$account = $this
->drupalCreateUser([
'administer role expire',
]);
$this
->drupalLogin($account);
$this
->drupalGet('admin/config/people/role-expire');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('Role to assign after the role');
}
public function testRoleExpireEditUserFields() {
$account = $this
->drupalCreateUser([
'edit users role expire',
]);
$this
->drupalLogin($account);
$this
->drupalGet('user/' . $account
->id() . '/edit');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('role expiration date/time');
}
public function testRoleExpireEditRoleFields() {
$account = $this
->drupalCreateUser([
'administer permissions',
'edit role expire default duration',
]);
$this
->drupalLogin($account);
$this
->drupalGet('admin/people/roles/manage/anonymous');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('Default duration for the role');
}
public function testRoleExpireAdminPageAction() {
$account = $this
->drupalCreateUser([
'administer permissions',
'administer role expire',
]);
$this
->drupalLogin($account);
$this
->createRoleWithOptionalExpirationUI('test role', 'test_role');
$this
->createRoleWithOptionalExpirationUI('test role two', 'test_role_two');
$test_def = 'test_role_two';
$test_two_def = 'test_role';
$this
->drupalGet('admin/config/people/role-expire');
$this
->getSession()
->getPage()
->selectFieldOption('edit-test-role', $test_def);
$this
->getSession()
->getPage()
->selectFieldOption('edit-test-role-two', $test_two_def);
$this
->getSession()
->getPage()
->pressButton('Save configuration');
$this
->assertSession()
->statusCodeEquals(200);
$this
->drupalGet('admin/config/people/role-expire');
$this
->assertSession()
->statusCodeEquals(200);
$stored_value = $this
->getSession()
->getPage()
->findField('edit-test-role')
->getValue();
$this
->assertEquals($test_def, $stored_value);
$stored_value = $this
->getSession()
->getPage()
->findField('edit-test-role-two')
->getValue();
$this
->assertEquals($test_two_def, $stored_value);
}
public function testRoleExpireAdminPageActionDisable() {
$account = $this
->drupalCreateUser([
'administer permissions',
'administer role expire',
'edit users role expire',
]);
$this
->drupalLogin($account);
$this
->createRoleWithOptionalExpirationUI('test role', 'test_role');
$this
->createRoleWithOptionalExpirationUI('test role two', 'test_role_two');
$test_def = 1;
$test_two_def = 0;
$this
->drupalGet('admin/config/people/role-expire');
$this
->getSession()
->getPage()
->checkField('edit-disable-test-role');
$this
->getSession()
->getPage()
->uncheckField('edit-disable-test-role-two');
$this
->getSession()
->getPage()
->pressButton('Save configuration');
$this
->assertSession()
->statusCodeEquals(200);
$this
->drupalGet('admin/config/people/role-expire');
$this
->assertSession()
->statusCodeEquals(200);
$stored_value = $this
->getSession()
->getPage()
->findField('edit-disable-test-role')
->getValue();
$this
->assertEquals($test_def, $stored_value);
$stored_value = $this
->getSession()
->getPage()
->findField('edit-disable-test-role-two')
->getValue();
$this
->assertEquals($test_two_def, $stored_value);
$this
->drupalGet('user/' . $account
->id() . '/edit');
$this
->getSession()
->getPage()
->checkField('edit-roles-test-role');
$this
->getSession()
->getPage()
->checkField('edit-roles-test-role-two');
$this
->getSession()
->getPage()
->pressButton('Save');
$this
->drupalGet('user/' . $account
->id() . '/edit');
$this
->assertSession()
->pageTextNotContains('test role role expiration date/time');
$this
->assertSession()
->pageTextContains('test role two role expiration date/time');
}
public function testRoleExpireEditUserFieldsAction() {
$account = $this
->drupalCreateUser([
'administer permissions',
'edit users role expire',
]);
$this
->drupalLogin($account);
$value_to_store = '2 days';
$this
->createRoleWithOptionalExpirationUI('test role', 'test_role', $value_to_store);
$this
->drupalGet('user/' . $account
->id() . '/edit');
$this
->assertSession()
->statusCodeEquals(200);
$this
->getSession()
->getPage()
->checkField('edit-roles-test-role');
$this
->getSession()
->getPage()
->pressButton('Save');
$expected_date = date('Y-m-d', strtotime('2 days'));
$this
->drupalGet('user/' . $account
->id() . '/edit');
$stored_value = $this
->getSession()
->getPage()
->findField('edit-role-expire-test-role')
->getValue();
$stored_date = substr($stored_value, 0, 10);
$this
->assertEquals($expected_date, $stored_date);
$this
->assertSession()
->pageTextContains('role expiration date/time');
}
public function testRoleExpireEditRoleFieldsAction() {
$account = $this
->drupalCreateUser([
'administer permissions',
'edit role expire default duration',
]);
$this
->drupalLogin($account);
$value_to_store = '2 days';
$this
->createRoleWithOptionalExpirationUI('test role', 'test_role', $value_to_store);
$this
->drupalGet('admin/people/roles/manage/test_role');
$this
->assertSession()
->statusCodeEquals(200);
$stored_value = $this
->getSession()
->getPage()
->findField('Default duration for the role')
->getValue();
$this
->assertEquals($value_to_store, $stored_value);
}
}