Merge pull request #12342 from marcusmoore/fix/dusk-test-suite

Fixed Dusk Test Suite
This commit is contained in:
snipe 2023-02-02 09:50:34 -08:00 committed by GitHub
commit 2a8851bbd7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 86 additions and 42 deletions

View file

@ -20,13 +20,13 @@ PUBLIC_FILESYSTEM_DISK=local_public
# REQUIRED: DATABASE SETTINGS
# --------------------------------------------
DB_CONNECTION=mysql
DB_HOST=localhost
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=snipeit-local
DB_USERNAME=snipeit-local
DB_PASSWORD=snipeit-local
DB_DATABASE=null
DB_USERNAME=null
DB_PASSWORD=null
DB_PREFIX=null
DB_DUMP_PATH='/Applications/MAMP/Library/bin'
#DB_DUMP_PATH=
# --------------------------------------------
# OPTIONAL: SSL DATABASE SETTINGS

2
.gitignore vendored
View file

@ -1,6 +1,8 @@
.couscous
.DS_Store
.env
.env.dusk.*
!.env.dusk.example
.idea
/bin/
/bootstrap/compiled.php

View file

@ -43,23 +43,33 @@ you want to run.
## Browser Tests
The browser tests use [Dusk](https://laravel.com/docs/8.x/dusk) to run them.
When troubleshooting any problems, make sure that your `.env` file is configured
correctly to run the existing application.
Browser tests are run via [Laravel Dusk](https://laravel.com/docs/8.x/dusk) and require Google Chrome to be installed.
Before attempting to run Dusk tests copy the example environment file for Dusk and update the values to match your environment:
`cp .env.dusk.example .env.dusk.local`
> `local` refers to the value of `APP_ENV` in your `.env` so if you have it set to `dev` then the file should be named `.env.dusk.dev`.
**Important**: Dusk tests cannot be run using an in-memory SQLite database. Additionally, the Dusk test suite uses the `DatabaseMigrations` trait which will leave the database in a fresh state after running. Therefore, it is recommended that you create a test database and point `DB_DATABASE` in `.env.dusk.local` to it.
### Test Setup
Your application needs to be configued and up and running in order for the browser
Your application needs to be configured and up and running in order for the browser
tests to actually run. When running the tests locally, you can start the application
using the following command:
`php artisan serve`
To run the test suite use the following command from another terminal tab or window:
Now you are ready to run the test suite. Use the following command from another terminal tab or window:
`php artisan dusk`
To run individual test files, you can pass the path to the test that you want to run.
To run individual test files, you can pass the path to the test that you want to run:
`php artisan dusk tests/Browser/LoginTest.php`
If you get an error when attempting to run Dusk tests that says `Couldn't connect to server` run:
`php artisan dusk:chrome-driver --detect`
This command will install the specific ChromeDriver Dusk needs for your operating system and Chrome version.

View file

@ -73,7 +73,7 @@
},
"require-dev": {
"fakerphp/faker": "^1.16",
"laravel/dusk": "^6.19",
"laravel/dusk": "^6.25",
"mockery/mockery": "^1.4",
"phpunit/php-token-stream": "^3.1",
"phpunit/phpunit": "^9.0",

14
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "0c1f3848f8c9ede2b5f1513e4feaa7d7",
"content-hash": "4fed0ab76a34ef85a44568e470abab48",
"packages": [
{
"name": "alek13/slack",
@ -11847,16 +11847,16 @@
},
{
"name": "laravel/dusk",
"version": "v6.25.0",
"version": "v6.25.2",
"source": {
"type": "git",
"url": "https://github.com/laravel/dusk.git",
"reference": "b4632b7493a187d31afc5c9ddec437c81b16421a"
"reference": "25a595ac3dc82089a91af10dd23b0d58fd3f6d0b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laravel/dusk/zipball/b4632b7493a187d31afc5c9ddec437c81b16421a",
"reference": "b4632b7493a187d31afc5c9ddec437c81b16421a",
"url": "https://api.github.com/repos/laravel/dusk/zipball/25a595ac3dc82089a91af10dd23b0d58fd3f6d0b",
"reference": "25a595ac3dc82089a91af10dd23b0d58fd3f6d0b",
"shasum": ""
},
"require": {
@ -11914,9 +11914,9 @@
],
"support": {
"issues": "https://github.com/laravel/dusk/issues",
"source": "https://github.com/laravel/dusk/tree/v6.25.0"
"source": "https://github.com/laravel/dusk/tree/v6.25.2"
},
"time": "2022-07-11T11:38:43+00:00"
"time": "2022-09-29T09:37:07+00:00"
},
{
"name": "mockery/mockery",

View file

@ -44,6 +44,8 @@ class MigrationCartalystSentryInstallGroups extends Migration
*/
public function down()
{
Schema::drop('permission_groups');
// See 2014_11_04_231416_update_group_field_for_reporting.php and 2019_06_12_184327_rename_groups_table.php
Schema::dropIfExists('permission_groups');
Schema::dropIfExists('groups');
}
}

View file

@ -26,6 +26,6 @@ class AddPhysicalToAssets extends Migration
*/
public function down()
{
$table->dropColumn('physical');
// $table->dropColumn('physical');
}
}

View file

@ -37,7 +37,7 @@ class ReCreateLicensesTable extends Migration
*/
public function down()
{
//
Schema::drop('licenses');
// This was most likely handled in 2013_11_17_054359_drop_licenses_table.php
Schema::dropIfExists('licenses');
}
}

View file

@ -31,6 +31,6 @@ class CreateLicenseSeatsTable extends Migration
*/
public function down()
{
//
Schema::dropIfExists('license_seats');
}
}

View file

@ -23,6 +23,8 @@ class AlterWarrantyColumnOnAssets extends Migration
*/
public function down()
{
//
Schema::table('assets', function ($table) {
$table->renameColumn('warranty_months', 'warrantee_months');
});
}
}

View file

@ -24,7 +24,7 @@ class AddEolOnModelsTable extends Migration
public function down()
{
Schema::table('models', function ($table) {
$table->dropColumn('old');
$table->dropColumn('eol');
});
}
}

View file

@ -105,10 +105,10 @@
*/
public function down()
{
Schema::table('asset_logs', function (Blueprint $table) {
$table->dropIndex('thread_id');
$table->dropColumn('thread_id');
});
// Schema::table('asset_logs', function (Blueprint $table) {
// $table->dropIndex('thread_id');
// $table->dropColumn('thread_id');
// });
}
/**

View file

@ -48,13 +48,19 @@ class MigrateMacAddress extends Migration
*/
public function down()
{
//
$f = \App\Models\CustomFieldset::where(['name' => 'Asset with MAC Address'])->first();
$f->fields()->delete();
$f->delete();
if ($f) {
$f->fields()->delete();
$f->delete();
}
Schema::table('models', function (Blueprint $table) {
$table->renameColumn('deprecated_mac_address', 'show_mac_address');
});
DB::statement('ALTER TABLE assets CHANGE _snipeit_mac_address mac_address varchar(255)');
if (Schema::hasColumn('assets', '_snipeit_mac_address')) {
DB::statement('ALTER TABLE assets CHANGE _snipeit_mac_address mac_address varchar(255)');
}
}
}

View file

@ -25,7 +25,7 @@ class AddShowInNavToStatusLabels extends Migration
public function down()
{
Schema::table('status_labels', function (Blueprint $table) {
$table->dropColumn('show_in_nav', 'field_encrypted');
$table->dropColumn('show_in_nav');
});
}
}

View file

@ -4,6 +4,7 @@ use App\Models\CustomField;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Str;
/**
* Fixes issue #2551 where columns got donked if the field name in non-ascii
@ -71,6 +72,25 @@ class FixUtf8CustomFieldColumnNames extends Migration
*/
public function down()
{
// In the up method above, updateLegacyColumnName is called and custom fields in the assets table are prefixed
// with "_snipe_it_", suffixed with "_{id of the CustomField}", and stored in custom_fields.db_column.
// The following reverses those changes.
foreach (CustomField::all() as $field) {
$currentColumnName = $field->db_column;
// "_snipeit_imei_1" becomes "_snipeit_imei"
$legacyColumnName = (string) Str::of($currentColumnName)->replaceMatches('/_(\d)+$/', '');
if (Schema::hasColumn(CustomField::$table_name, $currentColumnName)) {
Schema::table(CustomField::$table_name, function (Blueprint $table) use ($currentColumnName, $legacyColumnName) {
$table->renameColumn(
$currentColumnName,
$legacyColumnName
);
});
}
}
Schema::table('custom_fields', function ($table) {
$table->dropColumn('db_column');
$table->dropColumn('help_text');

View file

@ -28,7 +28,7 @@ class AddFieldsToManufacturer extends Migration
*/
public function down()
{
Schema::table('settings', function ($table) {
Schema::table('manufacturers', function ($table) {
$table->dropColumn('url');
$table->dropColumn('support_url');
$table->dropColumn('support_phone');

View file

@ -2,8 +2,8 @@
namespace Tests\Browser;
use App\Models\Setting;
use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;
@ -26,6 +26,9 @@ class LoginTest extends DuskTestCase
$user->permissions = '{"superuser": 1}';
$user->save();
Setting::factory()->create();
$this->browse(function (Browser $browser) {
$browser->visitRoute('login')
->assertSee(trans('auth/general.login_prompt'));
@ -37,10 +40,7 @@ class LoginTest extends DuskTestCase
->type('password', 'password')
->press(trans('auth/general.login'))
->assertPathIs('/');
$browser->screenshot('dashboard');
$browser->screenshot('dashboard');
});
// Delete the user afterwards
$user->delete();
}
}

View file

@ -5,11 +5,13 @@ namespace Tests;
use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Laravel\Dusk\TestCase as BaseTestCase;
abstract class DuskTestCase extends BaseTestCase
{
use CreatesApplication;
use DatabaseMigrations;
/**
* Prepare for Dusk test execution.