Skip to content

A free open source IT asset/license management system

Move test

Marcus Moore4bb19152c4a9
diff --git a/tests/Feature/Reporting/CustomReportTest.php b/tests/Feature/Reporting/CustomReportTest.php
index 91d627129d..0f53bd4efc 100644
--- a/tests/Feature/Reporting/CustomReportTest.php
+++ b/tests/Feature/Reporting/CustomReportTest.php
@@ -6,6 +6,7 @@ use App\Models\Asset;
use App\Models\Company;
use App\Models\ReportTemplate;
use App\Models\User;
+use Illuminate\Database\Eloquent\Collection;
use Illuminate\Testing\TestResponse;
use League\Csv\Reader;
use PHPUnit\Framework\Assert;
@@ -67,6 +68,27 @@ class CustomReportTest extends TestCase implements TestsPermissionsRequirement
]);
}
+ public function testSavedTemplatesOnPageAreScopedToTheUser()
+ {
+ // Given there is a saved template for one user
+ ReportTemplate::factory()->create(['name' => 'Report A']);
+
+ // When loading reports/custom while acting as another user that also has a saved template
+ $user = User::factory()->canViewReports()
+ ->has(ReportTemplate::factory(['name' => 'Report B']))
+ ->create();
+
+ // The user should not see the other user's template (in view as 'report_templates')
+ $this->actingAs($user)
+ ->get(route('reports/custom'))
+ ->assertViewHas([
+ 'report_templates' => function (Collection $reports) {
+ return $reports->pluck('name')->doesntContain('Report A');
+ }
+ ]);
+ }
+
+
public function testCustomAssetReport()
{
Asset::factory()->create(['name' => 'Asset A']);
diff --git a/tests/Unit/Models/ReportTemplates/ReportTemplateScopingTest.php b/tests/Unit/Models/ReportTemplates/ReportTemplateScopingTest.php
deleted file mode 100644
index 67052f7d4f..0000000000
--- a/tests/Unit/Models/ReportTemplates/ReportTemplateScopingTest.php
+++ /dev/null
@@ -1,31 +0,0 @@
-<?php
-
-namespace Tests\Unit\Models\ReportTemplates;
-
-use App\Models\ReportTemplate;
-use App\Models\User;
-use Illuminate\Database\Eloquent\Collection;
-use PHPUnit\Framework\Attributes\Group;
-use Tests\TestCase;
-
-#[Group('custom-reporting')]
-class ReportTemplateScopingTest extends TestCase
-{
- public function testSavedTemplatesAreScopedToTheUser()
- {
- // Given there is a saved template for one user
- ReportTemplate::factory()->create(['name' => 'Report A']);
-
- // When loading reports/custom while acting as another user that also has a saved template
- $user = User::factory()->canViewReports()
- ->has(ReportTemplate::factory(['name' => 'Report B']))
- ->create();
-
- // The user should not see the other user's template (in view as 'report_templates')
- $this->actingAs($user)
- ->get(route('reports/custom'))
- ->assertViewHas(['report_templates' => function (Collection $reports) {
- return $reports->pluck('name')->doesntContain('Report A');
- }]);
- }
-}