Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 12 additions & 27 deletions .ci/runtests.sh
Original file line number Diff line number Diff line change
@@ -1,37 +1,22 @@
#!/bin/bash
SELF_PATH=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
set -evuo pipefail

if [ -z "${DISPLAY:-}" ]; then
echo Start Xvfb;
export DISPLAY=:99.0;
/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1280x1024x24;
fi

if ! $(nc -z localhost 4444); then
$SELF_PATH/../vendor/bin/selenium-server-standalone -role hub -log $SELF_PATH/../selenium-server.log -enablePassThrough false &
until $(nc -z localhost 4444); do
echo Waiting for selenium hub to start...;
sleep 1;
done
fi
SELF_PATH=$(cd -P -- "$(dirname -- "$0")" && /bin/pwd -P)
ROOT=$(realpath $SELF_PATH/..)
HOST=localhost

export PATH="$SELF_PATH/../vendor/bin:$PATH"
if ! $(nc -z localhost 8910); then
java -Dwebdriver.chrome.driver="$SELF_PATH/../vendor/bin/chromedriver" -jar $SELF_PATH/../vendor/se/selenium-server-standalone/bin/selenium-server-standalone.jar -role node -port 8910 -log $SELF_PATH/..selenium-node.log &
until $(nc -z localhost 8910); do
echo Waiting for selenium node to start...;
sleep 1;
done
fi
$SELF_PATH/start-selenium.sh

if ! $(nc -z localhost 8000); then
pushd $SELF_PATH/..
php laravel serve &
if ! $(nc -z $HOST 8000); then
pushd $ROOT
php artisan serve --host=$HOST &
popd
until $(nc -z localhost 8000); do
until $(nc -z $HOST 8000); do
echo Waiting for laravel serve to start...;
sleep 1;
done
fi

$SELF_PATH/../vendor/bin/steward run laravel chrome -vvv
pushd $ROOT
$ROOT/vendor/bin/steward run laravel chrome -vvv
popd
20 changes: 17 additions & 3 deletions .ci/start-selenium.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
#!/bin/bash

realpath ()
{
f=$@;
if [ -d "$f" ]; then
base="";
dir="$f";
else
base="/$(basename "$f")";
dir=$(dirname "$f");
fi;
dir=$(cd "$dir" && /bin/pwd -P);
echo "$dir$base"
}
set -evuo pipefail

SELF_PATH=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
ROOT=$SELF_PATH/..
SELF_PATH=$(cd -P -- "$(dirname -- "$0")" && /bin/pwd -P)
ROOT=$(realpath $SELF_PATH/..)

if [ -z "${DISPLAY:-}" ]; then
echo Start Xvfb;
export DISPLAY=:99.0;
/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1280x1024x24;
/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1280x1024x24 || true;
fi

if ! $(nc -z localhost 4444); then
Expand Down
2 changes: 1 addition & 1 deletion .env.travis
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ CACHE_DRIVER=array
SESSION_DRIVER=file
QUEUE_DRIVER=sync

2FA_ENABLED=false
2FA_ENABLED=true
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"require-dev": {
"enm1989/chromedriver": "^2.35",
"filp/whoops": "~2.0",
"khanamiryan/qrcode-detector-decoder": "^1.0",
"lmc/steward": "dev-update-dependencies",
"matthiasnoback/live-code-coverage": "^0.1.0",
"mockery/mockery": "0.9.*",
Expand Down
52 changes: 51 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions resources/views/settings/security/2fa-enable.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
<div class="panel-body">
{{ trans('settings.2fa_enable_otp') }}
<p>
<img alt="Image of QR barcode" src="{{ $image }}" />
<img id="barcode" alt="Image of QR barcode" src="{{ $image }}" />
<br />
{{ trans('settings.2fa_enable_otp_help') }} <code>{{ $secret }}</code>
{{ trans('settings.2fa_enable_otp_help') }} <code id="secretkey">{{ $secret }}</code>
</p>
</div>

Expand Down
80 changes: 67 additions & 13 deletions tests/BrowserSelenium/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ abstract class BaseTestCase extends AbstractTestCase
/** @var string */
public static $baseUrl;

protected function getUrl()
{
}

public function setUp()
{
parent::setUp();

// Set base url according to environment
switch (ConfigProvider::getInstance()->env) {
case 'dev':
self::$baseUrl = 'http://monica.test/'; // env('APP_URL');
self::$baseUrl = config('app.url');
break;
case 'travis':
self::$baseUrl = 'http://localhost:8000/';
Expand All @@ -51,27 +55,47 @@ public function setUp()
* Init the WebDriver.
* (init should be run with "before" phpunit annotation, but it doesn't work !).
*/
public function init()
public function init($url = null)
{
$this->wd->get(self::$baseUrl);
$uri = self::$baseUrl;
if (! isset($url) || $url == null) {
$url = '';
}
if (ends_with($uri, '/')) {
$uri = substr($uri, 0, strlen($uri) - 1);
}

if (! starts_with($url, '/')) {
$url = '/'.$url;
}

$this->wd->get($uri.$url);
}

/**
* Init WebDriver and pass the login form.
*/
public function initAndLogin()
public function initAndLogin($url = null, $login = '[email protected]', $password = 'admin')
{
$this->init();
if (! isset($url) || $url == null) {
$url = $this->getUrl();
if ($url == null) {
$url = '/dashboard';
}
}
$this->init($url);

if ($this->getCurrentPath() == '/') {
//$url = $this->wd->getCurrentURL();
$this->findById('email')->sendKeys('[email protected]');
$this->findById('password')->sendKeys('admin');
$this->findByTag('button')->submit();
switch ($this->getCurrentPath()) {
case '/':
case '/login':
$this->findById('email')->sendKeys($login);
$this->findById('password')->sendKeys($password);
$this->findByTag('button')->submit();

$this->wd->wait()->until(
WebDriverExpectedCondition::urlContains('/dashboard')
);
$this->wd->wait()->until(
WebDriverExpectedCondition::urlContains($url)
);
break;
}
}

Expand All @@ -84,4 +108,34 @@ public function getCurrentPath()
parse_url($this->wd->getCurrentURL(), PHP_URL_PATH)
);
}

/**
* Get full uri for destination path.
*/
public function getDestUri($path)
{
$parse_url = parse_url($this->wd->getCurrentURL());
$scheme = isset($parse_url['scheme']) ? $parse_url['scheme'].'://' : '';
$host = isset($parse_url['host']) ? $parse_url['host'] : '';
$port = isset($parse_url['port']) ? ':'.$parse_url['port'] : '';

if (starts_with($path, '/')) {
$path = substr($path, 1);
}

return $scheme.$host.$port.'/'.$path;
}

/**
* Get url for path, find correponding link, and click it.
*/
public function clickDestUri($path)
{
$uri = $this->getDestUri($path);
$link = $this->findByXpath("//a[@href='$uri']");
$link->click();
$this->wd->wait()->until(
WebDriverExpectedCondition::urlContains($path)
);
}
}
Loading