Tests: Move logon helpers to the App component

pull/6453/head^2
Aleksander Machniak 6 years ago
parent 2c0dd762ed
commit e2bd4548ed

@ -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;
}

@ -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');
}
}

Loading…
Cancel
Save