mirror of
https://github.com/snipe/snipe-it.git
synced 2025-02-02 08:21:09 -08:00
Test organization
This commit is contained in:
parent
86762c5e90
commit
35f8a71c71
|
@ -1,36 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Unit\Models;
|
||||
namespace Tests\Unit\Models\ReportTemplates;
|
||||
|
||||
use App\Models\Department;
|
||||
use App\Models\Location;
|
||||
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 ReportTemplateTest extends TestCase
|
||||
class ReportTemplateParsingValuesTest 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');
|
||||
}]);
|
||||
}
|
||||
|
||||
public function testParsingValuesOnNonExistentReportTemplate()
|
||||
{
|
||||
$unsavedTemplate = new ReportTemplate;
|
|
@ -0,0 +1,31 @@
|
|||
<?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');
|
||||
}]);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue