Skip to content

A free open source IT asset/license management system

Write tests around getIdForCurrentUser method [sc-24748]

Marcus Moore76cc5995d9a3
diff --git a/tests/Unit/CompanyTest.php b/tests/Unit/Models/Company/CompanyTest.php
similarity index 92%
rename from tests/Unit/CompanyTest.php
rename to tests/Unit/Models/Company/CompanyTest.php
index 6e04504843..6fd17e554b 100644
--- a/tests/Unit/CompanyTest.php
+++ b/tests/Unit/Models/Company/CompanyTest.php
@@ -1,5 +1,5 @@
<?php
-namespace Tests\Unit;
+namespace Tests\Unit\Models\Company;
use App\Models\Company;
use App\Models\User;
diff --git a/tests/Unit/Models/Company/GetIdForCurrentUserTest.php b/tests/Unit/Models/Company/GetIdForCurrentUserTest.php
new file mode 100644
index 0000000000..1ca88d7cac
--- /dev/null
+++ b/tests/Unit/Models/Company/GetIdForCurrentUserTest.php
@@ -0,0 +1,45 @@
+<?php
+
+namespace Tests\Unit\Models\Company;
+
+use App\Models\Company;
+use App\Models\User;
+use Tests\Support\InteractsWithSettings;
+use Tests\TestCase;
+
+class GetIdForCurrentUserTest extends TestCase
+{
+ use InteractsWithSettings;
+
+ 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));
+ }
+}