1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
<?php
namespace Tests\Browser\Components;
use Laravel\Dusk\Component;
use PHPUnit\Framework\Assert;
use Tests\Browser\Browser;
class App extends Component
{
/**
* Get the root selector for the component.
*
* @return string
*/
public function selector()
{
return '';
}
/**
* Assert that the browser page contains the component.
*
* @param Browser $browser
*
* @return void
*/
public function assert($browser)
{
// 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.
}
/**
* Get the element shortcuts for the component.
*
* @return array
*/
public function elements()
{
return [
];
}
/**
* Assert value of rcmail.env entry
*
* @param Browser $browser Browser object
* @param array|string $key Env key name or array of key->expected pairs
* @param mixed $expected Expected value when $key is a string
*/
public function assertEnv($browser, $key, $expected = null)
{
if (is_array($key)) {
foreach ($key as $name => $expected) {
Assert::assertEquals($expected, $browser->getEnv($name));
}
}
else {
Assert::assertEquals($expected, $browser->getEnv($key));
}
}
/**
* Assert existence of defined gui_objects
*/
public function assertObjects($browser, array $names)
{
$objects = $this->getObjects($browser);
foreach ($names as $object_name) {
Assert::assertContains($object_name, $objects);
}
}
/**
* Return names of defined gui_objects
*/
public function getObjects($browser)
{
return (array) $browser->driver->executeScript("var i, r = []; for (i in rcmail.gui_objects) r.push(i); return r");
}
/**
* 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 && $browser->getEnv('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');
}
}
|