diff --git a/.env.dusk.local b/.env.dusk.example similarity index 94% rename from .env.dusk.local rename to .env.dusk.example index 33343ffc51..074f6fc3d7 100644 --- a/.env.dusk.local +++ b/.env.dusk.example @@ -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 diff --git a/.gitignore b/.gitignore index 37e9d3f68c..078a7e4b8a 100755 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ .couscous .DS_Store .env +.env.dusk.* +!.env.dusk.example .idea /bin/ /bootstrap/compiled.php diff --git a/TESTING.md b/TESTING.md index 6624289758..8a430d498e 100644 --- a/TESTING.md +++ b/TESTING.md @@ -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. diff --git a/composer.json b/composer.json index 07dbf20639..06d8563039 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/composer.lock b/composer.lock index d6067c5e27..d23081089c 100644 --- a/composer.lock +++ b/composer.lock @@ -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", diff --git a/database/migrations/2012_12_06_225929_migration_cartalyst_sentry_install_groups.php b/database/migrations/2012_12_06_225929_migration_cartalyst_sentry_install_groups.php index cd45847bc7..55d7318736 100644 --- a/database/migrations/2012_12_06_225929_migration_cartalyst_sentry_install_groups.php +++ b/database/migrations/2012_12_06_225929_migration_cartalyst_sentry_install_groups.php @@ -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'); } } diff --git a/database/migrations/2013_11_17_054526_add_physical_to_assets.php b/database/migrations/2013_11_17_054526_add_physical_to_assets.php index 2ccc7c43dc..28d1117201 100755 --- a/database/migrations/2013_11_17_054526_add_physical_to_assets.php +++ b/database/migrations/2013_11_17_054526_add_physical_to_assets.php @@ -26,6 +26,6 @@ class AddPhysicalToAssets extends Migration */ public function down() { - $table->dropColumn('physical'); + // $table->dropColumn('physical'); } } diff --git a/database/migrations/2013_11_25_013244_recreate_licenses_table.php b/database/migrations/2013_11_25_013244_recreate_licenses_table.php index fb18452794..a22349dcd6 100755 --- a/database/migrations/2013_11_25_013244_recreate_licenses_table.php +++ b/database/migrations/2013_11_25_013244_recreate_licenses_table.php @@ -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'); } } diff --git a/database/migrations/2013_11_25_031458_create_license_seats_table.php b/database/migrations/2013_11_25_031458_create_license_seats_table.php index 466ef00870..d023b8ebec 100755 --- a/database/migrations/2013_11_25_031458_create_license_seats_table.php +++ b/database/migrations/2013_11_25_031458_create_license_seats_table.php @@ -31,6 +31,6 @@ class CreateLicenseSeatsTable extends Migration */ public function down() { - // + Schema::dropIfExists('license_seats'); } } diff --git a/database/migrations/2013_11_25_104343_alter_warranty_column_on_assets.php b/database/migrations/2013_11_25_104343_alter_warranty_column_on_assets.php index be62374dce..d63a6ad9b4 100755 --- a/database/migrations/2013_11_25_104343_alter_warranty_column_on_assets.php +++ b/database/migrations/2013_11_25_104343_alter_warranty_column_on_assets.php @@ -23,6 +23,8 @@ class AlterWarrantyColumnOnAssets extends Migration */ public function down() { - // + Schema::table('assets', function ($table) { + $table->renameColumn('warranty_months', 'warrantee_months'); + }); } } diff --git a/database/migrations/2013_12_10_084038_add_eol_on_models_table.php b/database/migrations/2013_12_10_084038_add_eol_on_models_table.php index d8d222deec..97e7b266e6 100755 --- a/database/migrations/2013_12_10_084038_add_eol_on_models_table.php +++ b/database/migrations/2013_12_10_084038_add_eol_on_models_table.php @@ -24,7 +24,7 @@ class AddEolOnModelsTable extends Migration public function down() { Schema::table('models', function ($table) { - $table->dropColumn('old'); + $table->dropColumn('eol'); }); } } diff --git a/database/migrations/2015_07_29_230054_add_thread_id_to_asset_logs_table.php b/database/migrations/2015_07_29_230054_add_thread_id_to_asset_logs_table.php index eefc283e3f..f14dc078cc 100644 --- a/database/migrations/2015_07_29_230054_add_thread_id_to_asset_logs_table.php +++ b/database/migrations/2015_07_29_230054_add_thread_id_to_asset_logs_table.php @@ -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'); + // }); } /** diff --git a/database/migrations/2015_09_22_003413_migrate_mac_address.php b/database/migrations/2015_09_22_003413_migrate_mac_address.php index 516b5c2ec7..3c4bf93e15 100644 --- a/database/migrations/2015_09_22_003413_migrate_mac_address.php +++ b/database/migrations/2015_09_22_003413_migrate_mac_address.php @@ -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)'); + } } } diff --git a/database/migrations/2016_08_23_145619_add_show_in_nav_to_status_labels.php b/database/migrations/2016_08_23_145619_add_show_in_nav_to_status_labels.php index c4e1a18177..5ea26bf4c1 100644 --- a/database/migrations/2016_08_23_145619_add_show_in_nav_to_status_labels.php +++ b/database/migrations/2016_08_23_145619_add_show_in_nav_to_status_labels.php @@ -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'); }); } } diff --git a/database/migrations/2017_01_25_063357_fix_utf8_custom_field_column_names.php b/database/migrations/2017_01_25_063357_fix_utf8_custom_field_column_names.php index 72e85698e0..4725cccfe1 100644 --- a/database/migrations/2017_01_25_063357_fix_utf8_custom_field_column_names.php +++ b/database/migrations/2017_01_25_063357_fix_utf8_custom_field_column_names.php @@ -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'); diff --git a/database/migrations/2017_03_10_210807_add_fields_to_manufacturer.php b/database/migrations/2017_03_10_210807_add_fields_to_manufacturer.php index 0d05a680c1..05af7c8316 100644 --- a/database/migrations/2017_03_10_210807_add_fields_to_manufacturer.php +++ b/database/migrations/2017_03_10_210807_add_fields_to_manufacturer.php @@ -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'); diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index 43d8b3d9e1..66872bd1bf 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -390,7 +390,8 @@ return [ 'start_date' => 'Start Date', 'end_date' => 'End Date', 'alt_uploaded_image_thumbnail' => 'Uploaded thumbnail', - 'placeholder_kit' => 'Select a kit' + 'placeholder_kit' => 'Select a kit', + 'file_not_found' => 'File not found', diff --git a/resources/views/users/view.blade.php b/resources/views/users/view.blade.php index 5d959589e6..c4f6eca878 100755 --- a/resources/views/users/view.blade.php +++ b/resources/views/users/view.blade.php @@ -869,16 +869,19 @@