Skip to content

Commit 6e9123a

Browse files
committed
Correctly tear down tests and remove cookies
1 parent 8bbe6bc commit 6e9123a

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tests/Browser/BrowserTestCase.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
use Laravel\Dusk\TestCase;
66
use BadMethodCallException;
7+
use Pterodactyl\Models\User;
78
use Tests\CreatesApplication;
9+
use Illuminate\Support\Facades\Hash;
810
use Illuminate\Database\Eloquent\Model;
911
use Facebook\WebDriver\Chrome\ChromeOptions;
1012
use Facebook\WebDriver\Remote\RemoteWebDriver;
@@ -15,6 +17,13 @@ abstract class BrowserTestCase extends TestCase
1517
{
1618
use CreatesApplication, DatabaseMigrations;
1719

20+
/**
21+
* The default password to use for new accounts.
22+
*
23+
* @var string
24+
*/
25+
protected static $userPassword = 'Password123';
26+
1827
/**
1928
* Setup tests.
2029
*/
@@ -61,4 +70,31 @@ protected function newBrowser($driver): PterodactylBrowser
6170
{
6271
return new PterodactylBrowser($driver);
6372
}
73+
74+
/**
75+
* Tear down the test and delete all cookies from the browser instance to address
76+
* instances where the test would be kicked over to the login page.
77+
*/
78+
protected function tearDown()
79+
{
80+
/** @var \Pterodactyl\Tests\Browser\PterodactylBrowser $browser */
81+
foreach (static::$browsers as $browser) {
82+
$browser->driver->manage()->deleteAllCookies();
83+
}
84+
85+
parent::tearDown();
86+
}
87+
88+
/**
89+
* Return a user model to authenticate aganist and use in the tests.
90+
*
91+
* @param array $attributes
92+
* @return \Pterodactyl\Models\User
93+
*/
94+
protected function user(array $attributes = []): User
95+
{
96+
return factory(User::class)->create(array_merge([
97+
'password' => Hash::make(static::$userPassword),
98+
], $attributes));
99+
}
64100
}

0 commit comments

Comments
 (0)