diff --git a/tests/Browser/Browser.php b/tests/Browser/Browser.php index 91ff17b15..03fe8d195 100644 --- a/tests/Browser/Browser.php +++ b/tests/Browser/Browser.php @@ -106,35 +106,14 @@ class Browser extends \Laravel\Dusk\Browser $this->driver->getKeyboard()->releaseKey(WebDriverKeys::LEFT_CONTROL); } - /** - * Log in the test user - */ - public function doLogin() - { - $this->type('_user', TESTS_USER); - $this->type('_pass', TESTS_PASS); - $this->click('button[type="submit"]'); - - // wait after successful login - $this->waitUntil('!rcmail.busy'); - - return $this; - } - /** * Visit specified task/action with logon if needed */ public function go($task = 'mail', $action = null, $login = true) { - $this->visit("/?_task=$task&_action=$action"); - - // check if we have a valid session - if ($login) { - $app = new Components\App(); - if ($app->getEnv($this, 'task') == 'login') { - $this->doLogin(); - } - } + $this->with(new Components\App(), function ($browser) use ($task, $action, $login) { + $browser->gotoAction($task, $action, $login); + }); return $this; } diff --git a/tests/Browser/Components/App.php b/tests/Browser/Components/App.php index fbc2744de..76ce633f9 100644 --- a/tests/Browser/Components/App.php +++ b/tests/Browser/Components/App.php @@ -27,9 +27,10 @@ class App extends BaseComponent */ public function assert($browser) { - $result = $browser->script("return typeof(window.rcmail)"); - - Assert::assertEquals('object', $result[0]); + // Assume the app (window.rcmail) is always available + // we can't assert that before we visit the page + // i.e. you will not be able to use gotoAction() + // method if you try to assert that fact. } /** @@ -84,4 +85,30 @@ class App extends BaseComponent return (array) $objects; } + + /** + * Visit specified task/action with logon if needed + */ + public function gotoAction($browser, $task = 'mail', $action = null, $login = true) + { + $browser->visit("/?_task={$task}&_action={$action}"); + + // check if we have a valid session + if ($login && $this->getEnv($browser, 'task') == 'login') { + $this->doLogin($browser); + } + } + + /** + * Log in the test user + */ + protected function doLogin($browser) + { + $browser->type('_user', TESTS_USER); + $browser->type('_pass', TESTS_PASS); + $browser->click('button[type="submit"]'); + + // wait after successful login + $browser->waitUntil('!rcmail.busy'); + } }