Fixed route parameters and tests to match

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2025-02-19 05:03:56 +00:00
parent ecc0e76e7b
commit 347eb2bdee
30 changed files with 65 additions and 65 deletions

View file

@ -97,7 +97,7 @@ class AccessoriesController extends Controller
*/
public function edit(Accessory $accessory) : View | RedirectResponse
{
return view('accessories.edit')->with('category_type', 'accessory');
return view('accessories.edit')->with('item', $accessory)->with('category_type', 'accessory');
}
/**

View file

@ -83,7 +83,7 @@ final class CompaniesController extends Controller
public function edit(Company $company) : View | RedirectResponse
{
$this->authorize('update', $company);
return view('companies/edit');
return view('companies/edit')->with('item', $company);
}
/**

View file

@ -111,7 +111,9 @@ class ComponentsController extends Controller
{
$this->authorize('update', $component);
return view('components/edit')->with('category_type', 'component');
return view('components/edit')
->with('item', $component)
->with('category_type', 'component');
}

View file

@ -12,7 +12,7 @@ class ShowAccessoryTest extends TestCase
public function testRequiresPermissionToViewAccessory()
{
$this->actingAs(User::factory()->create())
->get(route('accessories.show', Accessory::factory()->create()->id))
->get(route('accessories.show', Accessory::factory()->create()))
->assertForbidden();
}
@ -25,7 +25,7 @@ class ShowAccessoryTest extends TestCase
$userForCompanyB = User::factory()->for($companyB)->viewAccessories()->create();
$this->actingAs($userForCompanyB)
->get(route('accessories.show', $accessoryForCompanyA->id))
->get(route('accessories.show', $accessoryForCompanyA))
->assertForbidden();
}
@ -34,7 +34,7 @@ class ShowAccessoryTest extends TestCase
$accessory = Accessory::factory()->create();
$this->actingAs(User::factory()->viewAccessories()->create())
->get(route('accessories.show', $accessory->id))
->get(route('accessories.show', $accessory))
->assertOk()
->assertViewIs('accessories.view')
->assertViewHas(['accessory' => $accessory]);
@ -43,7 +43,7 @@ class ShowAccessoryTest extends TestCase
public function testPageRenders()
{
$this->actingAs(User::factory()->superuser()->create())
->get(route('accessories.show', Accessory::factory()->create()->id))
->get(route('accessories.show', Accessory::factory()->create()))
->assertOk();
}

View file

@ -16,7 +16,7 @@ class UpdateAccessoryTest extends TestCase
public function testRequiresPermissionToSeeEditAccessoryPage()
{
$this->actingAs(User::factory()->create())
->get(route('accessories.edit', Accessory::factory()->create()->id))
->get(route('accessories.edit', Accessory::factory()->create()))
->assertForbidden();
}

View file

@ -11,7 +11,7 @@ class ShowAssetModelsTest extends TestCase
public function testPageRenders()
{
$this->actingAs(User::factory()->superuser()->create())
->get(route('models.show', AssetModel::factory()->create()->id))
->get(route('models.show', AssetModel::factory()->create()))
->assertOk();
}
}

View file

@ -24,7 +24,7 @@ class UpdateAssetModelsTest extends TestCase
public function testPageRenders()
{
$this->actingAs(User::factory()->superuser()->create())
->get(route('models.edit', AssetModel::factory()->create()->id))
->get(route('models.edit', AssetModel::factory()->create()))
->assertOk();
}
@ -55,15 +55,15 @@ class UpdateAssetModelsTest extends TestCase
$this->assertTrue(AssetModel::where('name', 'Test Model')->exists());
$response = $this->actingAs(User::factory()->superuser()->create())
->from(route('models.edit', ['model' => $model->id]))
->put(route('models.update', ['model' => $model]), [
->from(route('models.edit', $model))
->put(route('models.update', $model), [
'name' => 'Test Model Edited',
'category_id' => Category::factory()->forAccessories()->create()->id,
])
->assertSessionHasErrors(['category_type'])
->assertInvalid(['category_type'])
->assertStatus(302)
->assertRedirect(route('models.edit', ['model' => $model->id]));
->assertRedirect(route('models.edit', $model));
$this->followRedirects($response)->assertSee(trans('general.error'));
$this->assertFalse(AssetModel::where('name', 'Test Model Edited')->exists());

View file

@ -27,7 +27,7 @@ class EditAssetTest extends TestCase
{
$asset = Asset::factory()->create();
$user = User::factory()->editAssets()->create();
$response = $this->actingAs($user)->get(route('hardware.edit', $asset->id));
$response = $this->actingAs($user)->get(route('hardware.edit', $asset));
$response->assertStatus(200);
}
@ -63,7 +63,7 @@ class EditAssetTest extends TestCase
'model_id' => AssetModel::factory()->create()->id,
])
->assertStatus(302)
->assertRedirect(route('hardware.show', ['hardware' => $asset->id]));
->assertRedirect(route('hardware.show', $asset));
$this->assertDatabaseHas('assets', ['asset_tag' => 'New Asset Tag']);
}
@ -81,8 +81,8 @@ class EditAssetTest extends TestCase
$currentTimestamp = now();
$this->actingAs(User::factory()->viewAssets()->editAssets()->create())
->from(route('hardware.edit', $asset->id))
->put(route('hardware.update', $asset->id), [
->from(route('hardware.edit', $asset))
->put(route('hardware.update', $asset), [
'status_id' => $achived_status->id,
'model_id' => $asset->model_id,
'asset_tags' => $asset->asset_tag,

View file

@ -11,7 +11,7 @@ class ShowCategoryTest extends TestCase
public function testPageRenders()
{
$this->actingAs(User::factory()->superuser()->create())
->get(route('categories.show', Category::factory()->create()->id))
->get(route('categories.show', Category::factory()->create()))
->assertOk();
}
}

View file

@ -23,7 +23,7 @@ class UpdateCategoriesTest extends TestCase
public function testPageRenders()
{
$this->actingAs(User::factory()->superuser()->create())
->get(route('categories.edit', Category::factory()->create()->id))
->get(route('categories.edit', Category::factory()->create()))
->assertOk();
}
@ -47,7 +47,7 @@ class UpdateCategoriesTest extends TestCase
$this->assertTrue(Category::where('name', 'Test Category')->exists());
$response = $this->actingAs(User::factory()->superuser()->create())
->put(route('categories.update', ['category' => $category]), [
->put(route('categories.update', $category), [
'name' => 'Test Category Edited',
'notes' => 'Test Note Edited',
])
@ -66,8 +66,8 @@ class UpdateCategoriesTest extends TestCase
$this->assertTrue(Category::where('name', 'Test Category')->exists());
$response = $this->actingAs(User::factory()->superuser()->create())
->from(route('categories.edit', ['category' => $category->id]))
->put(route('categories.update', ['category' => $category]), [
->from(route('categories.edit', $category->id))
->put(route('categories.update', $category), [
'name' => 'Test Category Edited',
'category_type' => 'accessory',
'notes' => 'Test Note Edited',
@ -87,8 +87,8 @@ class UpdateCategoriesTest extends TestCase
$category = Category::where('name', 'Laptops')->first();
$response = $this->actingAs(User::factory()->superuser()->create())
->from(route('categories.edit', ['category' => $category->id]))
->put(route('categories.update', ['category' => $category]), [
->from(route('categories.edit', $category))
->put(route('categories.update', $category), [
'name' => 'Test Category Edited',
'category_type' => 'accessory',
'notes' => 'Test Note Edited',
@ -96,7 +96,7 @@ class UpdateCategoriesTest extends TestCase
->assertSessionHasErrors(['category_type'])
->assertInvalid(['category_type'])
->assertStatus(302)
->assertRedirect(route('categories.edit', ['category' => $category->id]));
->assertRedirect(route('categories.edit', $category));
$this->followRedirects($response)->assertSee(trans('general.error'));
$this->assertFalse(Category::where('name', 'Test Category Edited')->where('notes', 'Test Note Edited')->exists());

View file

@ -188,7 +188,7 @@ class AssetCheckinTest extends TestCase
->get(route('hardware.checkin.create', ['assetId' => $asset->id]))
->assertStatus(302)
->assertSessionHas('error')
->assertRedirect(route('hardware.show',['hardware' => $asset->id]));
->assertRedirect(route('hardware.show', $asset->id));
}
public function testAssetCheckinPagePostIsRedirectedIfModelIsInvalid()
@ -201,7 +201,7 @@ class AssetCheckinTest extends TestCase
->post(route('hardware.checkin.store', ['assetId' => $asset->id]))
->assertStatus(302)
->assertSessionHas('error')
->assertRedirect(route('hardware.show', ['hardware' => $asset->id]));
->assertRedirect(route('hardware.show', $asset));
}
public function testAssetCheckinPagePostIsRedirectedIfRedirectSelectionIsIndex()
@ -228,6 +228,6 @@ class AssetCheckinTest extends TestCase
])
->assertStatus(302)
->assertSessionHasNoErrors()
->assertRedirect(route('hardware.show', ['hardware' => $asset->id]));
->assertRedirect(route('hardware.show', $asset));
}
}

View file

@ -16,9 +16,7 @@ class ComponentCheckinTest extends TestCase
$componentAsset = DB::table('components_assets')->where('component_id', $component->id)->first();
$this->actingAs(User::factory()->create())
->post(route('components.checkin.store', [
'componentID' => $componentAsset->id,
]))
->post(route('components.checkin.store', $componentAsset->id))
->assertForbidden();
}
@ -67,6 +65,6 @@ class ComponentCheckinTest extends TestCase
])
->assertStatus(302)
->assertSessionHasNoErrors()
->assertRedirect(route('components.show', ['component' => $component->id]));
->assertRedirect(route('components.show', $component));
}
}

View file

@ -25,7 +25,7 @@ class AccessoryCheckoutTest extends TestCase
public function testPageRenders()
{
$this->actingAs(User::factory()->superuser()->create())
->get(route('accessories.checkout.show', Accessory::factory()->create()->id))
->get(route('accessories.checkout.show', Accessory::factory()->create()))
->assertOk();
}
@ -241,7 +241,7 @@ class AccessoryCheckoutTest extends TestCase
])
->assertStatus(302)
->assertSessionHasNoErrors()
->assertRedirect(route('accessories.show', ['accessory' => $accessory->id]));
->assertRedirect(route('accessories.show', $accessory));
}
public function testAccessoryCheckoutPagePostIsRedirectedIfRedirectSelectionIsTarget()
@ -258,6 +258,6 @@ class AccessoryCheckoutTest extends TestCase
'assigned_qty' => 1,
])
->assertStatus(302)
->assertRedirect(route('users.show', ['user' => $user]));
->assertRedirect(route('users.show', $user));
}
}

View file

@ -263,7 +263,7 @@ class AssetCheckoutTest extends TestCase
->get(route('hardware.checkout.create', ['assetId' => $asset->id]))
->assertStatus(302)
->assertSessionHas('error')
->assertRedirect(route('hardware.show',['hardware' => $asset->id]));
->assertRedirect(route('hardware.show', $asset));
}
public function testAssetCheckoutPagePostIsRedirectedIfRedirectSelectionIsIndex()
@ -294,7 +294,7 @@ class AssetCheckoutTest extends TestCase
])
->assertStatus(302)
->assertSessionHasNoErrors()
->assertRedirect(route('hardware.show', ['hardware' => $asset->id]));
->assertRedirect(route('hardware.show', $asset));
}
public function testAssetCheckoutPagePostIsRedirectedIfRedirectSelectionIsUserTarget()
@ -328,7 +328,7 @@ class AssetCheckoutTest extends TestCase
'assigned_qty' => 1,
])
->assertStatus(302)
->assertRedirect(route('hardware.show', ['hardware' => $target]));
->assertRedirect(route('hardware.show', $target));
}
public function testAssetCheckoutPagePostIsRedirectedIfRedirectSelectionIsLocationTarget()

View file

@ -76,7 +76,7 @@ class ComponentsCheckoutTest extends TestCase
'assigned_qty' => 1,
])
->assertStatus(302)
->assertRedirect(route('components.show', ['component' => $component->id]));
->assertRedirect(route('components.show', $component));
}
public function testComponentCheckoutPagePostIsRedirectedIfRedirectSelectionIsTarget()
@ -92,6 +92,6 @@ class ComponentsCheckoutTest extends TestCase
'assigned_qty' => 1,
])
->assertStatus(302)
->assertRedirect(route('hardware.show', ['hardware' => $asset]));
->assertRedirect(route('hardware.show', $asset));
}
}

View file

@ -130,7 +130,7 @@ class ConsumableCheckoutTest extends TestCase
'assigned_qty' => 1,
])
->assertStatus(302)
->assertRedirect(route('consumables.show', ['consumable' => $consumable->id]));
->assertRedirect(route('consumables.show', $consumable));
}
public function testConsumableCheckoutPagePostIsRedirectedIfRedirectSelectionIsTarget()
@ -146,7 +146,7 @@ class ConsumableCheckoutTest extends TestCase
'assigned_qty' => 1,
])
->assertStatus(302)
->assertRedirect(route('users.show', ['user' => $user]));
->assertRedirect(route('users.show', $user));
}
}

View file

@ -90,7 +90,7 @@ class LicenseCheckoutTest extends TestCase
'redirect_option' => 'item',
])
->assertStatus(302)
->assertRedirect(route('licenses.show', ['license' => $license->id]));
->assertRedirect(route('licenses.show', $license));
}
public function testLicenseCheckoutPagePostIsRedirectedIfRedirectSelectionIsUserTarget()
@ -105,7 +105,7 @@ class LicenseCheckoutTest extends TestCase
'redirect_option' => 'target',
])
->assertStatus(302)
->assertRedirect(route('users.show', ['user' => $user->id]));
->assertRedirect(route('users.show', $user));
}
public function testLicenseCheckoutPagePostIsRedirectedIfRedirectSelectionIsAssetTarget()
{
@ -119,6 +119,6 @@ class LicenseCheckoutTest extends TestCase
'redirect_option' => 'target',
])
->assertStatus(302)
->assertRedirect(route('hardware.show', ['hardware' => $asset->id]));
->assertRedirect(route('hardware.show', $asset));
}
}

View file

@ -11,7 +11,7 @@ class EditCompanyTest extends TestCase
public function testPageRenders()
{
$this->actingAs(User::factory()->superuser()->create())
->get(route('companies.edit', Company::factory()->create()->id))
->get(route('companies.edit', Company::factory()->create()))
->assertOk();
}
}

View file

@ -11,7 +11,7 @@ class ShowCompanyTest extends TestCase
public function testPageRenders()
{
$this->actingAs(User::factory()->superuser()->create())
->get(route('companies.show', Company::factory()->create()->id))
->get(route('companies.show', Company::factory()->create()))
->assertOk();
}
}

View file

@ -11,7 +11,7 @@ class EditComponentTest extends TestCase
public function testPageRenders()
{
$this->actingAs(User::factory()->superuser()->create())
->get(route('components.edit', Component::factory()->create()->id))
->get(route('components.edit', Component::factory()->create()))
->assertOk();
}
}

View file

@ -11,7 +11,7 @@ class ShowComponentTest extends TestCase
public function testPageRenders()
{
$this->actingAs(User::factory()->superuser()->create())
->get(route('components.show', Component::factory()->create()->id))
->get(route('components.show', Component::factory()->create()))
->assertOk();
}
}

View file

@ -11,7 +11,7 @@ class EditConsumableTest extends TestCase
public function testPageRenders()
{
$this->actingAs(User::factory()->superuser()->create())
->get(route('consumables.show', Consumable::factory()->create()->id))
->get(route('consumables.show', Consumable::factory()->create()))
->assertOk();
}
}

View file

@ -29,7 +29,7 @@ class UpdateConsumableTest extends TestCase
$userForCompanyB = User::factory()->editConsumables()->for($companyB)->create();
$this->actingAs($userForCompanyB)
->get(route('consumables.edit', $consumableForCompanyA->id))
->get(route('consumables.edit', $consumableForCompanyA))
->assertRedirect(route('consumables.index'));
}
@ -51,7 +51,7 @@ class UpdateConsumableTest extends TestCase
$userForCompanyB = User::factory()->editConsumables()->for($companyB)->create();
$this->actingAs($userForCompanyB)
->put(route('consumables.update', $consumableForCompanyA->id), [
->put(route('consumables.update', $consumableForCompanyA), [
//
])
->assertForbidden();
@ -99,7 +99,7 @@ class UpdateConsumableTest extends TestCase
];
$this->actingAs(User::factory()->createConsumables()->editConsumables()->create())
->put(route('consumables.update', $consumable->id), $data + [
->put(route('consumables.update', $consumable), $data + [
'redirect_option' => 'index',
'category_type' => 'consumable',
])

View file

@ -11,7 +11,7 @@ class ShowDepartmentTest extends TestCase
public function testPageRenders()
{
$this->actingAs(User::factory()->superuser()->create())
->get(route('departments.show', Department::factory()->create()->id))
->get(route('departments.show', Department::factory()->create()))
->assertOk();
}
}

View file

@ -22,7 +22,7 @@ class UpdateDepartmentsTest extends TestCase
public function testPageRenders()
{
$this->actingAs(User::factory()->superuser()->create())
->get(route('departments.edit', Department::factory()->create()->id))
->get(route('departments.edit', Department::factory()->create()))
->assertOk();
}
@ -32,7 +32,7 @@ class UpdateDepartmentsTest extends TestCase
$this->assertTrue(Department::where('name', 'Test Department')->exists());
$response = $this->actingAs(User::factory()->superuser()->create())
->put(route('departments.update', ['department' => $department]), [
->put(route('departments.update', $department), [
'name' => 'Test Department Edited',
'notes' => 'Test Note Edited',
])

View file

@ -11,7 +11,7 @@ class ShowLocationTest extends TestCase
public function testPageRenders()
{
$this->actingAs(User::factory()->superuser()->create())
->get(route('locations.show', Location::factory()->create()->id))
->get(route('locations.show', Location::factory()->create()))
->assertOk();
}
}

View file

@ -21,7 +21,7 @@ class UpdateLocationsTest extends TestCase
public function testPageRenders()
{
$this->actingAs(User::factory()->superuser()->create())
->get(route('locations.update', Location::factory()->create()->id))
->get(route('locations.update', Location::factory()->create()))
->assertOk();
}
@ -48,8 +48,8 @@ class UpdateLocationsTest extends TestCase
$location = Location::factory()->create();
$response = $this->actingAs(User::factory()->superuser()->create())
->from(route('locations.edit', ['location' => $location->id]))
->put(route('locations.update', ['location' => $location]), [
->from(route('locations.edit', $location))
->put(route('locations.update', $location), [
'name' => 'Test Location',
'parent_id' => $location->id,
])
@ -63,7 +63,7 @@ class UpdateLocationsTest extends TestCase
{
$location = Location::factory()->create();
$response = $this->actingAs(User::factory()->superuser()->create())
->from(route('locations.edit', ['location' => $location->id]))
->from(route('locations.edit', $location))
->put(route('locations.update', ['location' => $location]), [
'name' => 'Test Location',
'parent_id' => '100000000'

View file

@ -11,7 +11,7 @@ class ShowManufacturerTest extends TestCase
public function testPageRenders()
{
$this->actingAs(User::factory()->superuser()->create())
->get(route('manufacturers.show', Manufacturer::factory()->create()->id))
->get(route('manufacturers.show', Manufacturer::factory()->create()))
->assertOk();
}
}

View file

@ -11,7 +11,7 @@ class UpdateManufacturerTest extends TestCase
public function testPageRenders()
{
$this->actingAs(User::factory()->superuser()->create())
->get(route('manufacturers.edit', Manufacturer::factory()->create()->id))
->get(route('manufacturers.edit', Manufacturer::factory()->create()))
->assertOk();
}
@ -21,7 +21,7 @@ class UpdateManufacturerTest extends TestCase
$this->assertTrue(Manufacturer::where('name', 'Test Manufacturer')->exists());
$response = $this->actingAs(User::factory()->superuser()->create())
->put(route('manufacturers.update', ['manufacturer' => $manufacturer]), [
->put(route('manufacturers.update', $manufacturer), [
'name' => 'Test Manufacturer Edited',
'notes' => 'Test Note Edited',
])

View file

@ -11,7 +11,7 @@ class ShowStatusLabelTest extends TestCase
public function testPageRenders()
{
$this->actingAs(User::factory()->superuser()->create())
->get(route('statuslabels.show', Statuslabel::factory()->create()->id))
->get(route('statuslabels.show', Statuslabel::factory()->create()))
->assertOk();
}
}