From 2aa50859b325ea0d31a0ab1e64da1acd34b1c937 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 10 Jan 2023 17:01:03 -0800 Subject: [PATCH 01/22] Bump Dusk version to fix broken macOS chrome driver link --- composer.json | 2 +- composer.lock | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) 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 bf8cb1f758..7c8b7030ba 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", From 581655f7562199c61267e15e8ba05f1b3fd32b52 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 10 Jan 2023 17:02:11 -0800 Subject: [PATCH 02/22] Run database migrations for all Dusk tests --- tests/DuskTestCase.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/DuskTestCase.php b/tests/DuskTestCase.php index ac750d9efc..e591a7c771 100644 --- a/tests/DuskTestCase.php +++ b/tests/DuskTestCase.php @@ -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. From bc0f666906d81eaedc0d9273ed54fb1cc8a6e496 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 10 Jan 2023 17:03:09 -0800 Subject: [PATCH 03/22] Create Setting in test to avoid being redirected to the setup screen --- tests/Browser/LoginTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/Browser/LoginTest.php b/tests/Browser/LoginTest.php index 5ed055cda9..18f5172f15 100644 --- a/tests/Browser/LoginTest.php +++ b/tests/Browser/LoginTest.php @@ -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(); } } From b8b2543b0dca61c29e90eac45a44d6852b6d4491 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 10 Jan 2023 17:04:21 -0800 Subject: [PATCH 04/22] Reference the correct table in migration down method --- .../migrations/2017_03_10_210807_add_fields_to_manufacturer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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'); From e5cb68cc5ebc73fda5266b783440117550f72f6c Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 10 Jan 2023 17:06:16 -0800 Subject: [PATCH 05/22] Move drop column command to correct migration --- .../2016_08_23_145619_add_show_in_nav_to_status_labels.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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'); }); } } From 39ab545cf5b08d3a79d6d4a84d96874db11519ba Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 10 Jan 2023 17:08:28 -0800 Subject: [PATCH 06/22] Update alter statement to use correct suffix for column This is brittle... --- database/migrations/2015_09_22_003413_migrate_mac_address.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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..8167e28adf 100644 --- a/database/migrations/2015_09_22_003413_migrate_mac_address.php +++ b/database/migrations/2015_09_22_003413_migrate_mac_address.php @@ -55,6 +55,6 @@ class MigrateMacAddress extends Migration 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)'); + DB::statement('ALTER TABLE assets CHANGE _snipeit_mac_address_1 mac_address varchar(255)'); } } From 4ee3cbf60e5b6f17ecae9e6fc2025795f26008bd Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 10 Jan 2023 17:20:20 -0800 Subject: [PATCH 07/22] Comment out migration's down method to match its up method --- ...015_07_29_230054_add_thread_id_to_asset_logs_table.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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'); + // }); } /** From c5b09ed95584b01e649c670f9d8b8e2a8778e041 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 10 Jan 2023 17:21:46 -0800 Subject: [PATCH 08/22] Fix column name typo --- .../migrations/2013_12_10_084038_add_eol_on_models_table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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'); }); } } From 296c9a723d25ec46190273ec39426d489cbe25c3 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 10 Jan 2023 17:22:29 -0800 Subject: [PATCH 09/22] Reverse column rename in migration's down method --- .../2013_11_25_104343_alter_warranty_column_on_assets.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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'); + }); } } From 03938d0f32fd6f1b6891d5aa75e83edc7f8eccc1 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 10 Jan 2023 17:24:38 -0800 Subject: [PATCH 10/22] Conditionally drop table --- .../migrations/2013_11_25_013244_recreate_licenses_table.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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'); } } From aec64fa64ac2a7b59e953972af55c349de7864d7 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 10 Jan 2023 17:25:25 -0800 Subject: [PATCH 11/22] Comment out migration's down method to match its up method --- .../migrations/2013_11_17_054526_add_physical_to_assets.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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'); } } From b5ea8b8a4fd17bc27ddffb05881a748fec4526b2 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 10 Jan 2023 17:29:38 -0800 Subject: [PATCH 12/22] Conditionally drop table --- ..._12_06_225929_migration_cartalyst_sentry_install_groups.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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..49242f2e30 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,7 @@ 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'); } } From e8c2b84d24b7fcfbd0bcced9bee09e0e701b5bed Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 11 Jan 2023 12:51:15 -0800 Subject: [PATCH 13/22] Add example dusk environment file --- .env.dusk.example | 106 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 .env.dusk.example diff --git a/.env.dusk.example b/.env.dusk.example new file mode 100644 index 0000000000..074f6fc3d7 --- /dev/null +++ b/.env.dusk.example @@ -0,0 +1,106 @@ +# -------------------------------------------- +# REQUIRED: BASIC APP SETTINGS +# -------------------------------------------- +APP_ENV=local +APP_DEBUG=false +APP_KEY=base64:hTUIUh9CP6dQx+6EjSlfWTgbaMaaRvlpEwk45vp+xmk= +APP_URL=http://127.0.0.1:8000 +APP_TIMEZONE='US/Eastern' +APP_LOCALE=en +APP_LOCKED=false +MAX_RESULTS=200 + +# -------------------------------------------- +# REQUIRED: UPLOADED FILE STORAGE SETTINGS +# -------------------------------------------- +PRIVATE_FILESYSTEM_DISK=local +PUBLIC_FILESYSTEM_DISK=local_public + +# -------------------------------------------- +# REQUIRED: DATABASE SETTINGS +# -------------------------------------------- +DB_CONNECTION=mysql +DB_HOST=127.0.0.1 +DB_PORT=3306 +DB_DATABASE=null +DB_USERNAME=null +DB_PASSWORD=null +DB_PREFIX=null +#DB_DUMP_PATH= + +# -------------------------------------------- +# OPTIONAL: SSL DATABASE SETTINGS +# -------------------------------------------- +DB_SSL=false +DB_SSL_KEY_PATH=null +DB_SSL_CERT_PATH=null +DB_SSL_CA_PATH=null +DB_SSL_CIPHER=null + +# -------------------------------------------- +# REQUIRED: OUTGOING MAIL SERVER SETTINGS +# -------------------------------------------- +MAIL_DRIVER="log" + + +# -------------------------------------------- +# REQUIRED: IMAGE LIBRARY +# This should be gd or imagick +# -------------------------------------------- +IMAGE_LIB=gd + + +# -------------------------------------------- +# OPTIONAL: SESSION SETTINGS +# -------------------------------------------- +SESSION_LIFETIME=12000 +EXPIRE_ON_CLOSE=false +ENCRYPT=true +COOKIE_NAME=snipeit_v5_local +SECURE_COOKIES=true + +# -------------------------------------------- +# OPTIONAL: SECURITY HEADER SETTINGS +# -------------------------------------------- +REFERRER_POLICY=same-origin +ENABLE_CSP=true +CORS_ALLOWED_ORIGINS="*" + +# -------------------------------------------- +# OPTIONAL: CACHE SETTINGS +# -------------------------------------------- +CACHE_DRIVER=file +SESSION_DRIVER=file +QUEUE_DRIVER=sync + +# -------------------------------------------- +# OPTIONAL: LOGIN THROTTLING +# -------------------------------------------- +LOGIN_MAX_ATTEMPTS=50000 +LOGIN_LOCKOUT_DURATION=1000 +RESET_PASSWORD_LINK_EXPIRES=15 + +# -------------------------------------------- +# OPTIONAL: API +# -------------------------------------------- +API_MAX_REQUESTS_PER_HOUR=200 + +# -------------------------------------------- +# OPTIONAL: SAML SETTINGS +# -------------------------------------------- +DISABLE_NOSAML_LOCAL_LOGIN=true + + +# -------------------------------------------- +# OPTIONAL: MISC +# -------------------------------------------- +LOG_CHANNEL=single +LOG_LEVEL=debug +LOG_CHANNEL=stack +LOG_SLACK_WEBHOOK_URL=null +APP_TRUSTED_PROXIES=192.168.1.1,10.0.0.1 +ALLOW_IFRAMING=true +ENABLE_HSTS=false +WARN_DEBUG=false +APP_CIPHER=AES-256-CBC + From 9a3a796e176ad593619d8633b73db77fe1d81ed7 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 11 Jan 2023 12:57:05 -0800 Subject: [PATCH 14/22] Add dusk environment files to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 37e9d3f68c..cc67e5c40d 100755 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .couscous .DS_Store .env +.env.dusk.* .idea /bin/ /bootstrap/compiled.php From 49383ddbe0fd3c6a37a5a22a7cfeaa67c0c49926 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 11 Jan 2023 12:58:57 -0800 Subject: [PATCH 15/22] Delete old dusk local configuration --- .env.dusk.local | 106 ------------------------------------------------ 1 file changed, 106 deletions(-) delete mode 100644 .env.dusk.local diff --git a/.env.dusk.local b/.env.dusk.local deleted file mode 100644 index 33343ffc51..0000000000 --- a/.env.dusk.local +++ /dev/null @@ -1,106 +0,0 @@ -# -------------------------------------------- -# REQUIRED: BASIC APP SETTINGS -# -------------------------------------------- -APP_ENV=local -APP_DEBUG=false -APP_KEY=base64:hTUIUh9CP6dQx+6EjSlfWTgbaMaaRvlpEwk45vp+xmk= -APP_URL=http://127.0.0.1:8000 -APP_TIMEZONE='US/Eastern' -APP_LOCALE=en -APP_LOCKED=false -MAX_RESULTS=200 - -# -------------------------------------------- -# REQUIRED: UPLOADED FILE STORAGE SETTINGS -# -------------------------------------------- -PRIVATE_FILESYSTEM_DISK=local -PUBLIC_FILESYSTEM_DISK=local_public - -# -------------------------------------------- -# REQUIRED: DATABASE SETTINGS -# -------------------------------------------- -DB_CONNECTION=mysql -DB_HOST=localhost -DB_PORT=3306 -DB_DATABASE=snipeit-local -DB_USERNAME=snipeit-local -DB_PASSWORD=snipeit-local -DB_PREFIX=null -DB_DUMP_PATH='/Applications/MAMP/Library/bin' - -# -------------------------------------------- -# OPTIONAL: SSL DATABASE SETTINGS -# -------------------------------------------- -DB_SSL=false -DB_SSL_KEY_PATH=null -DB_SSL_CERT_PATH=null -DB_SSL_CA_PATH=null -DB_SSL_CIPHER=null - -# -------------------------------------------- -# REQUIRED: OUTGOING MAIL SERVER SETTINGS -# -------------------------------------------- -MAIL_DRIVER="log" - - -# -------------------------------------------- -# REQUIRED: IMAGE LIBRARY -# This should be gd or imagick -# -------------------------------------------- -IMAGE_LIB=gd - - -# -------------------------------------------- -# OPTIONAL: SESSION SETTINGS -# -------------------------------------------- -SESSION_LIFETIME=12000 -EXPIRE_ON_CLOSE=false -ENCRYPT=true -COOKIE_NAME=snipeit_v5_local -SECURE_COOKIES=true - -# -------------------------------------------- -# OPTIONAL: SECURITY HEADER SETTINGS -# -------------------------------------------- -REFERRER_POLICY=same-origin -ENABLE_CSP=true -CORS_ALLOWED_ORIGINS="*" - -# -------------------------------------------- -# OPTIONAL: CACHE SETTINGS -# -------------------------------------------- -CACHE_DRIVER=file -SESSION_DRIVER=file -QUEUE_DRIVER=sync - -# -------------------------------------------- -# OPTIONAL: LOGIN THROTTLING -# -------------------------------------------- -LOGIN_MAX_ATTEMPTS=50000 -LOGIN_LOCKOUT_DURATION=1000 -RESET_PASSWORD_LINK_EXPIRES=15 - -# -------------------------------------------- -# OPTIONAL: API -# -------------------------------------------- -API_MAX_REQUESTS_PER_HOUR=200 - -# -------------------------------------------- -# OPTIONAL: SAML SETTINGS -# -------------------------------------------- -DISABLE_NOSAML_LOCAL_LOGIN=true - - -# -------------------------------------------- -# OPTIONAL: MISC -# -------------------------------------------- -LOG_CHANNEL=single -LOG_LEVEL=debug -LOG_CHANNEL=stack -LOG_SLACK_WEBHOOK_URL=null -APP_TRUSTED_PROXIES=192.168.1.1,10.0.0.1 -ALLOW_IFRAMING=true -ENABLE_HSTS=false -WARN_DEBUG=false -APP_CIPHER=AES-256-CBC - From bc80f672ee1f88e8d4bc66facee410f439bcdedd Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 11 Jan 2023 13:00:34 -0800 Subject: [PATCH 16/22] Keep the example dusk environment file --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index cc67e5c40d..078a7e4b8a 100755 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ .DS_Store .env .env.dusk.* +!.env.dusk.example .idea /bin/ /bootstrap/compiled.php From 49f2573f36602370666808494d9d738cd96ee436 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 11 Jan 2023 13:51:01 -0800 Subject: [PATCH 17/22] Update testing readme --- TESTING.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/TESTING.md b/TESTING.md index 6624289758..f7034895a3 100644 --- a/TESTING.md +++ b/TESTING.md @@ -43,23 +43,25 @@ 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`. ### 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` From 0dd7cc9967941a821fe9d45864ab0c6844c8be4d Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 11 Jan 2023 13:54:28 -0800 Subject: [PATCH 18/22] Add note about installing ChromeDriver to testing readme --- TESTING.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/TESTING.md b/TESTING.md index f7034895a3..a1706177a9 100644 --- a/TESTING.md +++ b/TESTING.md @@ -65,3 +65,9 @@ Now you are ready to run the test suite. Use the following command from another 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. From 51da747809ff039d5d294f493f13cd726cd4fbc3 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 11 Jan 2023 18:05:07 -0800 Subject: [PATCH 19/22] Add note about database requirements when running Dusk tests --- TESTING.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/TESTING.md b/TESTING.md index a1706177a9..8a430d498e 100644 --- a/TESTING.md +++ b/TESTING.md @@ -50,6 +50,8 @@ Before attempting to run Dusk tests copy the example environment file for Dusk a `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 configured and up and running in order for the browser From e6dc61d2cffe712f9f0a77b78eed83f84ed7f5f1 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 23 Jan 2023 15:42:05 -0800 Subject: [PATCH 20/22] Revert column names to legacy versions in down method --- ...357_fix_utf8_custom_field_column_names.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) 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'); From 760844de6fb252bd7f979d8eaa6fa3a92283caf2 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 23 Jan 2023 15:42:33 -0800 Subject: [PATCH 21/22] Add conditionals --- .../2015_09_22_003413_migrate_mac_address.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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 8167e28adf..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_1 mac_address varchar(255)'); + + if (Schema::hasColumn('assets', '_snipeit_mac_address')) { + DB::statement('ALTER TABLE assets CHANGE _snipeit_mac_address mac_address varchar(255)'); + } } } From cd582be851b6dff9d1c3135ff3c0a7d79519ecae Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 23 Jan 2023 15:42:45 -0800 Subject: [PATCH 22/22] Drop tables that may exist in down methods --- ...2_12_06_225929_migration_cartalyst_sentry_install_groups.php | 1 + .../migrations/2013_11_25_031458_create_license_seats_table.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) 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 49242f2e30..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 @@ -46,5 +46,6 @@ class MigrationCartalystSentryInstallGroups extends Migration { // 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_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'); } }