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

View file

@ -4,7 +4,9 @@ namespace Pterodactyl\Tests\Browser;
use Laravel\Dusk\TestCase;
use BadMethodCallException;
use Pterodactyl\Models\User;
use Tests\CreatesApplication;
use Illuminate\Support\Facades\Hash;
use Illuminate\Database\Eloquent\Model;
use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\RemoteWebDriver;
@ -15,6 +17,13 @@ abstract class BrowserTestCase extends TestCase
{
use CreatesApplication, DatabaseMigrations;
/**
* The default password to use for new accounts.
*
* @var string
*/
protected static $userPassword = 'Password123';
/**
* Setup tests.
*/
@ -61,4 +70,31 @@ abstract class BrowserTestCase extends TestCase
{
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));
}
}