Wip
This commit is contained in:
parent
f38f8db445
commit
660c85aa97
3 changed files with 97 additions and 0 deletions
36
tests/Browser/LoginTest.php
Normal file
36
tests/Browser/LoginTest.php
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Tests\Browser;
|
||||
|
||||
use Laravel\Dusk\Browser;
|
||||
use Pterodactyl\Models\User;
|
||||
use Pterodactyl\Tests\DuskTestCase;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Pterodactyl\Tests\Browser\Pages\Login;
|
||||
// use Pterodactyl\Tests\Traits\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
|
||||
class LoginTest extends DuskTestCase
|
||||
{
|
||||
use DatabaseMigrations;
|
||||
|
||||
/**
|
||||
* A Dusk test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLogin()
|
||||
{
|
||||
$login = 'testing@pterodactyl.io';
|
||||
$pass = 'password';
|
||||
|
||||
$user = User::factory()->create([
|
||||
'email' => $login,
|
||||
'password' => Hash::make($pass),
|
||||
]);
|
||||
|
||||
$this->browse(function (Browser $browser) use ($login, $pass) {
|
||||
$browser->visit(new Login())->loginToPanel($browser, $login, $pass);
|
||||
});
|
||||
}
|
||||
}
|
39
tests/Browser/Pages/Login.php
Normal file
39
tests/Browser/Pages/Login.php
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Tests\Browser\Pages;
|
||||
|
||||
use Laravel\Dusk\Browser;
|
||||
use Laravel\Dusk\Page;
|
||||
|
||||
class Login extends Page
|
||||
{
|
||||
/**
|
||||
* Get the URL for the page.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function url()
|
||||
{
|
||||
return '/auth/login';
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the browser is on the page.
|
||||
*
|
||||
* @param Browser $browser
|
||||
* @return void
|
||||
*/
|
||||
public function assert(Browser $browser)
|
||||
{
|
||||
$browser->assertPathIs($this->url());
|
||||
}
|
||||
|
||||
public function loginToPanel(Browser $browser, $username, $password)
|
||||
{
|
||||
$browser->type('username', $username);
|
||||
$browser->script("document.querySelector('input[name=username]').value = '$username'");
|
||||
$browser->type('password', $password);
|
||||
|
||||
$browser->clickAndWaitForReload('button[type=submit]', 2);
|
||||
}
|
||||
}
|
22
tests/Traits/DatabaseMigrations.php
Normal file
22
tests/Traits/DatabaseMigrations.php
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Tests\Traits;
|
||||
|
||||
use Illuminate\Contracts\Console\Kernel;
|
||||
use Illuminate\Foundation\Testing\Traits\CanConfigureMigrationCommands;
|
||||
|
||||
trait DatabaseMigrations
|
||||
{
|
||||
use CanConfigureMigrationCommands;
|
||||
|
||||
/**
|
||||
* Define hooks to migrate the database before and after each test.
|
||||
*
|
||||
*/
|
||||
public function runDatabaseMigrations(): void
|
||||
{
|
||||
$this->artisan('migrate:fresh', $this->migrateFreshUsing());
|
||||
|
||||
$this->app[Kernel::class]->setArtisan(null);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue