diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php
index 6d32e8b6f..e9551d51a 100644
--- a/app/Http/Controllers/Api/UsersController.php
+++ b/app/Http/Controllers/Api/UsersController.php
@@ -661,7 +661,17 @@ class UsersController extends Controller
$user = User::find($request->get('id'));
$user->two_factor_secret = null;
$user->two_factor_enrolled = 0;
- $user->save();
+ $user->saveQuietly();
+
+ // Log the reset
+ $logaction = new Actionlog();
+ $logaction->target_type = User::class;
+ $logaction->target_id = $user->id;
+ $logaction->item_type = User::class;
+ $logaction->item_id = $user->id;
+ $logaction->created_at = date('Y-m-d H:i:s');
+ $logaction->user_id = Auth::user()->id;
+ $logaction->logaction('2FA reset');
return response()->json(['message' => trans('admin/settings/general.two_factor_reset_success')], 200);
} catch (\Exception $e) {
diff --git a/app/Http/Controllers/Assets/AssetsController.php b/app/Http/Controllers/Assets/AssetsController.php
index 0683a54e3..6054718e6 100755
--- a/app/Http/Controllers/Assets/AssetsController.php
+++ b/app/Http/Controllers/Assets/AssetsController.php
@@ -102,6 +102,10 @@ class AssetsController extends Controller
{
$this->authorize(Asset::class);
+ // There are a lot more rules to add here but prevents
+ // errors around `asset_tags` not being present below.
+ $this->validate($request, ['asset_tags' => ['required', 'array']]);
+
// Handle asset tags - there could be one, or potentially many.
// This is only necessary on create, not update, since bulk editing is handled
// differently
diff --git a/app/Http/Controllers/CustomFieldsController.php b/app/Http/Controllers/CustomFieldsController.php
index ffe5eceec..23ea9da34 100644
--- a/app/Http/Controllers/CustomFieldsController.php
+++ b/app/Http/Controllers/CustomFieldsController.php
@@ -260,7 +260,7 @@ class CustomFieldsController extends Controller
$field->name = trim(e($request->get("name")));
$field->element = e($request->get("element"));
- $field->field_values = e($request->get("field_values"));
+ $field->field_values = $request->get("field_values");
$field->user_id = Auth::id();
$field->help_text = $request->get("help_text");
$field->show_in_email = $show_in_email;
diff --git a/app/Presenters/ActionlogPresenter.php b/app/Presenters/ActionlogPresenter.php
index ddff10864..2794b6c5f 100644
--- a/app/Presenters/ActionlogPresenter.php
+++ b/app/Presenters/ActionlogPresenter.php
@@ -38,10 +38,14 @@ class ActionlogPresenter extends Presenter
public function icon()
{
-
+
// User related icons
if ($this->itemType() == 'user') {
+ if ($this->actionType()=='2fa reset') {
+ return 'fa-solid fa-mobile-screen';
+ }
+
if ($this->actionType()=='create new') {
return 'fa-solid fa-user-plus';
}
@@ -61,6 +65,7 @@ class ActionlogPresenter extends Presenter
if ($this->actionType()=='update') {
return 'fa-solid fa-user-pen';
}
+
return 'fa-solid fa-user';
}
diff --git a/resources/lang/en-US/admin/settings/general.php b/resources/lang/en-US/admin/settings/general.php
index 33cfd7b41..71fb8eb2c 100644
--- a/resources/lang/en-US/admin/settings/general.php
+++ b/resources/lang/en-US/admin/settings/general.php
@@ -261,7 +261,7 @@ return [
'two_factor_enrollment' => 'Two-Factor Enrollment',
'two_factor_enabled_text' => 'Enable Two Factor',
'two_factor_reset' => 'Reset Two-Factor Secret',
- 'two_factor_reset_help' => 'This will force the user to enroll their device with Google Authenticator again. This can be useful if their currently enrolled device is lost or stolen. ',
+ 'two_factor_reset_help' => 'This will force the user to enroll their device with their authenticator app again. This can be useful if their currently enrolled device is lost or stolen. ',
'two_factor_reset_success' => 'Two factor device successfully reset',
'two_factor_reset_error' => 'Two factor device reset failed',
'two_factor_enabled_warning' => 'Enabling two-factor if it is not currently enabled will immediately force you to authenticate with a Google Auth enrolled device. You will have the ability to enroll your device if one is not currently enrolled.',
diff --git a/resources/lang/en-US/general.php b/resources/lang/en-US/general.php
index bf1702484..9f9a0e08c 100644
--- a/resources/lang/en-US/general.php
+++ b/resources/lang/en-US/general.php
@@ -1,6 +1,7 @@
'2FA reset',
'accessories' => 'Accessories',
'activated' => 'Activated',
'accepted_date' => 'Date Accepted',
diff --git a/resources/views/models/custom_fields_form.blade.php b/resources/views/models/custom_fields_form.blade.php
index bae98373e..3c49ef8f7 100644
--- a/resources/views/models/custom_fields_form.blade.php
+++ b/resources/views/models/custom_fields_form.blade.php
@@ -9,7 +9,7 @@
@if ($field->element=='listbox')
{{ Form::select($field->db_column_name(), $field->formatFieldValuesAsArray(),
- Request::old($field->db_column_name(),(isset($item) ? Helper::gracefulDecrypt($field, htmlspecialchars($item->{$field->db_column_name()}, ENT_QUOTES)) : $field->defaultValue($model->id))), ['class'=>'format select2 form-control']) }}
+ Request::old($field->db_column_name(),(isset($item) ? Helper::gracefulDecrypt($field, $item->{$field->db_column_name()}) : $field->defaultValue($model->id))), ['class'=>'format select2 form-control']) }}
@elseif ($field->element=='textarea')
diff --git a/resources/views/models/custom_fields_form_bulk_edit.blade.php b/resources/views/models/custom_fields_form_bulk_edit.blade.php
index f30c60d33..dc0ad1f88 100644
--- a/resources/views/models/custom_fields_form_bulk_edit.blade.php
+++ b/resources/views/models/custom_fields_form_bulk_edit.blade.php
@@ -25,7 +25,7 @@
@if ($field->element=='listbox')
{{ Form::select($field->db_column_name(), $field->formatFieldValuesAsArray(),
- Request::old($field->db_column_name(),(isset($item) ? Helper::gracefulDecrypt($field, htmlspecialchars($item->{$field->db_column_name()}, ENT_QUOTES)) : $field->defaultValue($model->id))), ['class'=>'format select2 form-control']) }}
+ Request::old($field->db_column_name(),(isset($item) ? Helper::gracefulDecrypt($field, $item->{$field->db_column_name()}) : $field->defaultValue($model->id))), ['class'=>'format select2 form-control']) }}
@elseif ($field->element=='textarea')
@if($field->is_unique)
diff --git a/resources/views/users/edit.blade.php b/resources/views/users/edit.blade.php
index 8d24e440b..9a2a039af 100755
--- a/resources/views/users/edit.blade.php
+++ b/resources/views/users/edit.blade.php
@@ -499,18 +499,21 @@
@endif
-
-
- @if ((Auth::user()->isSuperUser()) && ($snipeSettings->two_factor_enabled!='0') && ($snipeSettings->two_factor_enabled!=''))
+ @if ((Auth::user()->isSuperUser()) && ($user->two_factor_active_and_enrolled()) && ($snipeSettings->two_factor_enabled!='0') && ($snipeSettings->two_factor_enabled!=''))
diff --git a/tests/Feature/Api/Accessories/AccessoryCheckoutTest.php b/tests/Feature/Api/Accessories/AccessoryCheckoutTest.php
index d65a3ad61..854a96ada 100644
--- a/tests/Feature/Api/Accessories/AccessoryCheckoutTest.php
+++ b/tests/Feature/Api/Accessories/AccessoryCheckoutTest.php
@@ -7,13 +7,10 @@ use App\Models\Actionlog;
use App\Models\User;
use App\Notifications\CheckoutAccessoryNotification;
use Illuminate\Support\Facades\Notification;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class AccessoryCheckoutTest extends TestCase
{
- use InteractsWithSettings;
-
public function testCheckingOutAccessoryRequiresCorrectPermission()
{
$this->actingAsForApi(User::factory()->create())
diff --git a/tests/Feature/Api/Assets/AssetCheckinTest.php b/tests/Feature/Api/Assets/AssetCheckinTest.php
index 6f8daf569..add90a067 100644
--- a/tests/Feature/Api/Assets/AssetCheckinTest.php
+++ b/tests/Feature/Api/Assets/AssetCheckinTest.php
@@ -11,13 +11,10 @@ use App\Models\Statuslabel;
use App\Models\User;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Event;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class AssetCheckinTest extends TestCase
{
- use InteractsWithSettings;
-
public function testCheckingInAssetRequiresCorrectPermission()
{
$this->actingAsForApi(User::factory()->create())
diff --git a/tests/Feature/Api/Assets/AssetIndexTest.php b/tests/Feature/Api/Assets/AssetIndexTest.php
index 778483c1c..3175db695 100644
--- a/tests/Feature/Api/Assets/AssetIndexTest.php
+++ b/tests/Feature/Api/Assets/AssetIndexTest.php
@@ -6,13 +6,10 @@ use App\Models\Asset;
use App\Models\Company;
use App\Models\User;
use Illuminate\Testing\Fluent\AssertableJson;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class AssetIndexTest extends TestCase
{
- use InteractsWithSettings;
-
public function testAssetIndexReturnsExpectedAssets()
{
Asset::factory()->count(3)->create();
diff --git a/tests/Feature/Api/Assets/AssetStoreTest.php b/tests/Feature/Api/Assets/AssetStoreTest.php
index 92a58a500..ceae05364 100644
--- a/tests/Feature/Api/Assets/AssetStoreTest.php
+++ b/tests/Feature/Api/Assets/AssetStoreTest.php
@@ -9,15 +9,11 @@ use App\Models\Location;
use App\Models\Statuslabel;
use App\Models\Supplier;
use App\Models\User;
-use Carbon\Carbon;
use Illuminate\Testing\Fluent\AssertableJson;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class AssetStoreTest extends TestCase
{
- use InteractsWithSettings;
-
public function testRequiresPermissionToCreateAsset()
{
$this->actingAsForApi(User::factory()->create())
diff --git a/tests/Feature/Api/Assets/AssetsForSelectListTest.php b/tests/Feature/Api/Assets/AssetsForSelectListTest.php
index cccae38d3..3c5e1e4e7 100644
--- a/tests/Feature/Api/Assets/AssetsForSelectListTest.php
+++ b/tests/Feature/Api/Assets/AssetsForSelectListTest.php
@@ -5,13 +5,10 @@ namespace Tests\Feature\Api\Assets;
use App\Models\Asset;
use App\Models\Company;
use App\Models\User;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class AssetsForSelectListTest extends TestCase
{
- use InteractsWithSettings;
-
public function testAssetsCanBeSearchedForByAssetTag()
{
Asset::factory()->create(['asset_tag' => '0001']);
diff --git a/tests/Feature/Api/Assets/RequestableAssetsTest.php b/tests/Feature/Api/Assets/RequestableAssetsTest.php
index 8649b1b00..d90e45f22 100644
--- a/tests/Feature/Api/Assets/RequestableAssetsTest.php
+++ b/tests/Feature/Api/Assets/RequestableAssetsTest.php
@@ -5,13 +5,10 @@ namespace Tests\Feature\Api\Assets;
use App\Models\Asset;
use App\Models\Company;
use App\Models\User;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class RequestableAssetsTest extends TestCase
{
- use InteractsWithSettings;
-
public function testViewingRequestableAssetsRequiresCorrectPermission()
{
$this->actingAsForApi(User::factory()->create())
diff --git a/tests/Feature/Api/Components/ComponentIndexTest.php b/tests/Feature/Api/Components/ComponentIndexTest.php
index ee83b7a46..517724a49 100644
--- a/tests/Feature/Api/Components/ComponentIndexTest.php
+++ b/tests/Feature/Api/Components/ComponentIndexTest.php
@@ -5,13 +5,10 @@ namespace Tests\Feature\Api\Components;
use App\Models\Company;
use App\Models\Component;
use App\Models\User;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class ComponentIndexTest extends TestCase
{
- use InteractsWithSettings;
-
public function testComponentIndexAdheresToCompanyScoping()
{
[$companyA, $companyB] = Company::factory()->count(2)->create();
diff --git a/tests/Feature/Api/Consumables/ConsumableCheckoutTest.php b/tests/Feature/Api/Consumables/ConsumableCheckoutTest.php
index 103be96ac..1528e65aa 100644
--- a/tests/Feature/Api/Consumables/ConsumableCheckoutTest.php
+++ b/tests/Feature/Api/Consumables/ConsumableCheckoutTest.php
@@ -7,13 +7,10 @@ use App\Models\Consumable;
use App\Models\User;
use App\Notifications\CheckoutConsumableNotification;
use Illuminate\Support\Facades\Notification;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class ConsumableCheckoutTest extends TestCase
{
- use InteractsWithSettings;
-
public function testCheckingOutConsumableRequiresCorrectPermission()
{
$this->actingAsForApi(User::factory()->create())
diff --git a/tests/Feature/Api/Consumables/ConsumablesIndexTest.php b/tests/Feature/Api/Consumables/ConsumablesIndexTest.php
index 33c10ed07..00fa43da2 100644
--- a/tests/Feature/Api/Consumables/ConsumablesIndexTest.php
+++ b/tests/Feature/Api/Consumables/ConsumablesIndexTest.php
@@ -5,13 +5,10 @@ namespace Tests\Feature\Api\Consumables;
use App\Models\Company;
use App\Models\Consumable;
use App\Models\User;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class ConsumablesIndexTest extends TestCase
{
- use InteractsWithSettings;
-
public function testConsumableIndexAdheresToCompanyScoping()
{
[$companyA, $companyB] = Company::factory()->count(2)->create();
diff --git a/tests/Feature/Api/Departments/DepartmentIndexTest.php b/tests/Feature/Api/Departments/DepartmentIndexTest.php
index 1a3884308..11ab5df9b 100644
--- a/tests/Feature/Api/Departments/DepartmentIndexTest.php
+++ b/tests/Feature/Api/Departments/DepartmentIndexTest.php
@@ -5,15 +5,11 @@ namespace Tests\Feature\Api\Departments;
use App\Models\Company;
use App\Models\Department;
use App\Models\User;
-use Illuminate\Routing\Route;
use Illuminate\Testing\Fluent\AssertableJson;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class DepartmentIndexTest extends TestCase
{
- use InteractsWithSettings;
-
public function testViewingDepartmentIndexRequiresAuthentication()
{
$this->getJson(route('api.departments.index'))->assertRedirect();
diff --git a/tests/Feature/Api/Groups/GroupStoreTest.php b/tests/Feature/Api/Groups/GroupStoreTest.php
index 9ffba5191..31a69fb46 100644
--- a/tests/Feature/Api/Groups/GroupStoreTest.php
+++ b/tests/Feature/Api/Groups/GroupStoreTest.php
@@ -4,13 +4,10 @@ namespace Tests\Feature\Api\Groups;
use App\Models\Group;
use App\Models\User;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class GroupStoreTest extends TestCase
{
- use InteractsWithSettings;
-
public function testStoringGroupRequiresSuperAdminPermission()
{
$this->actingAsForApi(User::factory()->create())
diff --git a/tests/Feature/Api/Licenses/LicensesIndexTest.php b/tests/Feature/Api/Licenses/LicensesIndexTest.php
index a21a27da7..603002a09 100644
--- a/tests/Feature/Api/Licenses/LicensesIndexTest.php
+++ b/tests/Feature/Api/Licenses/LicensesIndexTest.php
@@ -5,13 +5,10 @@ namespace Tests\Feature\Api\Licenses;
use App\Models\Company;
use App\Models\License;
use App\Models\User;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class LicensesIndexTest extends TestCase
{
- use InteractsWithSettings;
-
public function testLicensesIndexAdheresToCompanyScoping()
{
[$companyA, $companyB] = Company::factory()->count(2)->create();
diff --git a/tests/Feature/Api/Locations/LocationsForSelectListTest.php b/tests/Feature/Api/Locations/LocationsForSelectListTest.php
index 4170cfc7f..bfc7fc537 100644
--- a/tests/Feature/Api/Locations/LocationsForSelectListTest.php
+++ b/tests/Feature/Api/Locations/LocationsForSelectListTest.php
@@ -5,13 +5,10 @@ namespace Tests\Feature\Api\Locations;
use App\Models\Location;
use App\Models\User;
use Illuminate\Testing\Fluent\AssertableJson;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class LocationsForSelectListTest extends TestCase
{
- use InteractsWithSettings;
-
public function testGettingLocationListRequiresProperPermission()
{
$this->actingAsForApi(User::factory()->create())
diff --git a/tests/Feature/Api/Users/UpdateUserApiTest.php b/tests/Feature/Api/Users/UpdateUserApiTest.php
index 0786b171e..f58aae4a0 100644
--- a/tests/Feature/Api/Users/UpdateUserApiTest.php
+++ b/tests/Feature/Api/Users/UpdateUserApiTest.php
@@ -3,13 +3,10 @@
namespace Tests\Feature\Api\Users;
use App\Models\User;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class UpdateUserApiTest extends TestCase
{
- use InteractsWithSettings;
-
public function testApiUsersCanBeActivatedWithNumber()
{
$admin = User::factory()->superuser()->create();
diff --git a/tests/Feature/Api/Users/UsersForSelectListTest.php b/tests/Feature/Api/Users/UsersForSelectListTest.php
index 8cdf700f0..1ebfcf72e 100644
--- a/tests/Feature/Api/Users/UsersForSelectListTest.php
+++ b/tests/Feature/Api/Users/UsersForSelectListTest.php
@@ -6,13 +6,10 @@ use App\Models\Company;
use App\Models\User;
use Illuminate\Testing\Fluent\AssertableJson;
use Laravel\Passport\Passport;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class UsersForSelectListTest extends TestCase
{
- use InteractsWithSettings;
-
public function testUsersAreReturned()
{
$users = User::factory()->superuser()->count(3)->create();
diff --git a/tests/Feature/Api/Users/UsersSearchTest.php b/tests/Feature/Api/Users/UsersSearchTest.php
index 723a115db..72f23017f 100644
--- a/tests/Feature/Api/Users/UsersSearchTest.php
+++ b/tests/Feature/Api/Users/UsersSearchTest.php
@@ -5,13 +5,10 @@ namespace Tests\Feature\Api\Users;
use App\Models\Company;
use App\Models\User;
use Laravel\Passport\Passport;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class UsersSearchTest extends TestCase
{
- use InteractsWithSettings;
-
public function testCanSearchByUserFirstAndLastName()
{
User::factory()->create(['first_name' => 'Luke', 'last_name' => 'Skywalker']);
diff --git a/tests/Feature/Api/Users/UsersUpdateTest.php b/tests/Feature/Api/Users/UsersUpdateTest.php
index 953a671cf..d6e0f9e46 100644
--- a/tests/Feature/Api/Users/UsersUpdateTest.php
+++ b/tests/Feature/Api/Users/UsersUpdateTest.php
@@ -8,13 +8,10 @@ use App\Models\Group;
use App\Models\Location;
use App\Models\User;
use Illuminate\Support\Facades\Hash;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class UsersUpdateTest extends TestCase
{
- use InteractsWithSettings;
-
public function testCanUpdateUserViaPatch()
{
$admin = User::factory()->superuser()->create();
diff --git a/tests/Feature/Checkins/AccessoryCheckinTest.php b/tests/Feature/Checkins/AccessoryCheckinTest.php
index 25cd5d0d8..56030991e 100644
--- a/tests/Feature/Checkins/AccessoryCheckinTest.php
+++ b/tests/Feature/Checkins/AccessoryCheckinTest.php
@@ -8,13 +8,10 @@ use App\Models\User;
use App\Notifications\CheckinAccessoryNotification;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Notification;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class AccessoryCheckinTest extends TestCase
{
- use InteractsWithSettings;
-
public function testCheckingInAccessoryRequiresCorrectPermission()
{
$accessory = Accessory::factory()->checkedOutToUser()->create();
diff --git a/tests/Feature/Checkins/AssetCheckinTest.php b/tests/Feature/Checkins/AssetCheckinTest.php
index fb6d21a6a..1e6d2b995 100644
--- a/tests/Feature/Checkins/AssetCheckinTest.php
+++ b/tests/Feature/Checkins/AssetCheckinTest.php
@@ -11,13 +11,10 @@ use App\Models\Statuslabel;
use App\Models\User;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Event;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class AssetCheckinTest extends TestCase
{
- use InteractsWithSettings;
-
public function testCheckingInAssetRequiresCorrectPermission()
{
$this->actingAs(User::factory()->create())
diff --git a/tests/Feature/CheckoutAcceptances/AccessoryAcceptanceTest.php b/tests/Feature/CheckoutAcceptances/AccessoryAcceptanceTest.php
index a49b1167c..bdaf0e780 100644
--- a/tests/Feature/CheckoutAcceptances/AccessoryAcceptanceTest.php
+++ b/tests/Feature/CheckoutAcceptances/AccessoryAcceptanceTest.php
@@ -7,13 +7,10 @@ use App\Models\CheckoutAcceptance;
use App\Notifications\AcceptanceAssetAcceptedNotification;
use App\Notifications\AcceptanceAssetDeclinedNotification;
use Notification;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class AccessoryAcceptanceTest extends TestCase
{
- use InteractsWithSettings;
-
/**
* This can be absorbed into a bigger test
*/
diff --git a/tests/Feature/Checkouts/AccessoryCheckoutTest.php b/tests/Feature/Checkouts/AccessoryCheckoutTest.php
index cbe9801cc..11224e4d1 100644
--- a/tests/Feature/Checkouts/AccessoryCheckoutTest.php
+++ b/tests/Feature/Checkouts/AccessoryCheckoutTest.php
@@ -7,13 +7,10 @@ use App\Models\Actionlog;
use App\Models\User;
use App\Notifications\CheckoutAccessoryNotification;
use Illuminate\Support\Facades\Notification;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class AccessoryCheckoutTest extends TestCase
{
- use InteractsWithSettings;
-
public function testCheckingOutAccessoryRequiresCorrectPermission()
{
$this->actingAs(User::factory()->create())
diff --git a/tests/Feature/Checkouts/ConsumableCheckoutTest.php b/tests/Feature/Checkouts/ConsumableCheckoutTest.php
index 5785d0572..e38ae96c8 100644
--- a/tests/Feature/Checkouts/ConsumableCheckoutTest.php
+++ b/tests/Feature/Checkouts/ConsumableCheckoutTest.php
@@ -7,13 +7,10 @@ use App\Models\Consumable;
use App\Models\User;
use App\Notifications\CheckoutConsumableNotification;
use Illuminate\Support\Facades\Notification;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class ConsumableCheckoutTest extends TestCase
{
- use InteractsWithSettings;
-
public function testCheckingOutConsumableRequiresCorrectPermission()
{
$this->actingAs(User::factory()->create())
diff --git a/tests/Feature/Checkouts/LicenseCheckoutTest.php b/tests/Feature/Checkouts/LicenseCheckoutTest.php
index 978fac28f..2f4f51d4a 100644
--- a/tests/Feature/Checkouts/LicenseCheckoutTest.php
+++ b/tests/Feature/Checkouts/LicenseCheckoutTest.php
@@ -6,13 +6,10 @@ use App\Models\Asset;
use App\Models\License;
use App\Models\LicenseSeat;
use App\Models\User;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class LicenseCheckoutTest extends TestCase
{
- use InteractsWithSettings;
-
public function testNotesAreStoredInActionLogOnCheckoutToAsset()
{
$admin = User::factory()->superuser()->create();
diff --git a/tests/Feature/DashboardTest.php b/tests/Feature/DashboardTest.php
index 4e9459fb0..4690a1390 100644
--- a/tests/Feature/DashboardTest.php
+++ b/tests/Feature/DashboardTest.php
@@ -3,13 +3,10 @@
namespace Tests\Feature;
use App\Models\User;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class DashboardTest extends TestCase
{
- use InteractsWithSettings;
-
public function testUsersWithoutAdminAccessAreRedirected()
{
$this->actingAs(User::factory()->create())
diff --git a/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php b/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php
index dbe79c572..4ae415f1e 100644
--- a/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php
+++ b/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php
@@ -7,7 +7,6 @@ use App\Models\Asset;
use App\Models\User;
use App\Notifications\CheckinAssetNotification;
use Illuminate\Support\Facades\Notification;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
/**
@@ -15,8 +14,6 @@ use Tests\TestCase;
*/
class EmailNotificationsUponCheckinTest extends TestCase
{
- use InteractsWithSettings;
-
protected function setUp(): void
{
parent::setUp();
diff --git a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php
index b6bb7801a..29bf06d9d 100644
--- a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php
+++ b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckinTest.php
@@ -14,7 +14,6 @@ use App\Notifications\CheckinAssetNotification;
use App\Notifications\CheckinLicenseSeatNotification;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Notification;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
/**
@@ -22,8 +21,6 @@ use Tests\TestCase;
*/
class SlackNotificationsUponCheckinTest extends TestCase
{
- use InteractsWithSettings;
-
protected function setUp(): void
{
parent::setUp();
diff --git a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php
index 550f7c5b1..048448cad 100644
--- a/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php
+++ b/tests/Feature/Notifications/Webhooks/SlackNotificationsUponCheckoutTest.php
@@ -16,7 +16,6 @@ use App\Notifications\CheckoutConsumableNotification;
use App\Notifications\CheckoutLicenseSeatNotification;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Notification;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
/**
@@ -24,8 +23,6 @@ use Tests\TestCase;
*/
class SlackNotificationsUponCheckoutTest extends TestCase
{
- use InteractsWithSettings;
-
protected function setUp(): void
{
parent::setUp();
diff --git a/tests/Feature/Reports/CustomReportTest.php b/tests/Feature/Reports/CustomReportTest.php
index dd3199212..d90e4cb2a 100644
--- a/tests/Feature/Reports/CustomReportTest.php
+++ b/tests/Feature/Reports/CustomReportTest.php
@@ -8,14 +8,10 @@ use App\Models\User;
use Illuminate\Testing\TestResponse;
use League\Csv\Reader;
use PHPUnit\Framework\Assert;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
-
class CustomReportTest extends TestCase
{
- use InteractsWithSettings;
-
protected function setUp(): void
{
parent::setUp();
diff --git a/tests/Feature/Users/UpdateUserTest.php b/tests/Feature/Users/UpdateUserTest.php
index 92245059e..934fbce2b 100644
--- a/tests/Feature/Users/UpdateUserTest.php
+++ b/tests/Feature/Users/UpdateUserTest.php
@@ -3,13 +3,10 @@
namespace Tests\Feature\Users;
use App\Models\User;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class UpdateUserTest extends TestCase
{
- use InteractsWithSettings;
-
public function testUsersCanBeActivatedWithNumber()
{
$admin = User::factory()->superuser()->create();
diff --git a/tests/Support/InteractsWithSettings.php b/tests/Support/InitializesSettings.php
similarity index 90%
rename from tests/Support/InteractsWithSettings.php
rename to tests/Support/InitializesSettings.php
index a8c007018..7c08e6f89 100644
--- a/tests/Support/InteractsWithSettings.php
+++ b/tests/Support/InitializesSettings.php
@@ -4,7 +4,7 @@ namespace Tests\Support;
use App\Models\Setting;
-trait InteractsWithSettings
+trait InitializesSettings
{
protected Settings $settings;
diff --git a/tests/TestCase.php b/tests/TestCase.php
index 535f9a3e2..0c5ecc37e 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -9,7 +9,7 @@ use RuntimeException;
use Tests\Support\AssertsAgainstSlackNotifications;
use Tests\Support\CustomTestMacros;
use Tests\Support\InteractsWithAuthentication;
-use Tests\Support\InteractsWithSettings;
+use Tests\Support\InitializesSettings;
abstract class TestCase extends BaseTestCase
{
@@ -17,6 +17,7 @@ abstract class TestCase extends BaseTestCase
use CreatesApplication;
use CustomTestMacros;
use InteractsWithAuthentication;
+ use InitializesSettings;
use LazilyRefreshDatabase;
private array $globallyDisabledMiddleware = [
@@ -25,20 +26,23 @@ abstract class TestCase extends BaseTestCase
protected function setUp(): void
{
- if (!file_exists(realpath(__DIR__ . '/../') . '/.env.testing')) {
- throw new RuntimeException(
- '.env.testing file does not exist. Aborting to avoid wiping your local database'
- );
- }
+ $this->guardAgainstMissingEnv();
parent::setUp();
+ $this->registerCustomMacros();
+
$this->withoutMiddleware($this->globallyDisabledMiddleware);
- if (collect(class_uses_recursive($this))->contains(InteractsWithSettings::class)) {
- $this->initializeSettings();
- }
+ $this->initializeSettings();
+ }
- $this->registerCustomMacros();
+ private function guardAgainstMissingEnv(): void
+ {
+ if (!file_exists(realpath(__DIR__ . '/../') . '/.env.testing')) {
+ throw new RuntimeException(
+ '.env.testing file does not exist. Aborting to avoid wiping your local database.'
+ );
+ }
}
}
diff --git a/tests/Unit/AssetMaintenanceTest.php b/tests/Unit/AssetMaintenanceTest.php
index 69c4c3093..46a0efdd7 100644
--- a/tests/Unit/AssetMaintenanceTest.php
+++ b/tests/Unit/AssetMaintenanceTest.php
@@ -2,14 +2,10 @@
namespace Tests\Unit;
use App\Models\AssetMaintenance;
-use Carbon\Carbon;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class AssetMaintenanceTest extends TestCase
{
- use InteractsWithSettings;
-
public function testZerosOutWarrantyIfBlank()
{
$c = new AssetMaintenance;
diff --git a/tests/Unit/AssetModelTest.php b/tests/Unit/AssetModelTest.php
index aec8edf69..4cc62e20a 100644
--- a/tests/Unit/AssetModelTest.php
+++ b/tests/Unit/AssetModelTest.php
@@ -4,13 +4,10 @@ namespace Tests\Unit;
use App\Models\Asset;
use App\Models\Category;
use App\Models\AssetModel;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class AssetModelTest extends TestCase
{
- use InteractsWithSettings;
-
public function testAnAssetModelContainsAssets()
{
$category = Category::factory()->create([
diff --git a/tests/Unit/AssetTest.php b/tests/Unit/AssetTest.php
index d3d9a9011..9c3a76af6 100644
--- a/tests/Unit/AssetTest.php
+++ b/tests/Unit/AssetTest.php
@@ -5,13 +5,10 @@ use App\Models\Asset;
use App\Models\AssetModel;
use App\Models\Category;
use Carbon\Carbon;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class AssetTest extends TestCase
{
- use InteractsWithSettings;
-
public function testAutoIncrement()
{
$this->settings->enableAutoIncrement();
diff --git a/tests/Unit/CategoryTest.php b/tests/Unit/CategoryTest.php
index e5c98a67a..c3c9b0de8 100644
--- a/tests/Unit/CategoryTest.php
+++ b/tests/Unit/CategoryTest.php
@@ -4,13 +4,10 @@ namespace Tests\Unit;
use App\Models\Category;
use App\Models\AssetModel;
use App\Models\Asset;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class CategoryTest extends TestCase
{
- use InteractsWithSettings;
-
public function testFailsEmptyValidation()
{
// An Asset requires a name, a qty, and a category_id.
diff --git a/tests/Unit/CompanyScopingTest.php b/tests/Unit/CompanyScopingTest.php
index 669dd5ed4..3923dd9f7 100644
--- a/tests/Unit/CompanyScopingTest.php
+++ b/tests/Unit/CompanyScopingTest.php
@@ -12,13 +12,10 @@ use App\Models\License;
use App\Models\LicenseSeat;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class CompanyScopingTest extends TestCase
{
- use InteractsWithSettings;
-
public function models(): array
{
return [
diff --git a/tests/Unit/ComponentTest.php b/tests/Unit/ComponentTest.php
index 8f71057bf..df8f64771 100644
--- a/tests/Unit/ComponentTest.php
+++ b/tests/Unit/ComponentTest.php
@@ -5,13 +5,10 @@ use App\Models\Category;
use App\Models\Company;
use App\Models\Component;
use App\Models\Location;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class ComponentTest extends TestCase
{
- use InteractsWithSettings;
-
public function testAComponentBelongsToACompany()
{
$component = Component::factory()
diff --git a/tests/Unit/DepreciationTest.php b/tests/Unit/DepreciationTest.php
index ed033cf44..4dd842227 100644
--- a/tests/Unit/DepreciationTest.php
+++ b/tests/Unit/DepreciationTest.php
@@ -5,13 +5,10 @@ use App\Models\Depreciation;
use App\Models\Category;
use App\Models\License;
use App\Models\AssetModel;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class DepreciationTest extends TestCase
{
- use InteractsWithSettings;
-
public function testADepreciationHasModels()
{
$depreciation = Depreciation::factory()->create();
diff --git a/tests/Unit/LdapTest.php b/tests/Unit/LdapTest.php
index c286b3849..6beb0d211 100644
--- a/tests/Unit/LdapTest.php
+++ b/tests/Unit/LdapTest.php
@@ -3,8 +3,6 @@
namespace Tests\Unit;
use App\Models\Ldap;
-use Exception;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
/**
@@ -12,7 +10,6 @@ use Tests\TestCase;
*/
class LdapTest extends TestCase
{
- use InteractsWithSettings;
use \phpmock\phpunit\PHPMock;
public function testConnect()
diff --git a/tests/Unit/Models/Company/GetIdForCurrentUserTest.php b/tests/Unit/Models/Company/GetIdForCurrentUserTest.php
index 1ca88d7ca..6d77c8873 100644
--- a/tests/Unit/Models/Company/GetIdForCurrentUserTest.php
+++ b/tests/Unit/Models/Company/GetIdForCurrentUserTest.php
@@ -4,13 +4,10 @@ namespace Tests\Unit\Models\Company;
use App\Models\Company;
use App\Models\User;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class GetIdForCurrentUserTest extends TestCase
{
- use InteractsWithSettings;
-
public function testReturnsProvidedValueWhenFullCompanySupportDisabled()
{
$this->settings->disableMultipleFullCompanySupport();
diff --git a/tests/Unit/NotificationTest.php b/tests/Unit/NotificationTest.php
index 64cf8afb0..8005759a1 100644
--- a/tests/Unit/NotificationTest.php
+++ b/tests/Unit/NotificationTest.php
@@ -8,13 +8,10 @@ use App\Models\Category;
use Carbon\Carbon;
use App\Notifications\CheckoutAssetNotification;
use Illuminate\Support\Facades\Notification;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class NotificationTest extends TestCase
{
- use InteractsWithSettings;
-
public function testAUserIsEmailedIfTheyCheckoutAnAssetWithEULA()
{
$admin = User::factory()->superuser()->create();
diff --git a/tests/Unit/SnipeModelTest.php b/tests/Unit/SnipeModelTest.php
index ad4231010..2bc81da61 100644
--- a/tests/Unit/SnipeModelTest.php
+++ b/tests/Unit/SnipeModelTest.php
@@ -2,13 +2,10 @@
namespace Tests\Unit;
use App\Models\SnipeModel;
-use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class SnipeModelTest extends TestCase
{
- use InteractsWithSettings;
-
public function testSetsPurchaseDatesAppropriately()
{
$c = new SnipeModel;