Correctly tear down tests and remove cookies

This commit is contained in:
Dane Everitt 2018-07-15 11:44:08 -07:00
parent 8bbe6bc279
commit 6e9123af19
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
1 changed files with 36 additions and 0 deletions

View File

@ -4,7 +4,9 @@ namespace Pterodactyl\Tests\Browser;
use Laravel\Dusk\TestCase; use Laravel\Dusk\TestCase;
use BadMethodCallException; use BadMethodCallException;
use Pterodactyl\Models\User;
use Tests\CreatesApplication; use Tests\CreatesApplication;
use Illuminate\Support\Facades\Hash;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Facebook\WebDriver\Chrome\ChromeOptions; use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\RemoteWebDriver; use Facebook\WebDriver\Remote\RemoteWebDriver;
@ -15,6 +17,13 @@ abstract class BrowserTestCase extends TestCase
{ {
use CreatesApplication, DatabaseMigrations; use CreatesApplication, DatabaseMigrations;
/**
* The default password to use for new accounts.
*
* @var string
*/
protected static $userPassword = 'Password123';
/** /**
* Setup tests. * Setup tests.
*/ */
@ -61,4 +70,31 @@ abstract class BrowserTestCase extends TestCase
{ {
return new PterodactylBrowser($driver); return new PterodactylBrowser($driver);
} }
/**
* Tear down the test and delete all cookies from the browser instance to address
* instances where the test would be kicked over to the login page.
*/
protected function tearDown()
{
/** @var \Pterodactyl\Tests\Browser\PterodactylBrowser $browser */
foreach (static::$browsers as $browser) {
$browser->driver->manage()->deleteAllCookies();
}
parent::tearDown();
}
/**
* Return a user model to authenticate aganist and use in the tests.
*
* @param array $attributes
* @return \Pterodactyl\Models\User
*/
protected function user(array $attributes = []): User
{
return factory(User::class)->create(array_merge([
'password' => Hash::make(static::$userPassword),
], $attributes));
}
} }