44
55use Laravel \Dusk \TestCase ;
66use BadMethodCallException ;
7+ use Pterodactyl \Models \User ;
78use Tests \CreatesApplication ;
9+ use Illuminate \Support \Facades \Hash ;
810use Illuminate \Database \Eloquent \Model ;
911use Facebook \WebDriver \Chrome \ChromeOptions ;
1012use 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