From 42095c0167b661d0f7a996a3bd17e0c0cfac5750 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 15 Oct 2024 13:02:22 -0700 Subject: [PATCH 01/17] Add reference link --- tests/Feature/Assets/Api/StoreAssetTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/Feature/Assets/Api/StoreAssetTest.php b/tests/Feature/Assets/Api/StoreAssetTest.php index a147504519..ea5cfb6178 100644 --- a/tests/Feature/Assets/Api/StoreAssetTest.php +++ b/tests/Feature/Assets/Api/StoreAssetTest.php @@ -560,6 +560,9 @@ class StoreAssetTest extends TestCase $this->assertTrue($asset->assignedAssets()->find($response['payload']['id'])->is($apiAsset)); } + /** + * @link https://app.shortcut.com/grokability/story/24475 + */ public function testCompanyIdNeedsToBeInteger() { $this->actingAsForApi(User::factory()->createAssets()->create()) From d9afde4610dd0527fb19fd52093f2d654ce36430 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 15 Oct 2024 17:00:22 -0700 Subject: [PATCH 02/17] Write failing test --- tests/Feature/Assets/Api/StoreAssetTest.php | 47 +++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/Feature/Assets/Api/StoreAssetTest.php b/tests/Feature/Assets/Api/StoreAssetTest.php index ea5cfb6178..12c6d5e858 100644 --- a/tests/Feature/Assets/Api/StoreAssetTest.php +++ b/tests/Feature/Assets/Api/StoreAssetTest.php @@ -23,6 +23,53 @@ class StoreAssetTest extends TestCase ->assertForbidden(); } + /** + * @link https://github.com/snipe/snipe-it/issues/15654 + */ + public function testAdheresToFullMultipleCompaniesSupportScoping() + { + [$companyA, $companyB] = Company::factory()->count(2)->create(); + $model = AssetModel::factory()->create(); + $status = Statuslabel::factory()->readyToDeploy()->create(); + + $userInNoCompany = User::factory() + ->createAssets() + ->create(['company_id' => null]); + + $userInCompanyA = User::factory() + ->for($companyA) + ->createAssets() + ->create(); + + $this->assertNull($userInNoCompany->company_id); + $this->assertEquals($companyA->id, $userInCompanyA->company_id); + + $this->settings->enableMultipleFullCompanySupport(); + + $responseForUserWithNoCompany = $this->actingAsForApi($userInNoCompany) + ->postJson(route('api.assets.store'), [ + 'asset_tag' => 'random_string', + 'company_id' => $companyB->id, + 'model_id' => $model->id, + 'status_id' => $status->id, + ]); + + $responseForUserInCompanyA = $this->actingAsForApi($userInCompanyA) + ->postJson(route('api.assets.store'), [ + 'asset_tag' => 'another_string', + 'company_id' => $companyB->id, + 'model_id' => $model->id, + 'status_id' => $status->id, + ]); + + $assetForUserWithNoCompany = Asset::withoutGlobalScopes()->find($responseForUserWithNoCompany['payload']['id']); + $assetForUserInCompanyA = Asset::withoutGlobalScopes()->find($responseForUserInCompanyA['payload']['id']); + + // company_id should be the company_id of the user that performed the action + $this->assertNull($assetForUserWithNoCompany->company_id); + $this->assertEquals($userInCompanyA->company_id, $assetForUserInCompanyA->company_id); + } + public function testAllAssetAttributesAreStored() { $company = Company::factory()->create(); From cba1a560408c821c4112a2548a6df20755536efd Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 15 Oct 2024 17:38:11 -0700 Subject: [PATCH 03/17] Improve readability? --- tests/Feature/Assets/Api/StoreAssetTest.php | 77 ++++++++++++--------- 1 file changed, 44 insertions(+), 33 deletions(-) diff --git a/tests/Feature/Assets/Api/StoreAssetTest.php b/tests/Feature/Assets/Api/StoreAssetTest.php index 12c6d5e858..8d648b835d 100644 --- a/tests/Feature/Assets/Api/StoreAssetTest.php +++ b/tests/Feature/Assets/Api/StoreAssetTest.php @@ -10,8 +10,10 @@ use App\Models\Location; use App\Models\Statuslabel; use App\Models\Supplier; use App\Models\User; +use Generator; use Illuminate\Support\Facades\Crypt; use Illuminate\Testing\Fluent\AssertableJson; +use PHPUnit\Framework\Attributes\DataProvider; use Tests\TestCase; class StoreAssetTest extends TestCase @@ -23,51 +25,60 @@ class StoreAssetTest extends TestCase ->assertForbidden(); } + public static function userProvider(): Generator + { + yield 'User in a company' => [ + function () { + $jedi = Company::factory()->create(); + $sith = Company::factory()->create(); + $luke = User::factory()->for($jedi)->createAssets()->create(); + + return [ + 'actor' => $luke, + 'company_attempting_to_associate' => $sith, + 'assertions' => function ($asset) use ($jedi) { + self::assertEquals($jedi->id, $asset->company_id); + }, + ]; + } + ]; + + yield 'User without a company' => [ + function () { + $userInNoCompany = User::factory()->createAssets()->create(['company_id' => null]); + + return [ + 'actor' => $userInNoCompany, + 'company_attempting_to_associate' => Company::factory()->create(), + 'assertions' => function ($asset) { + self::assertNull($asset->company_id); + }, + ]; + } + ]; + } + /** * @link https://github.com/snipe/snipe-it/issues/15654 */ - public function testAdheresToFullMultipleCompaniesSupportScoping() + #[DataProvider('userProvider')] + public function testAdheresToFullMultipleCompaniesSupportScoping($data) { - [$companyA, $companyB] = Company::factory()->count(2)->create(); - $model = AssetModel::factory()->create(); - $status = Statuslabel::factory()->readyToDeploy()->create(); - - $userInNoCompany = User::factory() - ->createAssets() - ->create(['company_id' => null]); - - $userInCompanyA = User::factory() - ->for($companyA) - ->createAssets() - ->create(); - - $this->assertNull($userInNoCompany->company_id); - $this->assertEquals($companyA->id, $userInCompanyA->company_id); + ['actor' => $actor, 'company_attempting_to_associate' => $company, 'assertions' => $assertions] = $data(); $this->settings->enableMultipleFullCompanySupport(); - $responseForUserWithNoCompany = $this->actingAsForApi($userInNoCompany) + $response = $this->actingAsForApi($actor) ->postJson(route('api.assets.store'), [ 'asset_tag' => 'random_string', - 'company_id' => $companyB->id, - 'model_id' => $model->id, - 'status_id' => $status->id, + 'company_id' => $company->id, + 'model_id' => AssetModel::factory()->create()->id, + 'status_id' => Statuslabel::factory()->readyToDeploy()->create()->id, ]); - $responseForUserInCompanyA = $this->actingAsForApi($userInCompanyA) - ->postJson(route('api.assets.store'), [ - 'asset_tag' => 'another_string', - 'company_id' => $companyB->id, - 'model_id' => $model->id, - 'status_id' => $status->id, - ]); + $asset = Asset::withoutGlobalScopes()->findOrFail($response['payload']['id']); - $assetForUserWithNoCompany = Asset::withoutGlobalScopes()->find($responseForUserWithNoCompany['payload']['id']); - $assetForUserInCompanyA = Asset::withoutGlobalScopes()->find($responseForUserInCompanyA['payload']['id']); - - // company_id should be the company_id of the user that performed the action - $this->assertNull($assetForUserWithNoCompany->company_id); - $this->assertEquals($userInCompanyA->company_id, $assetForUserInCompanyA->company_id); + $assertions($asset); } public function testAllAssetAttributesAreStored() From 2f72c66614676efd205585e25d909424b136d869 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 16 Oct 2024 11:30:06 -0700 Subject: [PATCH 04/17] Add additional case --- tests/Feature/Assets/Api/StoreAssetTest.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/Feature/Assets/Api/StoreAssetTest.php b/tests/Feature/Assets/Api/StoreAssetTest.php index 8d648b835d..118ccee406 100644 --- a/tests/Feature/Assets/Api/StoreAssetTest.php +++ b/tests/Feature/Assets/Api/StoreAssetTest.php @@ -56,6 +56,21 @@ class StoreAssetTest extends TestCase ]; } ]; + + yield 'Super-User assigning across companies' => [ + function () { + $superUser = User::factory()->superuser()->create(); + $company = Company::factory()->create(); + + return [ + 'actor' => $superUser, + 'company_attempting_to_associate' => $company, + 'assertions' => function ($asset) use ($company) { + self::assertEquals($asset->company_id, $company->id); + }, + ]; + } + ]; } /** From 604a9644624a52cd1aa965d92d36aa936840265d Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 16 Oct 2024 11:52:24 -0700 Subject: [PATCH 05/17] Improve scenario descriptions --- tests/Feature/Assets/Api/StoreAssetTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Feature/Assets/Api/StoreAssetTest.php b/tests/Feature/Assets/Api/StoreAssetTest.php index 118ccee406..95b73520bf 100644 --- a/tests/Feature/Assets/Api/StoreAssetTest.php +++ b/tests/Feature/Assets/Api/StoreAssetTest.php @@ -27,7 +27,7 @@ class StoreAssetTest extends TestCase public static function userProvider(): Generator { - yield 'User in a company' => [ + yield "User in a company should result in user's company_id being used" => [ function () { $jedi = Company::factory()->create(); $sith = Company::factory()->create(); @@ -43,7 +43,7 @@ class StoreAssetTest extends TestCase } ]; - yield 'User without a company' => [ + yield "User without a company should result in asset's company_id being null" => [ function () { $userInNoCompany = User::factory()->createAssets()->create(['company_id' => null]); @@ -57,7 +57,7 @@ class StoreAssetTest extends TestCase } ]; - yield 'Super-User assigning across companies' => [ + yield "Super-User assigning across companies should result in asset's company_id being set to what was provided" => [ function () { $superUser = User::factory()->superuser()->create(); $company = Company::factory()->create(); From 159a1d3f4356141844767c2c2593252b98df3b11 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 17 Oct 2024 11:48:55 -0700 Subject: [PATCH 06/17] Be more explicit --- tests/Feature/Assets/Api/StoreAssetTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Feature/Assets/Api/StoreAssetTest.php b/tests/Feature/Assets/Api/StoreAssetTest.php index 95b73520bf..683a274c35 100644 --- a/tests/Feature/Assets/Api/StoreAssetTest.php +++ b/tests/Feature/Assets/Api/StoreAssetTest.php @@ -59,7 +59,7 @@ class StoreAssetTest extends TestCase yield "Super-User assigning across companies should result in asset's company_id being set to what was provided" => [ function () { - $superUser = User::factory()->superuser()->create(); + $superUser = User::factory()->superuser()->create(['company_id' => null]); $company = Company::factory()->create(); return [ From 50fa6ce33588f466e90829fb59e8d91411c8d736 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 17 Oct 2024 14:12:22 -0700 Subject: [PATCH 07/17] Scaffold tests --- ...soryWithFullMultipleCompanySupportTest.php | 87 ++++++++++++++++++ tests/Feature/Assets/Api/StoreAssetTest.php | 75 +--------------- ...ssetWithFullMultipleCompanySupportTest.php | 88 +++++++++++++++++++ ...ssetWithFullMultipleCompanySupportTest.php | 85 ++++++++++++++++++ 4 files changed, 262 insertions(+), 73 deletions(-) create mode 100644 tests/Feature/Accessories/Ui/CreateAccessoryWithFullMultipleCompanySupportTest.php create mode 100644 tests/Feature/Assets/Api/StoreAssetWithFullMultipleCompanySupportTest.php create mode 100644 tests/Feature/Assets/Ui/StoreAssetWithFullMultipleCompanySupportTest.php diff --git a/tests/Feature/Accessories/Ui/CreateAccessoryWithFullMultipleCompanySupportTest.php b/tests/Feature/Accessories/Ui/CreateAccessoryWithFullMultipleCompanySupportTest.php new file mode 100644 index 0000000000..02b01c6665 --- /dev/null +++ b/tests/Feature/Accessories/Ui/CreateAccessoryWithFullMultipleCompanySupportTest.php @@ -0,0 +1,87 @@ + [ + function () { + $jedi = Company::factory()->create(); + $sith = Company::factory()->create(); + $luke = User::factory()->for($jedi)->createAccessories()->create(); + + return [ + 'actor' => $luke, + 'company_attempting_to_associate' => $sith, + 'assertions' => function ($accessory) use ($jedi) { + self::assertEquals($jedi->id, $accessory->company_id); + }, + ]; + } + ]; + + yield "User without a company should result in accessory's company_id being null" => [ + function () { + $userInNoCompany = User::factory()->createAccessories()->create(['company_id' => null]); + + return [ + 'actor' => $userInNoCompany, + 'company_attempting_to_associate' => Company::factory()->create(), + 'assertions' => function ($accessory) { + self::assertNull($accessory->company_id); + }, + ]; + } + ]; + + yield "Super-User assigning across companies should result in accessory's company_id being set to what was provided" => [ + function () { + $superUser = User::factory()->superuser()->create(['company_id' => null]); + $company = Company::factory()->create(); + + return [ + 'actor' => $superUser, + 'company_attempting_to_associate' => $company, + 'assertions' => function ($accessory) use ($company) { + self::assertEquals($accessory->company_id, $company->id); + }, + ]; + } + ]; + } + + #[Group('focus')] + #[DataProvider('userProvider')] + public function testAdheresToFullMultipleCompaniesSupportScoping($data) + { + ['actor' => $actor, 'company_attempting_to_associate' => $company, 'assertions' => $assertions] = $data(); + + $this->settings->enableMultipleFullCompanySupport(); + + $this->actingAs($actor) + ->post(route('accessories.store'), [ + 'redirect_option' => 'index', + 'name' => 'My Cool Accessory', + 'qty' => '1', + 'category_id' => Category::factory()->create()->id, + 'company_id' => $company->id, + ]); + + $accessory = Accessory::withoutGlobalScopes()->where([ + 'name' => 'My Cool Accessory', + ])->sole(); + + $assertions($accessory); + } +} diff --git a/tests/Feature/Assets/Api/StoreAssetTest.php b/tests/Feature/Assets/Api/StoreAssetTest.php index 683a274c35..26fb1f78c0 100644 --- a/tests/Feature/Assets/Api/StoreAssetTest.php +++ b/tests/Feature/Assets/Api/StoreAssetTest.php @@ -10,10 +10,9 @@ use App\Models\Location; use App\Models\Statuslabel; use App\Models\Supplier; use App\Models\User; -use Generator; use Illuminate\Support\Facades\Crypt; use Illuminate\Testing\Fluent\AssertableJson; -use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use Tests\TestCase; class StoreAssetTest extends TestCase @@ -25,77 +24,6 @@ class StoreAssetTest extends TestCase ->assertForbidden(); } - public static function userProvider(): Generator - { - yield "User in a company should result in user's company_id being used" => [ - function () { - $jedi = Company::factory()->create(); - $sith = Company::factory()->create(); - $luke = User::factory()->for($jedi)->createAssets()->create(); - - return [ - 'actor' => $luke, - 'company_attempting_to_associate' => $sith, - 'assertions' => function ($asset) use ($jedi) { - self::assertEquals($jedi->id, $asset->company_id); - }, - ]; - } - ]; - - yield "User without a company should result in asset's company_id being null" => [ - function () { - $userInNoCompany = User::factory()->createAssets()->create(['company_id' => null]); - - return [ - 'actor' => $userInNoCompany, - 'company_attempting_to_associate' => Company::factory()->create(), - 'assertions' => function ($asset) { - self::assertNull($asset->company_id); - }, - ]; - } - ]; - - yield "Super-User assigning across companies should result in asset's company_id being set to what was provided" => [ - function () { - $superUser = User::factory()->superuser()->create(['company_id' => null]); - $company = Company::factory()->create(); - - return [ - 'actor' => $superUser, - 'company_attempting_to_associate' => $company, - 'assertions' => function ($asset) use ($company) { - self::assertEquals($asset->company_id, $company->id); - }, - ]; - } - ]; - } - - /** - * @link https://github.com/snipe/snipe-it/issues/15654 - */ - #[DataProvider('userProvider')] - public function testAdheresToFullMultipleCompaniesSupportScoping($data) - { - ['actor' => $actor, 'company_attempting_to_associate' => $company, 'assertions' => $assertions] = $data(); - - $this->settings->enableMultipleFullCompanySupport(); - - $response = $this->actingAsForApi($actor) - ->postJson(route('api.assets.store'), [ - 'asset_tag' => 'random_string', - 'company_id' => $company->id, - 'model_id' => AssetModel::factory()->create()->id, - 'status_id' => Statuslabel::factory()->readyToDeploy()->create()->id, - ]); - - $asset = Asset::withoutGlobalScopes()->findOrFail($response['payload']['id']); - - $assertions($asset); - } - public function testAllAssetAttributesAreStored() { $company = Company::factory()->create(); @@ -636,6 +564,7 @@ class StoreAssetTest extends TestCase /** * @link https://app.shortcut.com/grokability/story/24475 */ + #[Group('focus')] public function testCompanyIdNeedsToBeInteger() { $this->actingAsForApi(User::factory()->createAssets()->create()) diff --git a/tests/Feature/Assets/Api/StoreAssetWithFullMultipleCompanySupportTest.php b/tests/Feature/Assets/Api/StoreAssetWithFullMultipleCompanySupportTest.php new file mode 100644 index 0000000000..e3c4e6fe87 --- /dev/null +++ b/tests/Feature/Assets/Api/StoreAssetWithFullMultipleCompanySupportTest.php @@ -0,0 +1,88 @@ + [ + function () { + $jedi = Company::factory()->create(); + $sith = Company::factory()->create(); + $luke = User::factory()->for($jedi)->createAssets()->create(); + + return [ + 'actor' => $luke, + 'company_attempting_to_associate' => $sith, + 'assertions' => function ($asset) use ($jedi) { + self::assertEquals($jedi->id, $asset->company_id); + }, + ]; + } + ]; + + yield "User without a company should result in asset's company_id being null" => [ + function () { + $userInNoCompany = User::factory()->createAssets()->create(['company_id' => null]); + + return [ + 'actor' => $userInNoCompany, + 'company_attempting_to_associate' => Company::factory()->create(), + 'assertions' => function ($asset) { + self::assertNull($asset->company_id); + }, + ]; + } + ]; + + yield "Super-User assigning across companies should result in asset's company_id being set to what was provided" => [ + function () { + $superUser = User::factory()->superuser()->create(['company_id' => null]); + $company = Company::factory()->create(); + + return [ + 'actor' => $superUser, + 'company_attempting_to_associate' => $company, + 'assertions' => function ($asset) use ($company) { + self::assertEquals($asset->company_id, $company->id); + }, + ]; + } + ]; + } + + /** + * @link https://github.com/snipe/snipe-it/issues/15654 + */ + #[Group('focus')] + #[DataProvider('userProvider')] + public function testAdheresToFullMultipleCompaniesSupportScoping($data) + { + ['actor' => $actor, 'company_attempting_to_associate' => $company, 'assertions' => $assertions] = $data(); + + $this->settings->enableMultipleFullCompanySupport(); + + $response = $this->actingAsForApi($actor) + ->postJson(route('api.assets.store'), [ + 'asset_tag' => 'random_string', + 'company_id' => $company->id, + 'model_id' => AssetModel::factory()->create()->id, + 'status_id' => Statuslabel::factory()->readyToDeploy()->create()->id, + ]); + + $asset = Asset::withoutGlobalScopes()->findOrFail($response['payload']['id']); + + $assertions($asset); + } +} diff --git a/tests/Feature/Assets/Ui/StoreAssetWithFullMultipleCompanySupportTest.php b/tests/Feature/Assets/Ui/StoreAssetWithFullMultipleCompanySupportTest.php new file mode 100644 index 0000000000..6c15e4ada3 --- /dev/null +++ b/tests/Feature/Assets/Ui/StoreAssetWithFullMultipleCompanySupportTest.php @@ -0,0 +1,85 @@ + [ + function () { + $jedi = Company::factory()->create(); + $sith = Company::factory()->create(); + $luke = User::factory()->for($jedi)->createAssets()->create(); + + return [ + 'actor' => $luke, + 'company_attempting_to_associate' => $sith, + 'assertions' => function ($asset) use ($jedi) { + self::assertEquals($jedi->id, $asset->company_id); + }, + ]; + } + ]; + + yield "User without a company should result in asset's company_id being null" => [ + function () { + $userInNoCompany = User::factory()->createAssets()->create(['company_id' => null]); + + return [ + 'actor' => $userInNoCompany, + 'company_attempting_to_associate' => Company::factory()->create(), + 'assertions' => function ($asset) { + self::assertNull($asset->company_id); + }, + ]; + } + ]; + + yield "Super-User assigning across companies should result in asset's company_id being set to what was provided" => [ + function () { + $superUser = User::factory()->superuser()->create(['company_id' => null]); + $company = Company::factory()->create(); + + return [ + 'actor' => $superUser, + 'company_attempting_to_associate' => $company, + 'assertions' => function ($asset) use ($company) { + self::assertEquals($asset->company_id, $company->id); + }, + ]; + } + ]; + } + + #[Group('focus')] + #[DataProvider('userProvider')] + public function testAdheresToFullMultipleCompaniesSupportScoping($data) + { + ['actor' => $actor, 'company_attempting_to_associate' => $company, 'assertions' => $assertions] = $data(); + + $this->settings->enableMultipleFullCompanySupport(); + + $this->actingAs($actor) + ->post(route('hardware.store'), [ + 'asset_tags' => ['1' => '1234'], + 'model_id' => AssetModel::factory()->create()->id, + 'status_id' => Statuslabel::factory()->create()->id, + 'company_id' => $company->id, + ]); + + $asset = Asset::where('asset_tag', '1234')->sole(); + + $assertions($asset); + } +} From 15c2169477e9691216d9f3fc2b8b8ddd2d8ee21a Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 17 Oct 2024 14:31:05 -0700 Subject: [PATCH 08/17] Scaffold additional tests --- ...soryWithFullMultipleCompanySupportTest.php | 52 +------------- ...ssetWithFullMultipleCompanySupportTest.php | 52 +------------- ...ssetWithFullMultipleCompanySupportTest.php | 52 +------------- ...nentWithFullMultipleCompanySupportTest.php | 36 ++++++++++ ...ableWithFullMultipleCompanySupportTest.php | 35 ++++++++++ ...enseWithFullMultipleCompanySupportTest.php | 36 ++++++++++ ...taForFullMultipleCompanySupportTesting.php | 70 +++++++++++++++++++ 7 files changed, 183 insertions(+), 150 deletions(-) create mode 100644 tests/Feature/Components/Ui/StoreComponentWithFullMultipleCompanySupportTest.php create mode 100644 tests/Feature/Consumables/Ui/StoreConsumableWithFullMultipleCompanySupportTest.php create mode 100644 tests/Feature/Licenses/Ui/StoreLicenseWithFullMultipleCompanySupportTest.php create mode 100644 tests/Support/ProvidesDataForFullMultipleCompanySupportTesting.php diff --git a/tests/Feature/Accessories/Ui/CreateAccessoryWithFullMultipleCompanySupportTest.php b/tests/Feature/Accessories/Ui/CreateAccessoryWithFullMultipleCompanySupportTest.php index 02b01c6665..42a393e2f8 100644 --- a/tests/Feature/Accessories/Ui/CreateAccessoryWithFullMultipleCompanySupportTest.php +++ b/tests/Feature/Accessories/Ui/CreateAccessoryWithFullMultipleCompanySupportTest.php @@ -4,62 +4,14 @@ namespace Tests\Feature\Accessories\Ui; use App\Models\Accessory; use App\Models\Category; -use App\Models\Company; -use App\Models\User; -use Generator; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Group; +use Tests\Support\ProvidesDataForFullMultipleCompanySupportTesting; use Tests\TestCase; class CreateAccessoryWithFullMultipleCompanySupportTest extends TestCase { - public static function userProvider(): Generator - { - yield "User in a company should result in user's company_id being used" => [ - function () { - $jedi = Company::factory()->create(); - $sith = Company::factory()->create(); - $luke = User::factory()->for($jedi)->createAccessories()->create(); - - return [ - 'actor' => $luke, - 'company_attempting_to_associate' => $sith, - 'assertions' => function ($accessory) use ($jedi) { - self::assertEquals($jedi->id, $accessory->company_id); - }, - ]; - } - ]; - - yield "User without a company should result in accessory's company_id being null" => [ - function () { - $userInNoCompany = User::factory()->createAccessories()->create(['company_id' => null]); - - return [ - 'actor' => $userInNoCompany, - 'company_attempting_to_associate' => Company::factory()->create(), - 'assertions' => function ($accessory) { - self::assertNull($accessory->company_id); - }, - ]; - } - ]; - - yield "Super-User assigning across companies should result in accessory's company_id being set to what was provided" => [ - function () { - $superUser = User::factory()->superuser()->create(['company_id' => null]); - $company = Company::factory()->create(); - - return [ - 'actor' => $superUser, - 'company_attempting_to_associate' => $company, - 'assertions' => function ($accessory) use ($company) { - self::assertEquals($accessory->company_id, $company->id); - }, - ]; - } - ]; - } + use ProvidesDataForFullMultipleCompanySupportTesting; #[Group('focus')] #[DataProvider('userProvider')] diff --git a/tests/Feature/Assets/Api/StoreAssetWithFullMultipleCompanySupportTest.php b/tests/Feature/Assets/Api/StoreAssetWithFullMultipleCompanySupportTest.php index e3c4e6fe87..186355c32a 100644 --- a/tests/Feature/Assets/Api/StoreAssetWithFullMultipleCompanySupportTest.php +++ b/tests/Feature/Assets/Api/StoreAssetWithFullMultipleCompanySupportTest.php @@ -4,63 +4,15 @@ namespace Tests\Feature\Assets\Api; use App\Models\Asset; use App\Models\AssetModel; -use App\Models\Company; use App\Models\Statuslabel; -use App\Models\User; -use Generator; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Group; +use Tests\Support\ProvidesDataForFullMultipleCompanySupportTesting; use Tests\TestCase; class StoreAssetWithFullMultipleCompanySupportTest extends TestCase { - public static function userProvider(): Generator - { - yield "User in a company should result in user's company_id being used" => [ - function () { - $jedi = Company::factory()->create(); - $sith = Company::factory()->create(); - $luke = User::factory()->for($jedi)->createAssets()->create(); - - return [ - 'actor' => $luke, - 'company_attempting_to_associate' => $sith, - 'assertions' => function ($asset) use ($jedi) { - self::assertEquals($jedi->id, $asset->company_id); - }, - ]; - } - ]; - - yield "User without a company should result in asset's company_id being null" => [ - function () { - $userInNoCompany = User::factory()->createAssets()->create(['company_id' => null]); - - return [ - 'actor' => $userInNoCompany, - 'company_attempting_to_associate' => Company::factory()->create(), - 'assertions' => function ($asset) { - self::assertNull($asset->company_id); - }, - ]; - } - ]; - - yield "Super-User assigning across companies should result in asset's company_id being set to what was provided" => [ - function () { - $superUser = User::factory()->superuser()->create(['company_id' => null]); - $company = Company::factory()->create(); - - return [ - 'actor' => $superUser, - 'company_attempting_to_associate' => $company, - 'assertions' => function ($asset) use ($company) { - self::assertEquals($asset->company_id, $company->id); - }, - ]; - } - ]; - } + use ProvidesDataForFullMultipleCompanySupportTesting; /** * @link https://github.com/snipe/snipe-it/issues/15654 diff --git a/tests/Feature/Assets/Ui/StoreAssetWithFullMultipleCompanySupportTest.php b/tests/Feature/Assets/Ui/StoreAssetWithFullMultipleCompanySupportTest.php index 6c15e4ada3..183ad20a5f 100644 --- a/tests/Feature/Assets/Ui/StoreAssetWithFullMultipleCompanySupportTest.php +++ b/tests/Feature/Assets/Ui/StoreAssetWithFullMultipleCompanySupportTest.php @@ -4,63 +4,15 @@ namespace Tests\Feature\Assets\Ui; use App\Models\Asset; use App\Models\AssetModel; -use App\Models\Company; use App\Models\Statuslabel; -use App\Models\User; -use Generator; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Group; +use Tests\Support\ProvidesDataForFullMultipleCompanySupportTesting; use Tests\TestCase; class StoreAssetWithFullMultipleCompanySupportTest extends TestCase { - public static function userProvider(): Generator - { - yield "User in a company should result in user's company_id being used" => [ - function () { - $jedi = Company::factory()->create(); - $sith = Company::factory()->create(); - $luke = User::factory()->for($jedi)->createAssets()->create(); - - return [ - 'actor' => $luke, - 'company_attempting_to_associate' => $sith, - 'assertions' => function ($asset) use ($jedi) { - self::assertEquals($jedi->id, $asset->company_id); - }, - ]; - } - ]; - - yield "User without a company should result in asset's company_id being null" => [ - function () { - $userInNoCompany = User::factory()->createAssets()->create(['company_id' => null]); - - return [ - 'actor' => $userInNoCompany, - 'company_attempting_to_associate' => Company::factory()->create(), - 'assertions' => function ($asset) { - self::assertNull($asset->company_id); - }, - ]; - } - ]; - - yield "Super-User assigning across companies should result in asset's company_id being set to what was provided" => [ - function () { - $superUser = User::factory()->superuser()->create(['company_id' => null]); - $company = Company::factory()->create(); - - return [ - 'actor' => $superUser, - 'company_attempting_to_associate' => $company, - 'assertions' => function ($asset) use ($company) { - self::assertEquals($asset->company_id, $company->id); - }, - ]; - } - ]; - } + use ProvidesDataForFullMultipleCompanySupportTesting; #[Group('focus')] #[DataProvider('userProvider')] diff --git a/tests/Feature/Components/Ui/StoreComponentWithFullMultipleCompanySupportTest.php b/tests/Feature/Components/Ui/StoreComponentWithFullMultipleCompanySupportTest.php new file mode 100644 index 0000000000..7abd762205 --- /dev/null +++ b/tests/Feature/Components/Ui/StoreComponentWithFullMultipleCompanySupportTest.php @@ -0,0 +1,36 @@ + $actor, 'company_attempting_to_associate' => $company, 'assertions' => $assertions] = $data(); + + $this->settings->enableMultipleFullCompanySupport(); + + $this->actingAs($actor) + ->post(route('components.store'), [ + 'name' => 'My Cool Component', + 'qty' => '1', + 'category_id' => Category::factory()->create()->id, + 'company_id' => $company->id, + ]); + + $component = Component::where('name', 'My Cool Component')->sole(); + + $assertions($component); + } +} diff --git a/tests/Feature/Consumables/Ui/StoreConsumableWithFullMultipleCompanySupportTest.php b/tests/Feature/Consumables/Ui/StoreConsumableWithFullMultipleCompanySupportTest.php new file mode 100644 index 0000000000..fb9ab1e3b4 --- /dev/null +++ b/tests/Feature/Consumables/Ui/StoreConsumableWithFullMultipleCompanySupportTest.php @@ -0,0 +1,35 @@ + $actor, 'company_attempting_to_associate' => $company, 'assertions' => $assertions] = $data(); + + $this->settings->enableMultipleFullCompanySupport(); + + $this->actingAs($actor) + ->post(route('consumables.store'), [ + 'name' => 'My Cool Consumable', + 'category_id' => Category::factory()->forConsumables()->create()->id, + 'company_id' => $company->id, + ]); + + $consumable = Consumable::where('name', 'My Cool Consumable')->sole(); + + $assertions($consumable); + } +} diff --git a/tests/Feature/Licenses/Ui/StoreLicenseWithFullMultipleCompanySupportTest.php b/tests/Feature/Licenses/Ui/StoreLicenseWithFullMultipleCompanySupportTest.php new file mode 100644 index 0000000000..dcb827a842 --- /dev/null +++ b/tests/Feature/Licenses/Ui/StoreLicenseWithFullMultipleCompanySupportTest.php @@ -0,0 +1,36 @@ + $actor, 'company_attempting_to_associate' => $company, 'assertions' => $assertions] = $data(); + + $this->settings->enableMultipleFullCompanySupport(); + + $this->actingAs($actor) + ->post(route('licenses.store'), [ + 'name' => 'My Cool License', + 'seats' => '1', + 'category_id' => Category::factory()->forLicenses()->create()->id, + 'company_id' => $company->id, + ]); + + $license = License::where('name', 'My Cool License')->sole(); + + $assertions($license); + } +} diff --git a/tests/Support/ProvidesDataForFullMultipleCompanySupportTesting.php b/tests/Support/ProvidesDataForFullMultipleCompanySupportTesting.php new file mode 100644 index 0000000000..fad4c2ae7b --- /dev/null +++ b/tests/Support/ProvidesDataForFullMultipleCompanySupportTesting.php @@ -0,0 +1,70 @@ + [ + function () { + $jedi = Company::factory()->create(); + $sith = Company::factory()->create(); + $luke = User::factory()->for($jedi) + ->createAccessories() + ->createAssets() + ->createComponents() + ->createConsumables() + ->createLicenses() + ->create(); + + return [ + 'actor' => $luke, + 'company_attempting_to_associate' => $sith, + 'assertions' => function ($model) use ($jedi) { + self::assertEquals($jedi->id, $model->company_id); + }, + ]; + } + ]; + + yield "User without a company should result in company_id being null" => [ + function () { + $userInNoCompany = User::factory() + ->createAccessories() + ->createAssets() + ->createComponents() + ->createConsumables() + ->createLicenses() + ->create(['company_id' => null]); + + return [ + 'actor' => $userInNoCompany, + 'company_attempting_to_associate' => Company::factory()->create(), + 'assertions' => function ($model) { + self::assertNull($model->company_id); + }, + ]; + } + ]; + + yield "Super-User assigning across companies should result in company_id being set to what was provided" => [ + function () { + $superUser = User::factory()->superuser()->create(['company_id' => null]); + $company = Company::factory()->create(); + + return [ + 'actor' => $superUser, + 'company_attempting_to_associate' => $company, + 'assertions' => function ($model) use ($company) { + self::assertEquals($model->company_id, $company->id); + }, + ]; + } + ]; + } +} From 99dd51a965c7a02f8b24deddd1c233fac05f8465 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 17 Oct 2024 14:53:18 -0700 Subject: [PATCH 09/17] Improve name --- .../Ui/CreateAccessoryWithFullMultipleCompanySupportTest.php | 2 +- .../Assets/Api/StoreAssetWithFullMultipleCompanySupportTest.php | 2 +- .../Assets/Ui/StoreAssetWithFullMultipleCompanySupportTest.php | 2 +- .../Ui/StoreComponentWithFullMultipleCompanySupportTest.php | 2 +- .../Ui/StoreConsumableWithFullMultipleCompanySupportTest.php | 2 +- .../Ui/StoreLicenseWithFullMultipleCompanySupportTest.php | 2 +- .../ProvidesDataForFullMultipleCompanySupportTesting.php | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/Feature/Accessories/Ui/CreateAccessoryWithFullMultipleCompanySupportTest.php b/tests/Feature/Accessories/Ui/CreateAccessoryWithFullMultipleCompanySupportTest.php index 42a393e2f8..c256830a63 100644 --- a/tests/Feature/Accessories/Ui/CreateAccessoryWithFullMultipleCompanySupportTest.php +++ b/tests/Feature/Accessories/Ui/CreateAccessoryWithFullMultipleCompanySupportTest.php @@ -14,7 +14,7 @@ class CreateAccessoryWithFullMultipleCompanySupportTest extends TestCase use ProvidesDataForFullMultipleCompanySupportTesting; #[Group('focus')] - #[DataProvider('userProvider')] + #[DataProvider('dataForFullMultipleCompanySupportTesting')] public function testAdheresToFullMultipleCompaniesSupportScoping($data) { ['actor' => $actor, 'company_attempting_to_associate' => $company, 'assertions' => $assertions] = $data(); diff --git a/tests/Feature/Assets/Api/StoreAssetWithFullMultipleCompanySupportTest.php b/tests/Feature/Assets/Api/StoreAssetWithFullMultipleCompanySupportTest.php index 186355c32a..57d09e7e13 100644 --- a/tests/Feature/Assets/Api/StoreAssetWithFullMultipleCompanySupportTest.php +++ b/tests/Feature/Assets/Api/StoreAssetWithFullMultipleCompanySupportTest.php @@ -18,7 +18,7 @@ class StoreAssetWithFullMultipleCompanySupportTest extends TestCase * @link https://github.com/snipe/snipe-it/issues/15654 */ #[Group('focus')] - #[DataProvider('userProvider')] + #[DataProvider('dataForFullMultipleCompanySupportTesting')] public function testAdheresToFullMultipleCompaniesSupportScoping($data) { ['actor' => $actor, 'company_attempting_to_associate' => $company, 'assertions' => $assertions] = $data(); diff --git a/tests/Feature/Assets/Ui/StoreAssetWithFullMultipleCompanySupportTest.php b/tests/Feature/Assets/Ui/StoreAssetWithFullMultipleCompanySupportTest.php index 183ad20a5f..b6302f95c8 100644 --- a/tests/Feature/Assets/Ui/StoreAssetWithFullMultipleCompanySupportTest.php +++ b/tests/Feature/Assets/Ui/StoreAssetWithFullMultipleCompanySupportTest.php @@ -15,7 +15,7 @@ class StoreAssetWithFullMultipleCompanySupportTest extends TestCase use ProvidesDataForFullMultipleCompanySupportTesting; #[Group('focus')] - #[DataProvider('userProvider')] + #[DataProvider('dataForFullMultipleCompanySupportTesting')] public function testAdheresToFullMultipleCompaniesSupportScoping($data) { ['actor' => $actor, 'company_attempting_to_associate' => $company, 'assertions' => $assertions] = $data(); diff --git a/tests/Feature/Components/Ui/StoreComponentWithFullMultipleCompanySupportTest.php b/tests/Feature/Components/Ui/StoreComponentWithFullMultipleCompanySupportTest.php index 7abd762205..13bfd72273 100644 --- a/tests/Feature/Components/Ui/StoreComponentWithFullMultipleCompanySupportTest.php +++ b/tests/Feature/Components/Ui/StoreComponentWithFullMultipleCompanySupportTest.php @@ -14,7 +14,7 @@ class StoreComponentWithFullMultipleCompanySupportTest extends TestCase use ProvidesDataForFullMultipleCompanySupportTesting; #[Group('focus')] - #[DataProvider('userProvider')] + #[DataProvider('dataForFullMultipleCompanySupportTesting')] public function testAdheresToFullMultipleCompaniesSupportScoping($data) { ['actor' => $actor, 'company_attempting_to_associate' => $company, 'assertions' => $assertions] = $data(); diff --git a/tests/Feature/Consumables/Ui/StoreConsumableWithFullMultipleCompanySupportTest.php b/tests/Feature/Consumables/Ui/StoreConsumableWithFullMultipleCompanySupportTest.php index fb9ab1e3b4..00b2f5529d 100644 --- a/tests/Feature/Consumables/Ui/StoreConsumableWithFullMultipleCompanySupportTest.php +++ b/tests/Feature/Consumables/Ui/StoreConsumableWithFullMultipleCompanySupportTest.php @@ -14,7 +14,7 @@ class StoreConsumableWithFullMultipleCompanySupportTest extends TestCase use ProvidesDataForFullMultipleCompanySupportTesting; #[Group('focus')] - #[DataProvider('userProvider')] + #[DataProvider('dataForFullMultipleCompanySupportTesting')] public function testAdheresToFullMultipleCompaniesSupportScoping($data) { ['actor' => $actor, 'company_attempting_to_associate' => $company, 'assertions' => $assertions] = $data(); diff --git a/tests/Feature/Licenses/Ui/StoreLicenseWithFullMultipleCompanySupportTest.php b/tests/Feature/Licenses/Ui/StoreLicenseWithFullMultipleCompanySupportTest.php index dcb827a842..75a4b1f552 100644 --- a/tests/Feature/Licenses/Ui/StoreLicenseWithFullMultipleCompanySupportTest.php +++ b/tests/Feature/Licenses/Ui/StoreLicenseWithFullMultipleCompanySupportTest.php @@ -14,7 +14,7 @@ class StoreLicenseWithFullMultipleCompanySupportTest extends TestCase use ProvidesDataForFullMultipleCompanySupportTesting; #[Group('focus')] - #[DataProvider('userProvider')] + #[DataProvider('dataForFullMultipleCompanySupportTesting')] public function testAdheresToFullMultipleCompaniesSupportScoping($data) { ['actor' => $actor, 'company_attempting_to_associate' => $company, 'assertions' => $assertions] = $data(); diff --git a/tests/Support/ProvidesDataForFullMultipleCompanySupportTesting.php b/tests/Support/ProvidesDataForFullMultipleCompanySupportTesting.php index fad4c2ae7b..d247b98161 100644 --- a/tests/Support/ProvidesDataForFullMultipleCompanySupportTesting.php +++ b/tests/Support/ProvidesDataForFullMultipleCompanySupportTesting.php @@ -8,7 +8,7 @@ use Generator; trait ProvidesDataForFullMultipleCompanySupportTesting { - public static function userProvider(): Generator + public static function dataForFullMultipleCompanySupportTesting(): Generator { yield "User in a company should result in user's company_id being used" => [ function () { From 979e4502ffbadab5978d38633fe06aa96eed698a Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 17 Oct 2024 15:14:39 -0700 Subject: [PATCH 10/17] Have getIdForCurrentUser method return null if FMCS enabled, user is not super admin, and does not have company --- app/Models/Company.php | 2 +- tests/Unit/Models/Company/GetIdForCurrentUserTest.php | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/Models/Company.php b/app/Models/Company.php index 171d559542..8886da77f6 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -116,7 +116,7 @@ final class Company extends SnipeModel if ($current_user->company_id != null) { return $current_user->company_id; } else { - return static::getIdFromInput($unescaped_input); + return null; } } } diff --git a/tests/Unit/Models/Company/GetIdForCurrentUserTest.php b/tests/Unit/Models/Company/GetIdForCurrentUserTest.php index 6d77c88731..f69230fad1 100644 --- a/tests/Unit/Models/Company/GetIdForCurrentUserTest.php +++ b/tests/Unit/Models/Company/GetIdForCurrentUserTest.php @@ -4,8 +4,10 @@ namespace Tests\Unit\Models\Company; use App\Models\Company; use App\Models\User; +use PHPUnit\Framework\Attributes\Group; use Tests\TestCase; +#[Group('focus')] class GetIdForCurrentUserTest extends TestCase { public function testReturnsProvidedValueWhenFullCompanySupportDisabled() @@ -32,11 +34,11 @@ class GetIdForCurrentUserTest extends TestCase $this->assertEquals(2000, Company::getIdForCurrentUser(1000)); } - public function testReturnsProvidedValueForNonSuperUserWithoutCompanyIdWhenFullCompanySupportEnabled() + public function testReturnsNullForNonSuperUserWithoutCompanyIdWhenFullCompanySupportEnabled() { $this->settings->enableMultipleFullCompanySupport(); $this->actingAs(User::factory()->create(['company_id' => null])); - $this->assertEquals(1000, Company::getIdForCurrentUser(1000)); + $this->assertNull(Company::getIdForCurrentUser(1000)); } } From 7e1b47708e7d44a2ad3bc7af93a38fc2dc6e72a9 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 17 Oct 2024 15:18:41 -0700 Subject: [PATCH 11/17] Fix failing test ensuring company id is an integer --- app/Http/Requests/StoreAssetRequest.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/Http/Requests/StoreAssetRequest.php b/app/Http/Requests/StoreAssetRequest.php index 26d01051b4..e1665e2136 100644 --- a/app/Http/Requests/StoreAssetRequest.php +++ b/app/Http/Requests/StoreAssetRequest.php @@ -26,11 +26,18 @@ class StoreAssetRequest extends ImageUploadRequest public function prepareForValidation(): void { + // Guard against users passing in an array for company_id instead of an integer. + // If the company_id is not an integer then we simply use what was + // provided to be caught by model level validation later. + $idForCurrentUser = is_int($this->company_id) + ? Company::getIdForCurrentUser($this->company_id) + : $this->company_id; + $this->parseLastAuditDate(); $this->merge([ 'asset_tag' => $this->asset_tag ?? Asset::autoincrement_asset(), - 'company_id' => Company::getIdForCurrentUser($this->company_id), + 'company_id' => $idForCurrentUser, 'assigned_to' => $assigned_to ?? null, ]); } From a8d853c44a38b50db05884843c614fe7b7342d60 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 17 Oct 2024 15:26:27 -0700 Subject: [PATCH 12/17] Remove focus group tags --- .../Ui/CreateAccessoryWithFullMultipleCompanySupportTest.php | 2 -- tests/Feature/Assets/Api/StoreAssetTest.php | 2 -- .../Assets/Api/StoreAssetWithFullMultipleCompanySupportTest.php | 2 -- .../Assets/Ui/StoreAssetWithFullMultipleCompanySupportTest.php | 2 -- .../Ui/StoreComponentWithFullMultipleCompanySupportTest.php | 2 -- .../Ui/StoreConsumableWithFullMultipleCompanySupportTest.php | 2 -- .../Ui/StoreLicenseWithFullMultipleCompanySupportTest.php | 2 -- tests/Unit/Models/Company/GetIdForCurrentUserTest.php | 2 -- 8 files changed, 16 deletions(-) diff --git a/tests/Feature/Accessories/Ui/CreateAccessoryWithFullMultipleCompanySupportTest.php b/tests/Feature/Accessories/Ui/CreateAccessoryWithFullMultipleCompanySupportTest.php index c256830a63..a606db3fe2 100644 --- a/tests/Feature/Accessories/Ui/CreateAccessoryWithFullMultipleCompanySupportTest.php +++ b/tests/Feature/Accessories/Ui/CreateAccessoryWithFullMultipleCompanySupportTest.php @@ -5,7 +5,6 @@ namespace Tests\Feature\Accessories\Ui; use App\Models\Accessory; use App\Models\Category; use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\Attributes\Group; use Tests\Support\ProvidesDataForFullMultipleCompanySupportTesting; use Tests\TestCase; @@ -13,7 +12,6 @@ class CreateAccessoryWithFullMultipleCompanySupportTest extends TestCase { use ProvidesDataForFullMultipleCompanySupportTesting; - #[Group('focus')] #[DataProvider('dataForFullMultipleCompanySupportTesting')] public function testAdheresToFullMultipleCompaniesSupportScoping($data) { diff --git a/tests/Feature/Assets/Api/StoreAssetTest.php b/tests/Feature/Assets/Api/StoreAssetTest.php index 26fb1f78c0..ea5cfb6178 100644 --- a/tests/Feature/Assets/Api/StoreAssetTest.php +++ b/tests/Feature/Assets/Api/StoreAssetTest.php @@ -12,7 +12,6 @@ use App\Models\Supplier; use App\Models\User; use Illuminate\Support\Facades\Crypt; use Illuminate\Testing\Fluent\AssertableJson; -use PHPUnit\Framework\Attributes\Group; use Tests\TestCase; class StoreAssetTest extends TestCase @@ -564,7 +563,6 @@ class StoreAssetTest extends TestCase /** * @link https://app.shortcut.com/grokability/story/24475 */ - #[Group('focus')] public function testCompanyIdNeedsToBeInteger() { $this->actingAsForApi(User::factory()->createAssets()->create()) diff --git a/tests/Feature/Assets/Api/StoreAssetWithFullMultipleCompanySupportTest.php b/tests/Feature/Assets/Api/StoreAssetWithFullMultipleCompanySupportTest.php index 57d09e7e13..389a54dda5 100644 --- a/tests/Feature/Assets/Api/StoreAssetWithFullMultipleCompanySupportTest.php +++ b/tests/Feature/Assets/Api/StoreAssetWithFullMultipleCompanySupportTest.php @@ -6,7 +6,6 @@ use App\Models\Asset; use App\Models\AssetModel; use App\Models\Statuslabel; use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\Attributes\Group; use Tests\Support\ProvidesDataForFullMultipleCompanySupportTesting; use Tests\TestCase; @@ -17,7 +16,6 @@ class StoreAssetWithFullMultipleCompanySupportTest extends TestCase /** * @link https://github.com/snipe/snipe-it/issues/15654 */ - #[Group('focus')] #[DataProvider('dataForFullMultipleCompanySupportTesting')] public function testAdheresToFullMultipleCompaniesSupportScoping($data) { diff --git a/tests/Feature/Assets/Ui/StoreAssetWithFullMultipleCompanySupportTest.php b/tests/Feature/Assets/Ui/StoreAssetWithFullMultipleCompanySupportTest.php index b6302f95c8..3443256030 100644 --- a/tests/Feature/Assets/Ui/StoreAssetWithFullMultipleCompanySupportTest.php +++ b/tests/Feature/Assets/Ui/StoreAssetWithFullMultipleCompanySupportTest.php @@ -6,7 +6,6 @@ use App\Models\Asset; use App\Models\AssetModel; use App\Models\Statuslabel; use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\Attributes\Group; use Tests\Support\ProvidesDataForFullMultipleCompanySupportTesting; use Tests\TestCase; @@ -14,7 +13,6 @@ class StoreAssetWithFullMultipleCompanySupportTest extends TestCase { use ProvidesDataForFullMultipleCompanySupportTesting; - #[Group('focus')] #[DataProvider('dataForFullMultipleCompanySupportTesting')] public function testAdheresToFullMultipleCompaniesSupportScoping($data) { diff --git a/tests/Feature/Components/Ui/StoreComponentWithFullMultipleCompanySupportTest.php b/tests/Feature/Components/Ui/StoreComponentWithFullMultipleCompanySupportTest.php index 13bfd72273..bb36a6fa82 100644 --- a/tests/Feature/Components/Ui/StoreComponentWithFullMultipleCompanySupportTest.php +++ b/tests/Feature/Components/Ui/StoreComponentWithFullMultipleCompanySupportTest.php @@ -5,7 +5,6 @@ namespace Tests\Feature\Components\Ui; use App\Models\Category; use App\Models\Component; use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\Attributes\Group; use Tests\Support\ProvidesDataForFullMultipleCompanySupportTesting; use Tests\TestCase; @@ -13,7 +12,6 @@ class StoreComponentWithFullMultipleCompanySupportTest extends TestCase { use ProvidesDataForFullMultipleCompanySupportTesting; - #[Group('focus')] #[DataProvider('dataForFullMultipleCompanySupportTesting')] public function testAdheresToFullMultipleCompaniesSupportScoping($data) { diff --git a/tests/Feature/Consumables/Ui/StoreConsumableWithFullMultipleCompanySupportTest.php b/tests/Feature/Consumables/Ui/StoreConsumableWithFullMultipleCompanySupportTest.php index 00b2f5529d..6f53d2298c 100644 --- a/tests/Feature/Consumables/Ui/StoreConsumableWithFullMultipleCompanySupportTest.php +++ b/tests/Feature/Consumables/Ui/StoreConsumableWithFullMultipleCompanySupportTest.php @@ -5,7 +5,6 @@ namespace Tests\Feature\Consumables\Ui; use App\Models\Category; use App\Models\Consumable; use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\Attributes\Group; use Tests\Support\ProvidesDataForFullMultipleCompanySupportTesting; use Tests\TestCase; @@ -13,7 +12,6 @@ class StoreConsumableWithFullMultipleCompanySupportTest extends TestCase { use ProvidesDataForFullMultipleCompanySupportTesting; - #[Group('focus')] #[DataProvider('dataForFullMultipleCompanySupportTesting')] public function testAdheresToFullMultipleCompaniesSupportScoping($data) { diff --git a/tests/Feature/Licenses/Ui/StoreLicenseWithFullMultipleCompanySupportTest.php b/tests/Feature/Licenses/Ui/StoreLicenseWithFullMultipleCompanySupportTest.php index 75a4b1f552..de6ffbaaee 100644 --- a/tests/Feature/Licenses/Ui/StoreLicenseWithFullMultipleCompanySupportTest.php +++ b/tests/Feature/Licenses/Ui/StoreLicenseWithFullMultipleCompanySupportTest.php @@ -5,7 +5,6 @@ namespace Tests\Feature\Licenses\Ui; use App\Models\Category; use App\Models\License; use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\Attributes\Group; use Tests\Support\ProvidesDataForFullMultipleCompanySupportTesting; use Tests\TestCase; @@ -13,7 +12,6 @@ class StoreLicenseWithFullMultipleCompanySupportTest extends TestCase { use ProvidesDataForFullMultipleCompanySupportTesting; - #[Group('focus')] #[DataProvider('dataForFullMultipleCompanySupportTesting')] public function testAdheresToFullMultipleCompaniesSupportScoping($data) { diff --git a/tests/Unit/Models/Company/GetIdForCurrentUserTest.php b/tests/Unit/Models/Company/GetIdForCurrentUserTest.php index f69230fad1..c21c4f36a3 100644 --- a/tests/Unit/Models/Company/GetIdForCurrentUserTest.php +++ b/tests/Unit/Models/Company/GetIdForCurrentUserTest.php @@ -4,10 +4,8 @@ namespace Tests\Unit\Models\Company; use App\Models\Company; use App\Models\User; -use PHPUnit\Framework\Attributes\Group; use Tests\TestCase; -#[Group('focus')] class GetIdForCurrentUserTest extends TestCase { public function testReturnsProvidedValueWhenFullCompanySupportDisabled() From 4188849ae17d52dd9befd349b56419eaea9f5287 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 21 Oct 2024 12:19:48 -0700 Subject: [PATCH 13/17] Add failing test case --- ...ssetWithFullMultipleCompanySupportTest.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/Feature/Assets/Api/StoreAssetWithFullMultipleCompanySupportTest.php b/tests/Feature/Assets/Api/StoreAssetWithFullMultipleCompanySupportTest.php index 389a54dda5..60676f39c1 100644 --- a/tests/Feature/Assets/Api/StoreAssetWithFullMultipleCompanySupportTest.php +++ b/tests/Feature/Assets/Api/StoreAssetWithFullMultipleCompanySupportTest.php @@ -35,4 +35,24 @@ class StoreAssetWithFullMultipleCompanySupportTest extends TestCase $assertions($asset); } + + #[DataProvider('dataForFullMultipleCompanySupportTesting')] + public function testHandlesCompanyIdBeingString($data) + { + ['actor' => $actor, 'company_attempting_to_associate' => $company, 'assertions' => $assertions] = $data(); + + $this->settings->enableMultipleFullCompanySupport(); + + $response = $this->actingAsForApi($actor) + ->postJson(route('api.assets.store'), [ + 'asset_tag' => 'random_string', + 'company_id' => (string) $company->id, + 'model_id' => AssetModel::factory()->create()->id, + 'status_id' => Statuslabel::factory()->readyToDeploy()->create()->id, + ]); + + $asset = Asset::withoutGlobalScopes()->findOrFail($response['payload']['id']); + + $assertions($asset); + } } From 7eee239378f1b4318557886d1e022540a10977af Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 21 Oct 2024 12:20:28 -0700 Subject: [PATCH 14/17] use is_numeric instead of is_int --- app/Http/Requests/StoreAssetRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Requests/StoreAssetRequest.php b/app/Http/Requests/StoreAssetRequest.php index e1665e2136..d3e1eced26 100644 --- a/app/Http/Requests/StoreAssetRequest.php +++ b/app/Http/Requests/StoreAssetRequest.php @@ -29,7 +29,7 @@ class StoreAssetRequest extends ImageUploadRequest // Guard against users passing in an array for company_id instead of an integer. // If the company_id is not an integer then we simply use what was // provided to be caught by model level validation later. - $idForCurrentUser = is_int($this->company_id) + $idForCurrentUser = is_numeric($this->company_id) ? Company::getIdForCurrentUser($this->company_id) : $this->company_id; From e1882ee6d2a78506abfd371ba6e0d592ac487181 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 21 Oct 2024 12:21:45 -0700 Subject: [PATCH 15/17] Add comment --- app/Http/Requests/StoreAssetRequest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Requests/StoreAssetRequest.php b/app/Http/Requests/StoreAssetRequest.php index d3e1eced26..fb7469ac88 100644 --- a/app/Http/Requests/StoreAssetRequest.php +++ b/app/Http/Requests/StoreAssetRequest.php @@ -29,6 +29,7 @@ class StoreAssetRequest extends ImageUploadRequest // Guard against users passing in an array for company_id instead of an integer. // If the company_id is not an integer then we simply use what was // provided to be caught by model level validation later. + // The use of is_numeric accounts for 1 and '1'. $idForCurrentUser = is_numeric($this->company_id) ? Company::getIdForCurrentUser($this->company_id) : $this->company_id; From eb6c51fabdf755b488493bff2b1c4d52a3ba8b3f Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 22 Oct 2024 22:04:57 +0100 Subject: [PATCH 16/17] Fixes #15701 - load avif files properly in lightbox Signed-off-by: snipe --- resources/views/accessories/view.blade.php | 3 ++- resources/views/components/view.blade.php | 2 +- resources/views/consumables/view.blade.php | 2 +- resources/views/hardware/view.blade.php | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/resources/views/accessories/view.blade.php b/resources/views/accessories/view.blade.php index fb2904e2cf..1e3568f0ef 100644 --- a/resources/views/accessories/view.blade.php +++ b/resources/views/accessories/view.blade.php @@ -179,7 +179,8 @@ @if ($accessory->image!='')
- {{ $accessory->name }} + + {{ $accessory->name }}
@endif diff --git a/resources/views/components/view.blade.php b/resources/views/components/view.blade.php index 5bd185bedf..ba3a6d6e24 100644 --- a/resources/views/components/view.blade.php +++ b/resources/views/components/view.blade.php @@ -161,7 +161,7 @@
@if ($component->image!='') diff --git a/resources/views/consumables/view.blade.php b/resources/views/consumables/view.blade.php index 87650ac9eb..ac95e6391b 100644 --- a/resources/views/consumables/view.blade.php +++ b/resources/views/consumables/view.blade.php @@ -89,7 +89,7 @@ @if ($consumable->image!='') @endif diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.php index f93c26cf8e..7157c6872e 100755 --- a/resources/views/hardware/view.blade.php +++ b/resources/views/hardware/view.blade.php @@ -168,7 +168,7 @@