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
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ DB_DATABASE=monica
DB_USERNAME=homestead
DB_PASSWORD=secret
DB_PREFIX=
DB_TEST_HOST=127.0.0.1
DB_TEST_DATABASE=monica_test
DB_TEST_USERNAME=homestead
DB_TEST_PASSWORD=secret
Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ before_script:

# Start Xvfb
- "export DISPLAY=:99.0"
- if [[ "$SELENIUM" == "1" && "$SAUCELABS" != "1" ]]; then sh -e /etc/init.d/xvfb start; fi
- if [[ "$SELENIUM" == "1" && "$SAUCELABS" != "1" ]]; then /sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1280x1024x16; fi

# Start chromedriver
- bash -c "if [[ \"$SELENIUM\" == \"1\" && \"$SAUCELABS\" != \"1\" ]]; then ./vendor/laravel/dusk/bin/chromedriver-linux; fi" &
- bash -c "if [[ \"$SELENIUM\" == \"1\" && \"$SAUCELABS\" != \"1\" ]]; then ./vendor/bin/chromedriver; fi" &

script:
# Run unit tests
Expand Down
Binary file modified .travis.yml.sig
Binary file not shown.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3",
"enm1989/chromedriver": "^2.36",
"filp/whoops": "~2.0",
"khanamiryan/qrcode-detector-decoder": "^1.0",
"laravel/dusk": "^2.0",
Expand Down
40 changes: 39 additions & 1 deletion composer.lock

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

6 changes: 3 additions & 3 deletions database/seeds/FakeContentTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
use App\Account;
use App\Contact;
use GuzzleHttp\Client;
use Faker\Factory as Faker;
use Illuminate\Database\Seeder;
use Illuminate\Foundation\Testing\WithFaker;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Output\ConsoleOutput;

class FakeContentTableSeeder extends Seeder
{
use WithFaker;

private $numberOfContacts;
private $contact;
private $faker;
Expand All @@ -24,8 +26,6 @@ public function run()
{
$this->account = Account::createDefault('John', 'Doe', '[email protected]', 'admin');

$this->faker = Faker::create();

// create a random number of contacts
$this->numberOfContacts = rand(60, 100);
echo 'Generating '.$this->numberOfContacts.' fake contacts'.PHP_EOL;
Expand Down
4 changes: 0 additions & 4 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@
<env name="APP_ENV" value="testing"/>
<env name="APP_KEY" value="base64:NTrXToqFZJlv48dgPc+kNpc3SBt333TfDnF1mDShsBg="/>
<env name="DB_CONNECTION" value="testing"/>
<env name="DB_HOST" value="127.0.0.1"/>
<env name="DB_DATABASE" value="monica"/>
<env name="DB_USERNAME" value="homestead"/>
<env name="DB_PASSWORD" value="secret"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
Expand Down
4 changes: 0 additions & 4 deletions phpunitpostgres.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@
<env name="APP_ENV" value="testing"/>
<env name="APP_KEY" value="base64:NTrXToqFZJlv48dgPc+kNpc3SBt333TfDnF1mDShsBg="/>
<env name="DB_CONNECTION" value="pgsqltesting"/>
<env name="DB_HOST" value="127.0.0.1"/>
<env name="DB_DATABASE" value="monica"/>
<env name="DB_USERNAME" value="postgres"/>
<env name="DB_PASSWORD" value=""/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/settings/imports/upload.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
</div>

<div class="form-group actions">
<button type="submit" class="btn btn-primary">{{ trans('app.upload') }}</button>
<button id="upload" type="submit" class="btn btn-primary">{{ trans('app.upload') }}</button>
<a href="/settings/import" class="btn btn-secondary">{{ trans('app.cancel') }}</a>
</div> <!-- .form-group -->
</form>
Expand Down
5 changes: 5 additions & 0 deletions tests/Browser/Feature/UploadVCardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\User;
use Tests\DuskTestCase;
use Tests\Browser\Pages\ImportVCardUpload;

class UploadVCardTest extends DuskTestCase
{
Expand Down Expand Up @@ -61,6 +62,8 @@ public function test_user_can_import_contacts_from_a_vcf_card()
->visit('/settings/import')
->clickLink('Import vCard')
->attach('vcard', 'tests/stubs/single_vcard_stub.vcard')
->on(new ImportVCardUpload)
->scrollTo('upload')
->press('Upload')
->assertSee('1 imported');
});
Expand All @@ -80,6 +83,8 @@ public function test_user_see_error_when_importing_broken_vcard()
->visit('/settings/import')
->clickLink('Import vCard')
->attach('vcard', 'tests/stubs/broken_vcard_stub.vcard')
->on(new ImportVCardUpload)
->scrollTo('upload')
->press('Upload')
->assertSee('The vcard must be a file of type: vcf, vcard.');
});
Expand Down
2 changes: 1 addition & 1 deletion tests/Browser/Pages/DashboardValidate2fa.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function assert(Browser $browser)
public function elements()
{
return [
'verify' => 'verify',
'verify' => "button[name='verify']",
'otp' => '#one_time_password',
];
}
Expand Down
41 changes: 41 additions & 0 deletions tests/Browser/Pages/ImportVCardUpload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Tests\Browser\Pages;

use Laravel\Dusk\Browser;

class ImportVCardUpload extends Page
{
/**
* Get the URL for the page.
*
* @return string
*/
public function url()
{
return '/settings/import/upload';
}

/**
* Assert that the browser is on the page.
*
* @param Browser $browser
* @return void
*/
public function assert(Browser $browser)
{
$browser->assertPathIs($this->url());
}

/**
* Get the element shortcuts for the page.
*
* @return array
*/
public function elements()
{
return [
'upload' => '#upload',
];
}
}
1 change: 1 addition & 0 deletions tests/Browser/Pages/SettingsSecurity.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function assert(Browser $browser)
public function elements()
{
return [
'two_factor_link' => "a:contains('Enable Two Factor Authentication')",
];
}
}
2 changes: 1 addition & 1 deletion tests/Browser/Pages/SettingsSecurity2faDisable.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function assert(Browser $browser)
public function elements()
{
return [
'verify' => 'verify',
'verify' => "button[name='verify']",
'otp' => '#one_time_password',
];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Browser/Pages/SettingsSecurity2faEnable.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function elements()
return [
'barcode' => '#barcode',
'secretkey' => '#secretkey',
'verify' => 'verify',
'verify' => "button[name='verify']",
'otp' => '#one_time_password',
];
}
Expand Down
19 changes: 16 additions & 3 deletions tests/Browser/Settings/MultiFAControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function testHas2faEnableBarCode()
$this->browse(function (Browser $browser) use ($user) {
$browser->loginAs($user)
->visit(new SettingsSecurity)
->scrollTo('two_factor_link')
->clickLink('Enable Two Factor Authentication')
->on(new SettingsSecurity2faEnable)
->assertVisible('barcode')
Expand All @@ -68,6 +69,7 @@ public function testBarCodeContent()
$browser =
$browser->loginAs($user)
->visit(new SettingsSecurity)
->scrollTo('two_factor_link')
->clickLink('Enable Two Factor Authentication')
->on(new SettingsSecurity2faEnable);

Expand Down Expand Up @@ -116,9 +118,11 @@ public function testEnable2faWrongCode()
$browser =
$browser->loginAs($user)
->visit(new SettingsSecurity)
->scrollTo('two_factor_link')
->clickLink('Enable Two Factor Authentication')
->on(new SettingsSecurity2faEnable)
->type('one_time_password', '000000')
->scrollTo('verify')
->press('verify');

$this->assertTrue($this->hasDivAlert($browser));
Expand All @@ -140,6 +144,7 @@ public function testEnable2fa()
$browser =
$browser->loginAs($user)
->visit(new SettingsSecurity)
->scrollTo('two_factor_link')
->clickLink('Enable Two Factor Authentication')
->on(new SettingsSecurity2faEnable);

Expand All @@ -149,15 +154,17 @@ public function testEnable2fa()

private function enable2fa(Browser $browser)
{
$browser->on(new SettingsSecurity2faEnable);

$secretkey = $browser->text('secretkey');

$google2fa = new \PragmaRX\Google2FA\Google2FA();
$one_time_password = $google2fa->getCurrentOtp($secretkey);
$browser->type('otp', $one_time_password);

$browser =
$browser->press('verify')
->on(new SettingsSecurity);
$browser = $browser->scrollTo('verify')
->press('verify')
->on(new SettingsSecurity);

$this->assertTrue($this->hasDivAlert($browser));
$divalert = $this->getDivAlert($browser);
Expand All @@ -184,6 +191,7 @@ public function testEnable2faLoginWrongCode()
$browser =
$browser->loginAs($user)
->visit(new SettingsSecurity)
->scrollTo('two_factor_link')
->clickLink('Enable Two Factor Authentication')
->on(new SettingsSecurity2faEnable);

Expand Down Expand Up @@ -216,6 +224,7 @@ public function testEnable2faLogin()
$browser =
$browser->loginAs($user)
->visit(new SettingsSecurity)
->scrollTo('two_factor_link')
->clickLink('Enable Two Factor Authentication')
->on(new SettingsSecurity2faEnable);

Expand Down Expand Up @@ -248,6 +257,7 @@ public function testEnable2faDisable2fa()
$browser =
$browser->loginAs($user)
->visit(new SettingsSecurity)
->scrollTo('two_factor_link')
->clickLink('Enable Two Factor Authentication')
->on(new SettingsSecurity2faEnable);

Expand All @@ -259,6 +269,7 @@ public function testEnable2faDisable2fa()
$browser->visit(new SettingsSecurity2faDisable)
->assertVisible('otp')
->type('otp', $one_time_password)
->scrollTo('verify')
->press('verify');

$this->assertTrue($this->hasDivAlert($browser));
Expand All @@ -280,6 +291,7 @@ public function testEnable2faDisable2faWrongCode()
$browser =
$browser->loginAs($user)
->visit(new SettingsSecurity)
->scrollTo('two_factor_link')
->clickLink('Enable Two Factor Authentication')
->on(new SettingsSecurity2faEnable);

Expand All @@ -289,6 +301,7 @@ public function testEnable2faDisable2faWrongCode()
$browser->visit(new SettingsSecurity2faDisable)
->assertVisible('otp')
->type('otp', '000000')
->scrollTo('verify')
->press('verify');

$this->assertTrue($this->hasDivAlert($browser));
Expand Down
19 changes: 19 additions & 0 deletions tests/DuskTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,30 @@ abstract class DuskTestCase extends BaseTestCase
*/
public static function prepare()
{
static::useChromedriver(__DIR__.'/../vendor/bin/chromedriver');
if (env('SAUCELABS') != '1') {
static::startChromeDriver();
}
}

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

/*
* Macro scrollTo to scroll down/up, until the selector is visible
*/
Browser::macro('scrollTo', function ($selector) {
//$element = $this->element($selector);
//$this->driver->executeScript("arguments[0].scrollIntoView(true);",[$element]);

$selectorby = $this->resolver->format($selector);
$this->driver->executeScript("$(\"html, body\").animate({scrollTop: $(\"$selectorby\").offset().top}, 0);");

return $this;
});
}

/**
* Create the RemoteWebDriver instance.
*
Expand Down
3 changes: 2 additions & 1 deletion tests/Feature/ContactTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

use App\Contact;
use Tests\FeatureTestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class ContactTest extends FeatureTestCase
{
use DatabaseTransactions;
use DatabaseTransactions, WithFaker;

/**
* Returns an array containing a user object along with
Expand Down
Loading