misc_pterodactyl-panel/tests/Browser/Processes/Authentication/LoginProcessTest.php

84 lines
2.6 KiB
PHP
Raw Normal View History

2018-06-01 05:42:52 +00:00
<?php
namespace Pterodactyl\Tests\Browser\Processes\Authentication;
use Facebook\WebDriver\WebDriverKeys;
use Pterodactyl\Tests\Browser\BrowserTestCase;
use Pterodactyl\Tests\Browser\Pages\LoginPage;
use Pterodactyl\Tests\Browser\PterodactylBrowser;
class LoginProcessTest extends BrowserTestCase
{
private $user;
/**
* Setup tests.
*/
protected function setUp(): void
2018-06-01 05:42:52 +00:00
{
parent::setUp();
$this->user = $this->user();
2018-06-01 05:42:52 +00:00
}
/**
* Test that a user can login successfully using their email address.
*/
public function testLoginUsingEmail()
{
$this->browse(function (PterodactylBrowser $browser) {
2021-01-23 20:33:34 +00:00
$browser->visit(new LoginPage())
2018-06-01 05:42:52 +00:00
->waitFor('@username')
->type('@username', $this->user->email)
->type('@password', self::$userPassword)
2018-06-01 05:42:52 +00:00
->click('@loginButton')
->waitForReload()
->assertPathIs('/')
->assertAuthenticatedAs($this->user);
});
}
/**
* Test that a user can login successfully using their username.
*/
public function testLoginUsingUsername()
{
$this->browse(function (PterodactylBrowser $browser) {
2021-01-23 20:33:34 +00:00
$browser->visit(new LoginPage())
2018-06-01 05:42:52 +00:00
->waitFor('@username')
->type('@username', $this->user->username)
->type('@password', self::$userPassword)
2018-06-01 05:42:52 +00:00
->click('@loginButton')
->waitForReload()
->assertPathIs('/')
->assertAuthenticatedAs($this->user);
});
}
/**
* Test that entering the wrong password shows the expected error and then allows
* us to login without clearing the username field.
*/
public function testLoginWithErrors()
{
$this->browse(function (PterodactylBrowser $browser) {
$browser->logout()
->visit(new LoginPage())
->waitFor('@username')
->type('@username', $this->user->email)
2018-06-01 05:42:52 +00:00
->type('@password', 'invalid')
->click('@loginButton')
->waitFor('.alert.error')
->assertSeeIn('.alert.error', trans('auth.failed'))
->assertValue('@username', $this->user->email)
2018-06-01 05:42:52 +00:00
->assertValue('@password', '')
->assertFocused('@password')
->type('@password', self::$userPassword)
2018-06-01 05:42:52 +00:00
->keys('@password', [WebDriverKeys::ENTER])
->waitForReload()
->assertPathIs('/')
->assertAuthenticatedAs($this->user);
});
}
}