diff --git a/tests/Browser/BrowserTestCase.php b/tests/Browser/BrowserTestCase.php index 3548f9885..825978d3c 100644 --- a/tests/Browser/BrowserTestCase.php +++ b/tests/Browser/BrowserTestCase.php @@ -6,16 +6,16 @@ use Laravel\Dusk\TestCase; use BadMethodCallException; use Pterodactyl\Models\User; use Tests\CreatesApplication; +use Pterodactyl\Console\Kernel; use Illuminate\Support\Facades\Hash; use Illuminate\Database\Eloquent\Model; use Facebook\WebDriver\Chrome\ChromeOptions; use Facebook\WebDriver\Remote\RemoteWebDriver; use Facebook\WebDriver\Remote\DesiredCapabilities; -use Illuminate\Foundation\Testing\DatabaseMigrations; abstract class BrowserTestCase extends TestCase { - use CreatesApplication, DatabaseMigrations; + use CreatesApplication; /** * The default password to use for new accounts. @@ -24,6 +24,28 @@ abstract class BrowserTestCase extends TestCase */ protected static $userPassword = 'Password123'; + /** + * Create a fresh database instance before each test class is initialized. This is different + * than the default DatabaseMigrations as it is only run when the class is setup. The trait + * provided by Laravel will run on EACH test function, slowing things down significantly. + * + * If you need to reset the DB between function runs just include the trait in that specific + * test. In most cases you probably wont need to do this, or can modify the test slightly to + * avoid the need to do so. + */ + public static function setUpBeforeClass() + { + parent::setUpBeforeClass(); + + $app = require __DIR__ . '/../../bootstrap/app.php'; + + /** @var \Pterodactyl\Console\Kernel $kernel */ + $kernel = $app->make(Kernel::class); + + $kernel->bootstrap(); + $kernel->call('migrate:fresh'); + } + /** * Setup tests. */ diff --git a/tests/Browser/Processes/Authentication/LoginProcessTest.php b/tests/Browser/Processes/Authentication/LoginProcessTest.php index 1e0f8a0be..c6e58dd7a 100644 --- a/tests/Browser/Processes/Authentication/LoginProcessTest.php +++ b/tests/Browser/Processes/Authentication/LoginProcessTest.php @@ -2,8 +2,6 @@ namespace Pterodactyl\Tests\Browser\Processes\Authentication; -use Pterodactyl\Models\User; -use Illuminate\Support\Facades\Hash; use Facebook\WebDriver\WebDriverKeys; use Pterodactyl\Tests\Browser\BrowserTestCase; use Pterodactyl\Tests\Browser\Pages\LoginPage; @@ -20,10 +18,7 @@ class LoginProcessTest extends BrowserTestCase { parent::setUp(); - $this->user = factory(User::class)->create([ - 'email' => 'test@example.com', - 'password' => Hash::make('Password123'), - ]); + $this->user = $this->user(); } /** @@ -34,8 +29,8 @@ class LoginProcessTest extends BrowserTestCase $this->browse(function (PterodactylBrowser $browser) { $browser->visit(new LoginPage) ->waitFor('@username') - ->type('@username', 'test@example.com') - ->type('@password', 'Password123') + ->type('@username', $this->user->email) + ->type('@password', self::$userPassword) ->click('@loginButton') ->waitForReload() ->assertPathIs('/') @@ -52,7 +47,7 @@ class LoginProcessTest extends BrowserTestCase $browser->visit(new LoginPage) ->waitFor('@username') ->type('@username', $this->user->username) - ->type('@password', 'Password123') + ->type('@password', self::$userPassword) ->click('@loginButton') ->waitForReload() ->assertPathIs('/') @@ -70,15 +65,15 @@ class LoginProcessTest extends BrowserTestCase $browser->logout() ->visit(new LoginPage()) ->waitFor('@username') - ->type('@username', 'test@example.com') + ->type('@username', $this->user->email) ->type('@password', 'invalid') ->click('@loginButton') ->waitFor('.alert.error') ->assertSeeIn('.alert.error', trans('auth.failed')) - ->assertValue('@username', 'test@example.com') + ->assertValue('@username', $this->user->email) ->assertValue('@password', '') ->assertFocused('@password') - ->type('@password', 'Password123') + ->type('@password', self::$userPassword) ->keys('@password', [WebDriverKeys::ENTER]) ->waitForReload() ->assertPathIs('/')