diff --git a/.env.example b/.env.example index f9fbb5e5125..270b8a74eb0 100644 --- a/.env.example +++ b/.env.example @@ -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 diff --git a/.travis.yml b/.travis.yml index b3cd3cdff5f..a70f8c72d30 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/.travis.yml.sig b/.travis.yml.sig index d9193bdf3a2..1adaea22b16 100644 Binary files a/.travis.yml.sig and b/.travis.yml.sig differ diff --git a/composer.json b/composer.json index b6e59d7cd8e..32f617bdad9 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/composer.lock b/composer.lock index 06be03a2826..2d387d430ec 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "5ff22b6e774d07b8d33d5544c0210e87", + "content-hash": "26b41c2961513041c1ce4360f16fd1da", "packages": [ { "name": "aws/aws-sdk-php", @@ -5123,6 +5123,44 @@ ], "time": "2017-07-22T11:58:36+00:00" }, + { + "name": "enm1989/chromedriver", + "version": "2.36", + "source": { + "type": "git", + "url": "https://github.com/ENM1989/chromedriver.git", + "reference": "6af6ee96f78cecff036be73d61f526f4c5b21e7a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ENM1989/chromedriver/zipball/6af6ee96f78cecff036be73d61f526f4c5b21e7a", + "reference": "6af6ee96f78cecff036be73d61f526f4c5b21e7a", + "shasum": "" + }, + "bin": [ + "bin/chromedriver" + ], + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Nico Müller", + "email": "nico.mueller.1989@googlemail.com" + } + ], + "description": "Composer distribution of Chromedriver. Adds a executable to your composer bin directory.", + "homepage": "https://github.com/ENM1989/chromedriver", + "keywords": [ + "Chromedriver", + "chrome", + "selenium", + "webdriver" + ], + "time": "2018-03-06T20:49:24+00:00" + }, { "name": "facebook/webdriver", "version": "1.5.0", diff --git a/database/seeds/FakeContentTableSeeder.php b/database/seeds/FakeContentTableSeeder.php index 51ccd97dcdf..990a831de22 100644 --- a/database/seeds/FakeContentTableSeeder.php +++ b/database/seeds/FakeContentTableSeeder.php @@ -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; @@ -24,8 +26,6 @@ public function run() { $this->account = Account::createDefault('John', 'Doe', 'admin@admin.com', 'admin'); - $this->faker = Faker::create(); - // create a random number of contacts $this->numberOfContacts = rand(60, 100); echo 'Generating '.$this->numberOfContacts.' fake contacts'.PHP_EOL; diff --git a/phpunit.xml b/phpunit.xml index 5bce945a47c..9fa5aa10cb2 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -38,10 +38,6 @@ - - - - diff --git a/phpunitpostgres.xml b/phpunitpostgres.xml index a1200b801dd..1efb4e2eb73 100644 --- a/phpunitpostgres.xml +++ b/phpunitpostgres.xml @@ -38,10 +38,6 @@ - - - - diff --git a/resources/views/settings/imports/upload.blade.php b/resources/views/settings/imports/upload.blade.php index 1be71ae5c09..256d88349c6 100644 --- a/resources/views/settings/imports/upload.blade.php +++ b/resources/views/settings/imports/upload.blade.php @@ -61,7 +61,7 @@
- + {{ trans('app.cancel') }}
diff --git a/tests/Browser/Feature/UploadVCardTest.php b/tests/Browser/Feature/UploadVCardTest.php index 2ac3b64bfb7..ad75f67ad2c 100644 --- a/tests/Browser/Feature/UploadVCardTest.php +++ b/tests/Browser/Feature/UploadVCardTest.php @@ -4,6 +4,7 @@ use App\User; use Tests\DuskTestCase; +use Tests\Browser\Pages\ImportVCardUpload; class UploadVCardTest extends DuskTestCase { @@ -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'); }); @@ -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.'); }); diff --git a/tests/Browser/Pages/DashboardValidate2fa.php b/tests/Browser/Pages/DashboardValidate2fa.php index d2d02ebf6fc..a1e7e3fddce 100644 --- a/tests/Browser/Pages/DashboardValidate2fa.php +++ b/tests/Browser/Pages/DashboardValidate2fa.php @@ -35,7 +35,7 @@ public function assert(Browser $browser) public function elements() { return [ - 'verify' => 'verify', + 'verify' => "button[name='verify']", 'otp' => '#one_time_password', ]; } diff --git a/tests/Browser/Pages/ImportVCardUpload.php b/tests/Browser/Pages/ImportVCardUpload.php new file mode 100644 index 00000000000..97096129a47 --- /dev/null +++ b/tests/Browser/Pages/ImportVCardUpload.php @@ -0,0 +1,41 @@ +assertPathIs($this->url()); + } + + /** + * Get the element shortcuts for the page. + * + * @return array + */ + public function elements() + { + return [ + 'upload' => '#upload', + ]; + } +} diff --git a/tests/Browser/Pages/SettingsSecurity.php b/tests/Browser/Pages/SettingsSecurity.php index ed70ab1e2be..5d769d893bb 100644 --- a/tests/Browser/Pages/SettingsSecurity.php +++ b/tests/Browser/Pages/SettingsSecurity.php @@ -35,6 +35,7 @@ public function assert(Browser $browser) public function elements() { return [ + 'two_factor_link' => "a:contains('Enable Two Factor Authentication')", ]; } } diff --git a/tests/Browser/Pages/SettingsSecurity2faDisable.php b/tests/Browser/Pages/SettingsSecurity2faDisable.php index e4f14335d23..9ef550c4336 100644 --- a/tests/Browser/Pages/SettingsSecurity2faDisable.php +++ b/tests/Browser/Pages/SettingsSecurity2faDisable.php @@ -35,7 +35,7 @@ public function assert(Browser $browser) public function elements() { return [ - 'verify' => 'verify', + 'verify' => "button[name='verify']", 'otp' => '#one_time_password', ]; } diff --git a/tests/Browser/Pages/SettingsSecurity2faEnable.php b/tests/Browser/Pages/SettingsSecurity2faEnable.php index c41e5b58182..26bbb56a3db 100644 --- a/tests/Browser/Pages/SettingsSecurity2faEnable.php +++ b/tests/Browser/Pages/SettingsSecurity2faEnable.php @@ -37,7 +37,7 @@ public function elements() return [ 'barcode' => '#barcode', 'secretkey' => '#secretkey', - 'verify' => 'verify', + 'verify' => "button[name='verify']", 'otp' => '#one_time_password', ]; } diff --git a/tests/Browser/Settings/MultiFAControllerTest.php b/tests/Browser/Settings/MultiFAControllerTest.php index 6d8456a82a9..b805ac03be6 100644 --- a/tests/Browser/Settings/MultiFAControllerTest.php +++ b/tests/Browser/Settings/MultiFAControllerTest.php @@ -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') @@ -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); @@ -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)); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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)); @@ -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); @@ -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)); diff --git a/tests/DuskTestCase.php b/tests/DuskTestCase.php index 95ecccc37c1..fafebb68ccd 100644 --- a/tests/DuskTestCase.php +++ b/tests/DuskTestCase.php @@ -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. * diff --git a/tests/Feature/ContactTest.php b/tests/Feature/ContactTest.php index 5273cce855b..78cc59c5af7 100644 --- a/tests/Feature/ContactTest.php +++ b/tests/Feature/ContactTest.php @@ -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 diff --git a/tests/Feature/TaskTest.php b/tests/Feature/TaskTest.php index ef0c035077c..8226f478123 100644 --- a/tests/Feature/TaskTest.php +++ b/tests/Feature/TaskTest.php @@ -4,12 +4,12 @@ use App\Contact; use Tests\FeatureTestCase; -use Faker\Factory as Faker; +use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Foundation\Testing\DatabaseTransactions; class TaskTest extends FeatureTestCase { - use DatabaseTransactions; + use DatabaseTransactions, WithFaker; /** * Returns an array containing a user object along with @@ -31,9 +31,8 @@ public function test_user_can_add_a_task() { list($user, $contact) = $this->fetchUser(); - $faker = Faker::create(); - $taskTitle = $faker->realText(); - $taskDescription = $faker->realText(); + $taskTitle = $this->faker->realText(); + $taskDescription = $this->faker->realText(); $params = [ 'title' => $taskTitle, diff --git a/tests/TestCase.php b/tests/TestCase.php index 06d11a55a64..2932d4a69d6 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,23 +2,9 @@ namespace Tests; -use Faker\Factory; use Illuminate\Foundation\Testing\TestCase as BaseTestCase; abstract class TestCase extends BaseTestCase { use CreatesApplication; - - public $faker; - - /** - * TestCase constructor. - */ - public function __construct($name = null, array $data = [], $dataName = '') - { - parent::__construct($name, $data, $dataName); - - // Makes a Faker Factory available to all tests. - $this->faker = Factory::create(); - } }