From 6e9123af196bc7226a2bba29d3e6464e92930d35 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sun, 15 Jul 2018 11:44:08 -0700 Subject: [PATCH] Correctly tear down tests and remove cookies --- tests/Browser/BrowserTestCase.php | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/Browser/BrowserTestCase.php b/tests/Browser/BrowserTestCase.php index 7451fa1e8..3548f9885 100644 --- a/tests/Browser/BrowserTestCase.php +++ b/tests/Browser/BrowserTestCase.php @@ -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)); + } }