Skip to content

A free open source IT asset/license management system

Inline route helpers in tests

Marcus Mooredc0b8c757283
diff --git a/tests/Feature/ReportTemplates/DeleteReportTemplateTest.php b/tests/Feature/ReportTemplates/DeleteReportTemplateTest.php
index 52f4ad888d..2b108443a3 100644
--- a/tests/Feature/ReportTemplates/DeleteReportTemplateTest.php
+++ b/tests/Feature/ReportTemplates/DeleteReportTemplateTest.php
@@ -16,7 +16,7 @@ class DeleteReportTemplateTest extends TestCase implements TestsPermissionsRequi
$reportTemplate = ReportTemplate::factory()->create();
$this->actingAs(User::factory()->create())
- ->post($this->getRoute($reportTemplate))
+ ->post(route('report-templates.destroy', $reportTemplate->id))
->assertNotFound();
$this->assertModelExists($reportTemplate);
@@ -27,7 +27,7 @@ class DeleteReportTemplateTest extends TestCase implements TestsPermissionsRequi
$reportTemplate = ReportTemplate::factory()->create();
$this->actingAs(User::factory()->canViewReports()->create())
- ->delete($this->getRoute($reportTemplate))
+ ->delete(route('report-templates.destroy', $reportTemplate->id))
->assertNotFound();
$this->assertModelExists($reportTemplate);
@@ -39,14 +39,9 @@ class DeleteReportTemplateTest extends TestCase implements TestsPermissionsRequi
$reportTemplate = ReportTemplate::factory()->for($user, 'creator')->create();
$this->actingAs($user)
- ->delete($this->getRoute($reportTemplate))
+ ->delete(route('report-templates.destroy', $reportTemplate->id))
->assertRedirect(route('reports/custom'));
$this->assertSoftDeleted($reportTemplate);
}
-
- private function getRoute(ReportTemplate $reportTemplate): string
- {
- return route('report-templates.destroy', $reportTemplate->id);
- }
}
diff --git a/tests/Feature/ReportTemplates/EditReportTemplateTest.php b/tests/Feature/ReportTemplates/EditReportTemplateTest.php
index dad65ffbc8..88363ec8b1 100644
--- a/tests/Feature/ReportTemplates/EditReportTemplateTest.php
+++ b/tests/Feature/ReportTemplates/EditReportTemplateTest.php
@@ -14,7 +14,7 @@ class EditReportTemplateTest extends TestCase implements TestsPermissionsRequire
public function testRequiresPermission()
{
$this->actingAs(User::factory()->create())
- ->get($this->getRoute(ReportTemplate::factory()->create()))
+ ->get(route('report-templates.edit', ReportTemplate::factory()->create()))
->assertNotFound();
}
@@ -24,7 +24,7 @@ class EditReportTemplateTest extends TestCase implements TestsPermissionsRequire
$reportTemplate = ReportTemplate::factory()->create();
$this->actingAs($user)
- ->get($this->getRoute($reportTemplate))
+ ->get(route('report-templates.edit', $reportTemplate))
->assertNotFound();
}
@@ -34,12 +34,7 @@ class EditReportTemplateTest extends TestCase implements TestsPermissionsRequire
$reportTemplate = ReportTemplate::factory()->for($user, 'creator')->create();
$this->actingAs($user)
- ->get($this->getRoute($reportTemplate))
+ ->get(route('report-templates.edit', $reportTemplate))
->assertOk();
}
-
- private function getRoute(ReportTemplate $reportTemplate): string
- {
- return route('report-templates.edit', $reportTemplate);
- }
}
diff --git a/tests/Feature/ReportTemplates/ShowReportTemplateTest.php b/tests/Feature/ReportTemplates/ShowReportTemplateTest.php
index dfd7d68bcb..3e57db898a 100644
--- a/tests/Feature/ReportTemplates/ShowReportTemplateTest.php
+++ b/tests/Feature/ReportTemplates/ShowReportTemplateTest.php
@@ -14,7 +14,7 @@ class ShowReportTemplateTest extends TestCase implements TestsPermissionsRequire
public function testRequiresPermission()
{
$this->actingAs(User::factory()->create())
- ->get($this->getRoute(ReportTemplate::factory()->create()))
+ ->get(route('report-templates.show', ReportTemplate::factory()->create()))
->assertNotFound();
}
@@ -25,7 +25,7 @@ class ShowReportTemplateTest extends TestCase implements TestsPermissionsRequire
$user->reportTemplates()->save($reportTemplate);
$this->actingAs($user)
- ->get($this->getRoute($reportTemplate))
+ ->get(route('report-templates.show', $reportTemplate))
->assertOk()
->assertViewHas(['template' => function (ReportTemplate $templatePassedToView) use ($reportTemplate) {
return $templatePassedToView->is($reportTemplate);
@@ -37,12 +37,7 @@ class ShowReportTemplateTest extends TestCase implements TestsPermissionsRequire
$reportTemplate = ReportTemplate::factory()->create();
$this->actingAs(User::factory()->canViewReports()->create())
- ->get($this->getRoute($reportTemplate))
+ ->get(route('report-templates.show', $reportTemplate))
->assertNotFound();
}
-
- private function getRoute(ReportTemplate $reportTemplate): string
- {
- return route('report-templates.show', $reportTemplate);
- }
}
diff --git a/tests/Feature/ReportTemplates/StoreReportTemplateTest.php b/tests/Feature/ReportTemplates/StoreReportTemplateTest.php
index 492f5e4ecc..06121711e8 100644
--- a/tests/Feature/ReportTemplates/StoreReportTemplateTest.php
+++ b/tests/Feature/ReportTemplates/StoreReportTemplateTest.php
@@ -14,14 +14,14 @@ class StoreReportTemplateTest extends TestCase implements TestsPermissionsRequir
public function testRequiresPermission()
{
$this->actingAs(User::factory()->create())
- ->post($this->getRoute())
+ ->post(route('report-templates.store'))
->assertForbidden();
}
public function testSavingReportTemplateRequiresValidFields()
{
$this->actingAs(User::factory()->canViewReports()->create())
- ->post($this->getRoute(), [
+ ->post(route('report-templates.store'), [
'name' => '',
])
->assertSessionHasErrors('name');
@@ -33,7 +33,7 @@ class StoreReportTemplateTest extends TestCase implements TestsPermissionsRequir
// start on the custom report page
->from(route('reports/custom'))
->followingRedirects()
- ->post($this->getRoute(), [
+ ->post(route('report-templates.store'), [
'name' => '',
// set some values to ensure they are still present
// when returning to the custom report page.
@@ -48,7 +48,7 @@ class StoreReportTemplateTest extends TestCase implements TestsPermissionsRequir
$user = User::factory()->canViewReports()->create();
$this->actingAs($user)
- ->post($this->getRoute(), [
+ ->post(route('report-templates.store'), [
'name' => 'My Awesome Template',
'company' => '1',
'by_company_id' => ['1', '2'],
@@ -63,9 +63,4 @@ class StoreReportTemplateTest extends TestCase implements TestsPermissionsRequir
$this->assertEquals('1', $template->options['company']);
$this->assertEquals(['1', '2'], $template->options['by_company_id']);
}
-
- private function getRoute(): string
- {
- return route('report-templates.store');
- }
}
diff --git a/tests/Feature/ReportTemplates/UpdateReportTemplateTest.php b/tests/Feature/ReportTemplates/UpdateReportTemplateTest.php
index 8d4df153a6..9afecb0849 100644
--- a/tests/Feature/ReportTemplates/UpdateReportTemplateTest.php
+++ b/tests/Feature/ReportTemplates/UpdateReportTemplateTest.php
@@ -14,14 +14,14 @@ class UpdateReportTemplateTest extends TestCase implements TestsPermissionsRequi
public function testRequiresPermission()
{
$this->actingAs(User::factory()->create())
- ->post($this->getRoute(ReportTemplate::factory()->create()))
+ ->post(route('report-templates.update', ReportTemplate::factory()->create()))
->assertNotFound();
}
public function testCannotUpdateAnotherUsersReportTemplate()
{
$this->actingAs(User::factory()->canViewReports()->create())
- ->post($this->getRoute(ReportTemplate::factory()->create()))
+ ->post(route('report-templates.update', ReportTemplate::factory()->create()))
->assertNotFound();
}
@@ -32,7 +32,7 @@ class UpdateReportTemplateTest extends TestCase implements TestsPermissionsRequi
$reportTemplate = ReportTemplate::factory()->for($user, 'creator')->create();
$this->actingAs($user)
- ->post($this->getRoute($reportTemplate), [
+ ->post(route('report-templates.update', $reportTemplate), [
//
])
->assertSessionHasErrors([
@@ -56,7 +56,7 @@ class UpdateReportTemplateTest extends TestCase implements TestsPermissionsRequi
]);
$this->actingAs($user)
- ->post($this->getRoute($reportTemplate), [
+ ->post(route('report-templates.update', $reportTemplate), [
'name' => 'Updated Name',
'id' => 1,
'company' => 1,
@@ -71,9 +71,4 @@ class UpdateReportTemplateTest extends TestCase implements TestsPermissionsRequi
$this->assertEquals(1, $reportTemplate->checkmarkValue('company'));
$this->assertEquals([3], $reportTemplate->selectValues('by_company_id'));
}
-
- private function getRoute(ReportTemplate $reportTemplate): string
- {
- return route('report-templates.update', $reportTemplate);
- }
}