mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-08 20:37:29 -08:00
71 lines
2.4 KiB
PHP
71 lines
2.4 KiB
PHP
<?php
|
|||
|
|||
namespace Tests\Support;
|
|||
|
|||
use App\Models\Company;
|
|||
use App\Models\User;
|
|||
use Generator;
|
|||
|
|||
trait ProvidesDataForFullMultipleCompanySupportTesting
|
|||
{
|
|||
public static function dataForFullMultipleCompanySupportTesting(): 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()
|
|||
->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);
|
|||
},
|
|||
];
|
|||
}
|
|||
];
|
|||
}
|
|||
}
|