From f767cc082f20c16237a4241943b5c704dfaf73e2 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 6 Apr 2023 17:27:18 -0700 Subject: [PATCH 01/23] Introduce improved way to interact with settings in tests --- app/Observers/SettingObserver.php | 1 + database/factories/SettingFactory.php | 9 ------ tests/Feature/Api/Assets/AssetIndexTest.php | 3 -- .../Api/Users/UsersForSelectListTest.php | 7 ++--- tests/Support/Settings.php | 30 +++++++++++++++++++ tests/TestCase.php | 8 +++-- 6 files changed, 38 insertions(+), 20 deletions(-) create mode 100644 tests/Support/Settings.php diff --git a/app/Observers/SettingObserver.php b/app/Observers/SettingObserver.php index ec9dec3f2..350249f57 100644 --- a/app/Observers/SettingObserver.php +++ b/app/Observers/SettingObserver.php @@ -17,5 +17,6 @@ class SettingObserver public function saved(Setting $setting) { Cache::forget(Setting::SETUP_CHECK_KEY); + Setting::$_cache = null; } } diff --git a/database/factories/SettingFactory.php b/database/factories/SettingFactory.php index 970d00cd6..1655bd335 100644 --- a/database/factories/SettingFactory.php +++ b/database/factories/SettingFactory.php @@ -34,13 +34,4 @@ class SettingFactory extends Factory 'email_domain' => 'test.com', ]; } - - public function withMultipleFullCompanySupport() - { - return $this->state(function () { - return [ - 'full_multiple_companies_support' => 1, - ]; - }); - } } diff --git a/tests/Feature/Api/Assets/AssetIndexTest.php b/tests/Feature/Api/Assets/AssetIndexTest.php index 2190c791f..2bb54b809 100644 --- a/tests/Feature/Api/Assets/AssetIndexTest.php +++ b/tests/Feature/Api/Assets/AssetIndexTest.php @@ -3,7 +3,6 @@ namespace Tests\Feature\Api\Assets; use App\Models\Asset; -use App\Models\Setting; use App\Models\User; use Illuminate\Testing\Fluent\AssertableJson; use Laravel\Passport\Passport; @@ -13,8 +12,6 @@ class AssetIndexTest extends TestCase { public function testAssetIndexReturnsExpectedAssets() { - Setting::factory()->create(); - Asset::factory()->count(3)->create(); Passport::actingAs(User::factory()->superuser()->create()); diff --git a/tests/Feature/Api/Users/UsersForSelectListTest.php b/tests/Feature/Api/Users/UsersForSelectListTest.php index 8b2c01bcf..71e094b66 100644 --- a/tests/Feature/Api/Users/UsersForSelectListTest.php +++ b/tests/Feature/Api/Users/UsersForSelectListTest.php @@ -3,7 +3,6 @@ namespace Tests\Feature\Api\Users; use App\Models\Company; -use App\Models\Setting; use App\Models\User; use Illuminate\Testing\Fluent\AssertableJson; use Laravel\Passport\Passport; @@ -13,8 +12,6 @@ class UsersForSelectListTest extends TestCase { public function testUsersAreReturned() { - Setting::factory()->create(); - $users = User::factory()->superuser()->count(3)->create(); Passport::actingAs($users->first()); @@ -32,7 +29,7 @@ class UsersForSelectListTest extends TestCase public function testUsersScopedToCompanyWhenMultipleFullCompanySupportEnabled() { - Setting::factory()->withMultipleFullCompanySupport()->create(); + $this->settings->enableMultipleFullCompanySupport(); $jedi = Company::factory()->has(User::factory()->count(3)->sequence( ['first_name' => 'Luke', 'last_name' => 'Skywalker', 'username' => 'lskywalker'], @@ -60,7 +57,7 @@ class UsersForSelectListTest extends TestCase public function testUsersScopedToCompanyDuringSearchWhenMultipleFullCompanySupportEnabled() { - Setting::factory()->withMultipleFullCompanySupport()->create(); + $this->settings->enableMultipleFullCompanySupport(); $jedi = Company::factory()->has(User::factory()->count(3)->sequence( ['first_name' => 'Luke', 'last_name' => 'Skywalker', 'username' => 'lskywalker'], diff --git a/tests/Support/Settings.php b/tests/Support/Settings.php new file mode 100644 index 000000000..6e9d492c3 --- /dev/null +++ b/tests/Support/Settings.php @@ -0,0 +1,30 @@ +setting = Setting::factory()->create(); + } + + public function enableMultipleFullCompanySupport() + { + $this->update(['full_multiple_companies_support' => 1]); + } + + public function disableMultipleFullCompanySupport() + { + $this->update(['full_multiple_companies_support' => 0]); + } + + private function update(array $attributes) + { + Setting::unguarded(fn() => $this->setting->update($attributes)); + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php index efa533b8c..cc8d36105 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,15 +3,17 @@ namespace Tests; use App\Http\Middleware\SecurityHeaders; -use App\Models\Setting; use Illuminate\Foundation\Testing\LazilyRefreshDatabase; use Illuminate\Foundation\Testing\TestCase as BaseTestCase; +use Tests\Support\Settings; abstract class TestCase extends BaseTestCase { use CreatesApplication; use LazilyRefreshDatabase; + protected Settings $settings; + private array $globallyDisabledMiddleware = [ SecurityHeaders::class, ]; @@ -20,8 +22,8 @@ abstract class TestCase extends BaseTestCase { parent::setUp(); - $this->beforeApplicationDestroyed(fn() => Setting::$_cache = null); - $this->withoutMiddleware($this->globallyDisabledMiddleware); + + $this->settings = new Settings(); } } From bbfb6c338a60fa3063a3a493ce791a39f9904573 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 6 Apr 2023 17:28:16 -0700 Subject: [PATCH 02/23] Remove unused method --- tests/Support/Settings.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/Support/Settings.php b/tests/Support/Settings.php index 6e9d492c3..bef9378c7 100644 --- a/tests/Support/Settings.php +++ b/tests/Support/Settings.php @@ -18,11 +18,6 @@ class Settings $this->update(['full_multiple_companies_support' => 1]); } - public function disableMultipleFullCompanySupport() - { - $this->update(['full_multiple_companies_support' => 0]); - } - private function update(array $attributes) { Setting::unguarded(fn() => $this->setting->update($attributes)); From 8ac4d3aeea1e778fb5a8f7206ee9bf27df79f399 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 6 Apr 2023 17:42:15 -0700 Subject: [PATCH 03/23] Move to a static constructor --- tests/Support/Settings.php | 7 ++++++- tests/TestCase.php | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/Support/Settings.php b/tests/Support/Settings.php index bef9378c7..55ca6edc4 100644 --- a/tests/Support/Settings.php +++ b/tests/Support/Settings.php @@ -8,11 +8,16 @@ class Settings { private Setting $setting; - public function __construct() + private function __construct() { $this->setting = Setting::factory()->create(); } + public static function initialize() + { + return new self(); + } + public function enableMultipleFullCompanySupport() { $this->update(['full_multiple_companies_support' => 1]); diff --git a/tests/TestCase.php b/tests/TestCase.php index cc8d36105..6ab34ba48 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -24,6 +24,6 @@ abstract class TestCase extends BaseTestCase $this->withoutMiddleware($this->globallyDisabledMiddleware); - $this->settings = new Settings(); + $this->settings = Settings::initialize(); } } From 52c733b31d439ffe8de529136edd140b413fe340 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 6 Apr 2023 17:48:23 -0700 Subject: [PATCH 04/23] Add ability to set provided settings --- tests/Support/Settings.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/Support/Settings.php b/tests/Support/Settings.php index 55ca6edc4..a28819e8d 100644 --- a/tests/Support/Settings.php +++ b/tests/Support/Settings.php @@ -23,6 +23,11 @@ class Settings $this->update(['full_multiple_companies_support' => 1]); } + public function set(array $attributes) + { + $this->update($attributes); + } + private function update(array $attributes) { Setting::unguarded(fn() => $this->setting->update($attributes)); From 95f195046d09042aa7f23f733c0394fdff12dd6d Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 6 Apr 2023 17:50:24 -0700 Subject: [PATCH 05/23] Move cache flush to testing helper --- app/Observers/SettingObserver.php | 1 - tests/Support/Settings.php | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Observers/SettingObserver.php b/app/Observers/SettingObserver.php index 350249f57..ec9dec3f2 100644 --- a/app/Observers/SettingObserver.php +++ b/app/Observers/SettingObserver.php @@ -17,6 +17,5 @@ class SettingObserver public function saved(Setting $setting) { Cache::forget(Setting::SETUP_CHECK_KEY); - Setting::$_cache = null; } } diff --git a/tests/Support/Settings.php b/tests/Support/Settings.php index a28819e8d..e0b997054 100644 --- a/tests/Support/Settings.php +++ b/tests/Support/Settings.php @@ -31,5 +31,6 @@ class Settings private function update(array $attributes) { Setting::unguarded(fn() => $this->setting->update($attributes)); + Setting::$_cache = null; } } From 9561b6661389ae052403309c9fc9541480197b94 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 6 Apr 2023 17:58:53 -0700 Subject: [PATCH 06/23] Add return types and docblock --- tests/Support/Settings.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/Support/Settings.php b/tests/Support/Settings.php index e0b997054..5061c461d 100644 --- a/tests/Support/Settings.php +++ b/tests/Support/Settings.php @@ -7,28 +7,31 @@ use App\Models\Setting; class Settings { private Setting $setting; - + private function __construct() { $this->setting = Setting::factory()->create(); } - public static function initialize() + public static function initialize(): Settings { return new self(); } - public function enableMultipleFullCompanySupport() + public function enableMultipleFullCompanySupport(): void { $this->update(['full_multiple_companies_support' => 1]); } - public function set(array $attributes) + /** + * @param array $attributes Attributes to modify in the application's settings. + */ + public function set(array $attributes): void { $this->update($attributes); } - private function update(array $attributes) + private function update(array $attributes): void { Setting::unguarded(fn() => $this->setting->update($attributes)); Setting::$_cache = null; From cd0796dddadd436a71bde72939e69c54a3be7b4a Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 6 Apr 2023 18:46:29 -0700 Subject: [PATCH 07/23] Allow Settings to be chainable --- tests/Support/Settings.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/Support/Settings.php b/tests/Support/Settings.php index 5061c461d..ccf50c3ce 100644 --- a/tests/Support/Settings.php +++ b/tests/Support/Settings.php @@ -18,22 +18,24 @@ class Settings return new self(); } - public function enableMultipleFullCompanySupport(): void + public function enableMultipleFullCompanySupport(): Settings { - $this->update(['full_multiple_companies_support' => 1]); + return $this->update(['full_multiple_companies_support' => 1]); } /** * @param array $attributes Attributes to modify in the application's settings. */ - public function set(array $attributes): void + public function set(array $attributes): Settings { - $this->update($attributes); + return $this->update($attributes); } - private function update(array $attributes): void + private function update(array $attributes): Settings { Setting::unguarded(fn() => $this->setting->update($attributes)); Setting::$_cache = null; + + return $this; } } From 7c95e4517876bab8e800f15fd73257e2db51ba8d Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 12 Apr 2023 17:28:47 -0700 Subject: [PATCH 08/23] Introduce trait to conditionally interact with settings --- tests/Feature/Api/Assets/AssetIndexTest.php | 3 +++ tests/Feature/Api/Users/UsersForSelectListTest.php | 3 +++ tests/Support/InteractsWithSettings.php | 8 ++++++++ tests/TestCase.php | 5 ++++- 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 tests/Support/InteractsWithSettings.php diff --git a/tests/Feature/Api/Assets/AssetIndexTest.php b/tests/Feature/Api/Assets/AssetIndexTest.php index 2bb54b809..3618c6e01 100644 --- a/tests/Feature/Api/Assets/AssetIndexTest.php +++ b/tests/Feature/Api/Assets/AssetIndexTest.php @@ -6,10 +6,13 @@ use App\Models\Asset; use App\Models\User; use Illuminate\Testing\Fluent\AssertableJson; use Laravel\Passport\Passport; +use Tests\Support\InteractsWithSettings; use Tests\TestCase; class AssetIndexTest extends TestCase { + use InteractsWithSettings; + public function testAssetIndexReturnsExpectedAssets() { Asset::factory()->count(3)->create(); diff --git a/tests/Feature/Api/Users/UsersForSelectListTest.php b/tests/Feature/Api/Users/UsersForSelectListTest.php index 71e094b66..6ab5bf9a8 100644 --- a/tests/Feature/Api/Users/UsersForSelectListTest.php +++ b/tests/Feature/Api/Users/UsersForSelectListTest.php @@ -6,10 +6,13 @@ use App\Models\Company; use App\Models\User; use Illuminate\Testing\Fluent\AssertableJson; use Laravel\Passport\Passport; +use Tests\Support\InteractsWithSettings; use Tests\TestCase; class UsersForSelectListTest extends TestCase { + use InteractsWithSettings; + public function testUsersAreReturned() { $users = User::factory()->superuser()->count(3)->create(); diff --git a/tests/Support/InteractsWithSettings.php b/tests/Support/InteractsWithSettings.php new file mode 100644 index 000000000..0a7a9c53b --- /dev/null +++ b/tests/Support/InteractsWithSettings.php @@ -0,0 +1,8 @@ +withoutMiddleware($this->globallyDisabledMiddleware); - $this->settings = Settings::initialize(); + if (in_array(InteractsWithSettings::class, class_uses_recursive($this))) { + $this->settings = Settings::initialize(); + } } } From 6eed89df9108f9a0a158239ac11da62951197aa8 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 13 Apr 2023 11:03:26 -0700 Subject: [PATCH 09/23] Added components and consumables tab to suppliers Signed-off-by: snipe --- resources/views/suppliers/view.blade.php | 77 ++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/resources/views/suppliers/view.blade.php b/resources/views/suppliers/view.blade.php index 1cf95cfe4..9024bd927 100755 --- a/resources/views/suppliers/view.blade.php +++ b/resources/views/suppliers/view.blade.php @@ -65,6 +65,30 @@ +
  • + + + + +
  • + +
  • + + + + +
  • +