LoginHistoryTest.php in Login History 8
File
tests/src/Functional/LoginHistoryTest.php
View source
<?php
namespace Drupal\Tests\login_history\Functional;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Tests\BrowserTestBase;
class LoginHistoryTest extends BrowserTestBase {
use StringTranslationTrait;
public static $modules = [
'block',
'login_history',
];
protected $profile = 'minimal';
protected $adminUser;
protected $authenticatedUser;
protected $defaultTheme = 'stark';
protected function setUp() {
parent::setUp();
$this->adminUser = $this
->drupalCreateUser([
'access site reports',
'access administration pages',
'administer blocks',
'view all login histories',
'view own login history',
]);
$this
->drupalLogin($this->adminUser);
$this
->drupalPlaceBlock('last_login_block');
$this
->drupalLogout();
$this->authenticatedUser = $this
->drupalCreateUser([]);
}
public function testLoginHistory() {
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('admin/reports/login-history');
$this
->assertResponse(200);
$this
->assertText('Date');
$this
->assertText('Username');
$this
->assertText('IP Address');
$this
->assertText('One-time login?');
$this
->assertText('User Agent');
$this
->drupalGet('<front>');
$this
->assertText('You last logged in from');
$this
->clickLink($this
->t('View your login history'));
$this
->drupalGet('user/' . $this->adminUser
->id() . '/login-history');
$this
->assertResponse(200);
$this
->drupalLogout();
$this
->drupalLogin($this->authenticatedUser);
$this
->drupalGet('admin/reports/login-history');
$this
->assertSession()
->statusCodeNotEquals(200);
$this
->drupalGet('<front>');
$this
->assertNoText('You last logged in from');
$this
->drupalGet('user/' . $this->authenticatedUser
->id() . '/login-history');
$this
->assertResponse(403);
$this
->drupalLogout();
}
}