ajout app
This commit is contained in:
22
SNIPE-IT/tests/Unit/Models/Company/CompanyTest.php
Normal file
22
SNIPE-IT/tests/Unit/Models/Company/CompanyTest.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace Tests\Unit\Models\Company;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\User;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CompanyTest extends TestCase
|
||||
{
|
||||
public function testACompanyCanHaveUsers()
|
||||
{
|
||||
$company = Company::factory()->create();
|
||||
$user = User::factory()
|
||||
->create(
|
||||
[
|
||||
'company_id'=> $company->id
|
||||
]
|
||||
);
|
||||
|
||||
$this->assertCount(1, $company->users);
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Models\Company;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\User;
|
||||
use Tests\TestCase;
|
||||
|
||||
class GetIdForCurrentUserTest extends TestCase
|
||||
{
|
||||
public function testReturnsProvidedValueWhenFullCompanySupportDisabled()
|
||||
{
|
||||
$this->settings->disableMultipleFullCompanySupport();
|
||||
|
||||
$this->actingAs(User::factory()->create());
|
||||
$this->assertEquals(1000, Company::getIdForCurrentUser(1000));
|
||||
}
|
||||
|
||||
public function testReturnsProvidedValueForSuperUsersWhenFullCompanySupportEnabled()
|
||||
{
|
||||
$this->settings->enableMultipleFullCompanySupport();
|
||||
|
||||
$this->actingAs(User::factory()->superuser()->create());
|
||||
$this->assertEquals(2000, Company::getIdForCurrentUser(2000));
|
||||
}
|
||||
|
||||
public function testReturnsNonSuperUsersCompanyIdWhenFullCompanySupportEnabled()
|
||||
{
|
||||
$this->settings->enableMultipleFullCompanySupport();
|
||||
|
||||
$this->actingAs(User::factory()->forCompany(['id' => 2000])->create());
|
||||
$this->assertEquals(2000, Company::getIdForCurrentUser(1000));
|
||||
}
|
||||
|
||||
public function testReturnsProvidedValueForNonSuperUserWithoutCompanyIdWhenFullCompanySupportEnabled()
|
||||
{
|
||||
$this->settings->enableMultipleFullCompanySupport();
|
||||
|
||||
$this->actingAs(User::factory()->create(['company_id' => null]));
|
||||
$this->assertEquals(1000, Company::getIdForCurrentUser(1000));
|
||||
}
|
||||
}
|
26
SNIPE-IT/tests/Unit/Models/Labels/FieldOptionTest.php
Normal file
26
SNIPE-IT/tests/Unit/Models/Labels/FieldOptionTest.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Models\Labels;
|
||||
|
||||
use App\Models\Asset;
|
||||
use App\Models\Labels\FieldOption;
|
||||
use App\Models\User;
|
||||
use Tests\TestCase;
|
||||
|
||||
class FieldOptionTest extends TestCase
|
||||
{
|
||||
public function testItDisplaysAssignedToProperly()
|
||||
{
|
||||
// "assignedTo" is a "special" value that can be used in the new label engine
|
||||
$fieldOption = FieldOption::fromString('Assigned To=assignedTo');
|
||||
|
||||
$asset = Asset::factory()
|
||||
->assignedToUser(User::factory()->create(['first_name' => 'Luke', 'last_name' => 'Skywalker']))
|
||||
->create();
|
||||
|
||||
$this->assertEquals('Luke Skywalker', $fieldOption->getValue($asset));
|
||||
// If the "assignedTo" relationship was eager loaded then the way to get the
|
||||
// relationship changes from $asset->assignedTo to $asset->assigned.
|
||||
$this->assertEquals('Luke Skywalker', $fieldOption->getValue(Asset::with('assignedTo')->find($asset->id)));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user