2016-12-19 11:04:28 -08:00
|
|
|
<?php
|
2021-11-30 20:09:29 -08:00
|
|
|
namespace Tests\Unit;
|
2016-12-19 11:04:28 -08:00
|
|
|
|
|
|
|
use App\Models\Accessory;
|
|
|
|
use App\Models\Asset;
|
|
|
|
use App\Models\Component;
|
|
|
|
use App\Models\Consumable;
|
|
|
|
use App\Models\License;
|
|
|
|
use App\Models\User;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
2021-11-30 20:09:29 -08:00
|
|
|
use Tests\Unit\BaseTest;
|
2016-12-19 11:04:28 -08:00
|
|
|
|
2017-07-11 20:37:02 -07:00
|
|
|
class PermissionsTest extends BaseTest
|
2016-12-19 11:04:28 -08:00
|
|
|
{
|
2017-06-12 17:39:03 -07:00
|
|
|
public function _before()
|
2016-12-19 11:04:28 -08:00
|
|
|
{
|
2017-07-11 20:37:02 -07:00
|
|
|
parent::_before();
|
2016-12-19 11:04:28 -08:00
|
|
|
$this->noHardware = [
|
2017-06-12 17:39:03 -07:00
|
|
|
'assets.view' => false,
|
|
|
|
'assets.create' => false,
|
|
|
|
'assets.edit' => false,
|
|
|
|
'assets.delete' => false,
|
2016-12-19 11:04:28 -08:00
|
|
|
];
|
|
|
|
|
|
|
|
$this->noLicenses = [
|
2017-06-12 17:39:03 -07:00
|
|
|
'licenses.view' => false,
|
|
|
|
'licenses.create' => false,
|
|
|
|
'licenses.edit' => false,
|
|
|
|
'licenses.delete' => false,
|
2016-12-19 11:04:28 -08:00
|
|
|
];
|
|
|
|
|
|
|
|
$this->noAccessories = [
|
2017-06-12 17:39:03 -07:00
|
|
|
'accessories.view' => false,
|
|
|
|
'accessories.create' => false,
|
|
|
|
'accessories.edit' => false,
|
|
|
|
'accessories.delete' => false,
|
2016-12-19 11:04:28 -08:00
|
|
|
];
|
|
|
|
|
|
|
|
$this->noConsumables = [
|
2017-06-12 17:39:03 -07:00
|
|
|
'consumables.view' => false,
|
|
|
|
'consumables.create' => false,
|
|
|
|
'consumables.edit' => false,
|
|
|
|
'consumables.delete' => false,
|
2016-12-19 11:04:28 -08:00
|
|
|
];
|
|
|
|
|
|
|
|
$this->noComponents = [
|
2017-06-12 17:39:03 -07:00
|
|
|
'components.view' => false,
|
|
|
|
'components.create' => false,
|
|
|
|
'components.edit' => false,
|
|
|
|
'components.delete' => false,
|
2016-12-19 11:04:28 -08:00
|
|
|
];
|
|
|
|
|
|
|
|
$this->noUsers = [
|
2017-06-12 17:39:03 -07:00
|
|
|
'users.view' => false,
|
|
|
|
'users.create' => false,
|
|
|
|
'users.edit' => false,
|
|
|
|
'users.delete' => false,
|
2016-12-19 11:04:28 -08:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
private $noHardware;
|
|
|
|
private $noLicenses;
|
|
|
|
private $noAccessories;
|
|
|
|
private $noConsumables;
|
|
|
|
private $noComponents;
|
|
|
|
private $noUsers;
|
|
|
|
|
|
|
|
// tests
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2016-12-19 11:04:28 -08:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function a_user_with_no_permissions_sees_nothing()
|
|
|
|
{
|
2021-06-10 13:17:44 -07:00
|
|
|
$u = \App\Models\User::factory()->create();
|
2016-12-19 11:04:28 -08:00
|
|
|
$permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers;
|
|
|
|
// $permissions = $this->noHardware;
|
|
|
|
$this->hitRoutes($permissions, $u);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function a_user_with_view_asset_permissions_can_view_assets()
|
|
|
|
{
|
2021-06-10 13:17:44 -07:00
|
|
|
$u = \App\Models\User::factory()->viewAssets()->create();
|
2016-12-19 11:04:28 -08:00
|
|
|
$permissions = $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers;
|
|
|
|
|
|
|
|
$permissions = array_merge($permissions, [
|
2017-06-12 17:39:03 -07:00
|
|
|
'assets.view' => true,
|
|
|
|
'assets.create' => false,
|
|
|
|
'assets.edit' => false,
|
|
|
|
'assets.delete' => false,
|
2016-12-19 11:04:28 -08:00
|
|
|
]);
|
|
|
|
$this->hitRoutes($permissions, $u);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function a_user_with_create_asset_permissions_can_create_assets()
|
|
|
|
{
|
2021-06-10 13:17:44 -07:00
|
|
|
$u = \App\Models\User::factory()->createAssets()->create();
|
2016-12-19 11:04:28 -08:00
|
|
|
$permissions = $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers;
|
|
|
|
|
|
|
|
$permissions = array_merge($permissions, [
|
2017-06-12 17:39:03 -07:00
|
|
|
'assets.view' => false,
|
|
|
|
'assets.create' => true,
|
|
|
|
'assets.edit' => false,
|
|
|
|
'assets.delete' => false,
|
2016-12-19 11:04:28 -08:00
|
|
|
]);
|
|
|
|
$this->hitRoutes($permissions, $u);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function a_user_with_edit_assets_permissions_can_edit_assets()
|
|
|
|
{
|
2021-06-10 13:17:44 -07:00
|
|
|
$u = \App\Models\User::factory()->editAssets()->create();
|
2016-12-19 11:04:28 -08:00
|
|
|
|
|
|
|
$permissions = $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers;
|
|
|
|
|
|
|
|
$permissions = array_merge($permissions, [
|
2017-06-12 17:39:03 -07:00
|
|
|
'assets.view' => false,
|
|
|
|
'assets.create' => false,
|
|
|
|
'assets.edit' => true,
|
|
|
|
'assets.delete' => false,
|
|
|
|
]);
|
|
|
|
$this->hitRoutes($permissions, $u);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function a_user_with_delete_assets_permissions_can_delete_assets()
|
|
|
|
{
|
2021-06-10 13:17:44 -07:00
|
|
|
$u = \App\Models\User::factory()->deleteAssets()->create();
|
2017-06-12 17:39:03 -07:00
|
|
|
$permissions = $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers;
|
|
|
|
$permissions = array_merge($permissions, [
|
|
|
|
'assets.view' => false,
|
|
|
|
'assets.create' => false,
|
|
|
|
'assets.edit' => false,
|
|
|
|
'assets.delete' => true,
|
2016-12-19 11:04:28 -08:00
|
|
|
]);
|
|
|
|
$this->hitRoutes($permissions, $u);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function a_user_with_view_licenses_permissions_can_view_licenses()
|
|
|
|
{
|
2021-06-10 13:17:44 -07:00
|
|
|
$u = \App\Models\User::factory()->viewLicenses()->create();
|
2016-12-19 11:04:28 -08:00
|
|
|
$permissions = $this->noHardware + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers;
|
|
|
|
|
|
|
|
$permissions = array_merge($permissions, [
|
2017-06-12 17:39:03 -07:00
|
|
|
'licenses.view' => true,
|
|
|
|
'licenses.create' => false,
|
|
|
|
'licenses.edit' => false,
|
|
|
|
'licenses.delete' => false,
|
2016-12-19 11:04:28 -08:00
|
|
|
]);
|
|
|
|
$this->hitRoutes($permissions, $u);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function a_user_with_create_licenses_permissions_can_create_licenses()
|
|
|
|
{
|
2021-06-10 13:17:44 -07:00
|
|
|
$u = \App\Models\User::factory()->createLicenses()->create();
|
2016-12-19 11:04:28 -08:00
|
|
|
$permissions = $this->noHardware + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers;
|
|
|
|
|
|
|
|
$permissions = array_merge($permissions, [
|
2017-06-12 17:39:03 -07:00
|
|
|
'licenses.view' => false,
|
|
|
|
'licenses.create' => true,
|
|
|
|
'licenses.edit' => false,
|
|
|
|
'licenses.delete' => false,
|
2016-12-19 11:04:28 -08:00
|
|
|
]);
|
|
|
|
$this->hitRoutes($permissions, $u);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function a_user_with_edit_licenses_permissions_can_edit_licenses()
|
|
|
|
{
|
2021-06-10 13:17:44 -07:00
|
|
|
$u = \App\Models\User::factory()->editLicenses()->create();
|
2016-12-19 11:04:28 -08:00
|
|
|
$permissions = $this->noHardware + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers;
|
|
|
|
|
|
|
|
$permissions = array_merge($permissions, [
|
2017-06-12 17:39:03 -07:00
|
|
|
'licenses.view' => false,
|
|
|
|
'licenses.create' => false,
|
|
|
|
'licenses.edit' => true,
|
|
|
|
'licenses.delete' => false,
|
|
|
|
]);
|
|
|
|
$this->hitRoutes($permissions, $u);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function a_user_with_delete_licenses_permissions_can_delete_licenses()
|
|
|
|
{
|
2021-06-10 13:17:44 -07:00
|
|
|
$u = \App\Models\User::factory()->deleteLicenses()->create();
|
2017-06-12 17:39:03 -07:00
|
|
|
$permissions = $this->noHardware + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers;
|
|
|
|
|
|
|
|
$permissions = array_merge($permissions, [
|
|
|
|
'licenses.view' => false,
|
|
|
|
'licenses.create' => false,
|
|
|
|
'licenses.edit' => false,
|
|
|
|
'licenses.delete' => true,
|
2016-12-19 11:04:28 -08:00
|
|
|
]);
|
|
|
|
$this->hitRoutes($permissions, $u);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
2021-06-10 13:15:52 -07:00
|
|
|
*/
|
2016-12-19 11:04:28 -08:00
|
|
|
public function a_user_with_view_accessories_permissions_can_view_accessories()
|
|
|
|
{
|
2021-06-10 13:17:44 -07:00
|
|
|
$u = \App\Models\User::factory()->viewAccessories()->create();
|
2016-12-19 11:04:28 -08:00
|
|
|
|
|
|
|
$permissions = $this->noHardware + $this->noLicenses + $this->noConsumables + $this->noComponents + $this->noUsers;
|
|
|
|
|
|
|
|
$permissions = array_merge($permissions, [
|
2017-06-12 17:39:03 -07:00
|
|
|
'accessories.view' => true,
|
|
|
|
'accessories.create' => false,
|
|
|
|
'accessories.edit' => false,
|
|
|
|
'accessories.delete' => false,
|
2016-12-19 11:04:28 -08:00
|
|
|
]);
|
|
|
|
$this->hitRoutes($permissions, $u);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function a_user_with_create_accessories_permissions_can_create_accessories()
|
|
|
|
{
|
2021-06-10 13:17:44 -07:00
|
|
|
$u = \App\Models\User::factory()->createAccessories()->create();
|
2016-12-19 11:04:28 -08:00
|
|
|
|
|
|
|
$permissions = $this->noHardware + $this->noLicenses + $this->noConsumables + $this->noComponents + $this->noUsers;
|
|
|
|
|
|
|
|
$permissions = array_merge($permissions, [
|
2017-06-12 17:39:03 -07:00
|
|
|
'accessories.view' => false,
|
|
|
|
'accessories.create' => true,
|
|
|
|
'accessories.edit' => false,
|
|
|
|
'accessories.delete' => false,
|
2016-12-19 11:04:28 -08:00
|
|
|
]);
|
|
|
|
$this->hitRoutes($permissions, $u);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function a_user_with_edit_accessories_permissions_can_edit_accessories()
|
|
|
|
{
|
2021-06-10 13:17:44 -07:00
|
|
|
$u = \App\Models\User::factory()->editAccessories()->create();
|
2017-06-12 17:39:03 -07:00
|
|
|
|
|
|
|
$permissions = $this->noHardware + $this->noLicenses + $this->noConsumables + $this->noComponents + $this->noUsers;
|
|
|
|
|
|
|
|
$permissions = array_merge($permissions, [
|
|
|
|
'accessories.view' => false,
|
|
|
|
'accessories.create' => false,
|
|
|
|
'accessories.edit' => true,
|
|
|
|
'accessories.delete' => false,
|
|
|
|
]);
|
|
|
|
$this->hitRoutes($permissions, $u);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function a_user_with_delete_accessories_permissions_can_delete_accessories()
|
|
|
|
{
|
2021-06-10 13:17:44 -07:00
|
|
|
$u = \App\Models\User::factory()->deleteAccessories()->create();
|
2016-12-19 11:04:28 -08:00
|
|
|
|
|
|
|
$permissions = $this->noHardware + $this->noLicenses + $this->noConsumables + $this->noComponents + $this->noUsers;
|
|
|
|
|
|
|
|
$permissions = array_merge($permissions, [
|
2017-06-12 17:39:03 -07:00
|
|
|
'accessories.view' => false,
|
|
|
|
'accessories.create' => false,
|
|
|
|
'accessories.edit' => false,
|
|
|
|
'accessories.delete' => true,
|
2016-12-19 11:04:28 -08:00
|
|
|
]);
|
|
|
|
$this->hitRoutes($permissions, $u);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function a_user_with_view_consumables_permissions_can_view_consumables()
|
|
|
|
{
|
2021-06-10 13:17:44 -07:00
|
|
|
$u = \App\Models\User::factory()->viewConsumables()->create();
|
2016-12-19 11:04:28 -08:00
|
|
|
|
|
|
|
$permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noComponents + $this->noUsers;
|
|
|
|
|
|
|
|
$permissions = array_merge($permissions, [
|
2017-06-12 17:39:03 -07:00
|
|
|
'consumables.view' => true,
|
|
|
|
'consumables.create' => false,
|
|
|
|
'consumables.edit' => false,
|
|
|
|
'consumables.delete' => false,
|
2016-12-19 11:04:28 -08:00
|
|
|
]);
|
|
|
|
$this->hitRoutes($permissions, $u);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function a_user_with_create_consumables_permissions_can_create_consumables()
|
|
|
|
{
|
2021-06-10 13:17:44 -07:00
|
|
|
$u = \App\Models\User::factory()->createConsumables()->create();
|
2016-12-19 11:04:28 -08:00
|
|
|
|
|
|
|
$permissions = $this->noHardware + $this->noLicenses + $this->noConsumables + $this->noComponents + $this->noUsers;
|
|
|
|
|
|
|
|
$permissions = array_merge($permissions, [
|
2017-06-12 17:39:03 -07:00
|
|
|
'consumables.view' => false,
|
|
|
|
'consumables.create' => true,
|
|
|
|
'consumables.edit' => false,
|
|
|
|
'consumables.delete' => false,
|
2016-12-19 11:04:28 -08:00
|
|
|
]);
|
|
|
|
$this->hitRoutes($permissions, $u);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function a_user_with_edit_consumables_permissions_can_edit_consumables()
|
|
|
|
{
|
2021-06-10 13:17:44 -07:00
|
|
|
$u = \App\Models\User::factory()->editConsumables()->create();
|
2016-12-19 11:04:28 -08:00
|
|
|
|
|
|
|
$permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noComponents + $this->noUsers;
|
|
|
|
|
|
|
|
$permissions = array_merge($permissions, [
|
2017-06-12 17:39:03 -07:00
|
|
|
'consumables.view' => false,
|
|
|
|
'consumables.create' => false,
|
|
|
|
'consumables.edit' => true,
|
|
|
|
'consumables.delete' => false,
|
|
|
|
]);
|
|
|
|
$this->hitRoutes($permissions, $u);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function a_user_with_delete_consumables_permissions_can_delete_consumables()
|
|
|
|
{
|
2021-06-10 13:17:44 -07:00
|
|
|
$u = \App\Models\User::factory()->deleteConsumables()->create();
|
2017-06-12 17:39:03 -07:00
|
|
|
|
|
|
|
$permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noComponents + $this->noUsers;
|
|
|
|
|
|
|
|
$permissions = array_merge($permissions, [
|
|
|
|
'consumables.view' => false,
|
|
|
|
'consumables.create' => false,
|
|
|
|
'consumables.edit' => false,
|
|
|
|
'consumables.delete' => true,
|
2016-12-19 11:04:28 -08:00
|
|
|
]);
|
|
|
|
$this->hitRoutes($permissions, $u);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function a_user_with_view_users_permissions_can_view_users()
|
|
|
|
{
|
2021-06-10 13:17:44 -07:00
|
|
|
$u = \App\Models\User::factory()->viewUsers()->create();
|
2016-12-19 11:04:28 -08:00
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
$permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents;
|
2016-12-19 11:04:28 -08:00
|
|
|
|
|
|
|
$permissions = array_merge($permissions, [
|
2017-06-12 17:39:03 -07:00
|
|
|
'users.view' => true,
|
|
|
|
'users.create' => false,
|
|
|
|
'users.edit' => false,
|
|
|
|
'users.delete' => false,
|
2016-12-19 11:04:28 -08:00
|
|
|
]);
|
|
|
|
$this->hitRoutes($permissions, $u);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function a_user_with_create_users_permissions_can_create_users()
|
|
|
|
{
|
2021-06-10 13:17:44 -07:00
|
|
|
$u = \App\Models\User::factory()->createUsers()->create();
|
2016-12-19 11:04:28 -08:00
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
$permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents;
|
2016-12-19 11:04:28 -08:00
|
|
|
|
|
|
|
$permissions = array_merge($permissions, [
|
2017-06-12 17:39:03 -07:00
|
|
|
'users.view' => false,
|
|
|
|
'users.create' => true,
|
|
|
|
'users.edit' => false,
|
|
|
|
'users.delete' => false,
|
2016-12-19 11:04:28 -08:00
|
|
|
]);
|
|
|
|
$this->hitRoutes($permissions, $u);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function a_user_with_edit_users_permissions_can_edit_users()
|
|
|
|
{
|
2021-06-10 13:17:44 -07:00
|
|
|
$u = \App\Models\User::factory()->editUsers()->create();
|
2016-12-19 11:04:28 -08:00
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
$permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents;
|
2016-12-19 11:04:28 -08:00
|
|
|
|
|
|
|
$permissions = array_merge($permissions, [
|
2017-06-12 17:39:03 -07:00
|
|
|
'users.view' => false,
|
|
|
|
'users.create' => false,
|
|
|
|
'users.edit' => true,
|
|
|
|
'users.delete' => false,
|
|
|
|
]);
|
|
|
|
$this->hitRoutes($permissions, $u);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function a_user_with_delete_users_permissions_can_delete_users()
|
|
|
|
{
|
2021-06-10 13:17:44 -07:00
|
|
|
$u = \App\Models\User::factory()->deleteUsers()->create();
|
2017-06-12 17:39:03 -07:00
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
$permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents;
|
2017-06-12 17:39:03 -07:00
|
|
|
|
|
|
|
$permissions = array_merge($permissions, [
|
|
|
|
'users.view' => false,
|
|
|
|
'users.create' => false,
|
|
|
|
'users.edit' => false,
|
|
|
|
'users.delete' => true,
|
2016-12-19 11:04:28 -08:00
|
|
|
]);
|
|
|
|
$this->hitRoutes($permissions, $u);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function a_user_with_view_components_permissions_can_view_components()
|
|
|
|
{
|
2021-06-10 13:17:44 -07:00
|
|
|
$u = \App\Models\User::factory()->viewComponents()->create();
|
2016-12-19 11:04:28 -08:00
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
$permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noUsers;
|
2016-12-19 11:04:28 -08:00
|
|
|
|
|
|
|
$permissions = array_merge($permissions, [
|
2017-06-12 17:39:03 -07:00
|
|
|
'components.view' => true,
|
|
|
|
'components.create' => false,
|
|
|
|
'components.edit' => false,
|
|
|
|
'components.delete' => false,
|
2016-12-19 11:04:28 -08:00
|
|
|
]);
|
|
|
|
$this->hitRoutes($permissions, $u);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function a_user_with_create_components_permissions_can_create_components()
|
|
|
|
{
|
2021-06-10 13:17:44 -07:00
|
|
|
$u = \App\Models\User::factory()->createComponents()->create();
|
2021-06-10 13:15:52 -07:00
|
|
|
$permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noUsers;
|
2016-12-19 11:04:28 -08:00
|
|
|
|
|
|
|
$permissions = array_merge($permissions, [
|
2017-06-12 17:39:03 -07:00
|
|
|
'components.view' => false,
|
|
|
|
'components.create' => true,
|
|
|
|
'components.edit' => false,
|
|
|
|
'components.delete' => false,
|
2016-12-19 11:04:28 -08:00
|
|
|
]);
|
|
|
|
$this->hitRoutes($permissions, $u);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function a_user_with_edit_components_permissions_can_edit_components()
|
|
|
|
{
|
2021-06-10 13:17:44 -07:00
|
|
|
$u = \App\Models\User::factory()->editComponents()->create();
|
2016-12-19 11:04:28 -08:00
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
$permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noUsers;
|
2016-12-19 11:04:28 -08:00
|
|
|
|
|
|
|
$permissions = array_merge($permissions, [
|
2017-06-12 17:39:03 -07:00
|
|
|
'components.view' => false,
|
|
|
|
'components.create' => false,
|
|
|
|
'components.edit' => true,
|
|
|
|
'components.delete' => false,
|
2016-12-19 11:04:28 -08:00
|
|
|
]);
|
|
|
|
$this->hitRoutes($permissions, $u);
|
|
|
|
}
|
|
|
|
|
2017-06-12 17:39:03 -07:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function a_user_with_delete_components_permissions_can_delete_components()
|
2016-12-19 11:04:28 -08:00
|
|
|
{
|
2021-06-10 13:17:44 -07:00
|
|
|
$u = \App\Models\User::factory()->deleteComponents()->create();
|
2016-12-19 22:00:50 -08:00
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
$permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noUsers;
|
2017-06-12 17:39:03 -07:00
|
|
|
|
|
|
|
$permissions = array_merge($permissions, [
|
|
|
|
'components.view' => false,
|
|
|
|
'components.create' => false,
|
|
|
|
'components.edit' => false,
|
|
|
|
'components.delete' => true,
|
|
|
|
]);
|
|
|
|
// dd($u);
|
|
|
|
$this->hitRoutes($permissions, $u);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function hitRoutes(array $routes, User $user)
|
|
|
|
{
|
|
|
|
foreach ($routes as $route => $expectation) {
|
|
|
|
$this->assertEquals($user->hasAccess($route), $expectation);
|
2016-12-19 11:04:28 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|