diff --git a/app/Http/Controllers/Api/AssetMaintenancesController.php b/app/Http/Controllers/Api/AssetMaintenancesController.php
index 9df66dbab6d0..e486848730ec 100644
--- a/app/Http/Controllers/Api/AssetMaintenancesController.php
+++ b/app/Http/Controllers/Api/AssetMaintenancesController.php
@@ -4,6 +4,7 @@
use App\Helpers\Helper;
use App\Http\Controllers\Controller;
+use App\Http\Requests\ImageUploadRequest;
use App\Http\Transformers\AssetMaintenancesTransformer;
use App\Models\Asset;
use App\Models\AssetMaintenance;
@@ -126,14 +127,15 @@ public function index(Request $request) : JsonResponse | array
* @version v1.0
* @since [v1.8]
*/
- public function store(Request $request) : JsonResponse | array
+ public function store(ImageUploadRequest $request) : JsonResponse | array
{
$this->authorize('update', Asset::class);
+
// create a new model instance
$maintenance = new AssetMaintenance();
$maintenance->fill($request->all());
$maintenance->created_by = auth()->id();
-
+ $maintenance = $request->handleImages($maintenance);
// Was the asset maintenance created?
if ($maintenance->save()) {
return response()->json(Helper::formatStandardApiResponse('success', $maintenance, trans('admin/asset_maintenances/message.create.success')));
diff --git a/app/Http/Controllers/AssetMaintenancesController.php b/app/Http/Controllers/AssetMaintenancesController.php
index 0e46118af79e..3405d592ab8e 100644
--- a/app/Http/Controllers/AssetMaintenancesController.php
+++ b/app/Http/Controllers/AssetMaintenancesController.php
@@ -2,6 +2,7 @@
namespace App\Http\Controllers;
+use App\Http\Requests\ImageUploadRequest;
use App\Models\Asset;
use App\Models\AssetMaintenance;
use App\Models\Company;
@@ -69,7 +70,7 @@ public function create() : View
* @version v1.0
* @since [v1.8]
*/
- public function store(Request $request) : RedirectResponse
+ public function store(ImageUploadRequest $request) : RedirectResponse
{
$this->authorize('update', Asset::class);
@@ -101,6 +102,7 @@ public function store(Request $request) : RedirectResponse
$assetMaintenance->asset_maintenance_time = (int) $completionDate->diffInDays($startDate, true);
}
+ $assetMaintenance = $request->handleImages($assetMaintenance);
// Was the asset maintenance created?
if (!$assetMaintenance->save()) {
@@ -143,7 +145,7 @@ public function edit(AssetMaintenance $maintenance) : View | RedirectResponse
* @version v1.0
* @since [v1.8]
*/
- public function update(Request $request, AssetMaintenance $maintenance) : View | RedirectResponse
+ public function update(ImageUploadRequest $request, AssetMaintenance $maintenance) : View | RedirectResponse
{
$this->authorize('update', Asset::class);
$this->authorize('update', $maintenance->asset);
@@ -176,6 +178,7 @@ public function update(Request $request, AssetMaintenance $maintenance) : View |
$completionDate = Carbon::parse($maintenance->completion_date);
$maintenance->asset_maintenance_time = (int) $completionDate->diffInDays($startDate, true);
}
+ $maintenance = $request->handleImages($maintenance);
if ($maintenance->save()) {
return redirect()->route('maintenances.index')
diff --git a/app/Http/Requests/ImageUploadRequest.php b/app/Http/Requests/ImageUploadRequest.php
index abb0cee5f75f..52d61d5bd339 100644
--- a/app/Http/Requests/ImageUploadRequest.php
+++ b/app/Http/Requests/ImageUploadRequest.php
@@ -11,6 +11,7 @@
use Intervention\Image\Exception\NotReadableException;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Validator;
+use Illuminate\Support\Str;
class ImageUploadRequest extends Request
{
@@ -70,11 +71,12 @@ protected function base64FileKeys(): array
public function handleImages($item, $w = 600, $form_fieldname = 'image', $path = null, $db_fieldname = 'image')
{
- $type = strtolower(class_basename(get_class($item)));
+ $type = Str::snake(class_basename(get_class($item)));
if (is_null($path)) {
- $path = str_plural($type);
+ \Log::debug('path is null');
+ $path = Str::of(str_plural($type))->snake();
if ($type == 'assetmodel') {
$path = 'models';
@@ -85,6 +87,11 @@ public function handleImages($item, $w = 600, $form_fieldname = 'image', $path =
}
}
+
+ if (!Storage::exists($path)) {
+ Storage::makeDirectory($path);
+ }
+
if ($this->offsetGet($form_fieldname) instanceof UploadedFile) {
$image = $this->offsetGet($form_fieldname);
} elseif ($this->hasFile($form_fieldname)) {
@@ -96,7 +103,7 @@ public function handleImages($item, $w = 600, $form_fieldname = 'image', $path =
if (!config('app.lock_passwords')) {
$ext = $image->guessExtension();
- $file_name = $type.'-'.$form_fieldname.'-'.$item->id.'-'.str_random(10).'.'.$ext;
+ $file_name = $type.'-'.$form_fieldname.($item->id ?? '-'.$item->id).'-'.str_random(10).'.'.$ext;
if (($image->getMimeType() == 'image/vnd.microsoft.icon') || ($image->getMimeType() == 'image/x-icon') || ($image->getMimeType() == 'image/avif') || ($image->getMimeType() == 'image/webp')) {
// If the file is an icon, webp or avif, we need to just move it since gd doesn't support resizing
diff --git a/app/Http/Transformers/AssetMaintenancesTransformer.php b/app/Http/Transformers/AssetMaintenancesTransformer.php
index ab4ca04cc699..6106f134e404 100644
--- a/app/Http/Transformers/AssetMaintenancesTransformer.php
+++ b/app/Http/Transformers/AssetMaintenancesTransformer.php
@@ -7,6 +7,7 @@
use App\Models\AssetMaintenance;
use Illuminate\Support\Facades\Gate;
use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Support\Facades\Storage;
class AssetMaintenancesTransformer
{
@@ -33,6 +34,7 @@ public function transformAssetMaintenance(AssetMaintenance $assetmaintenance)
'created_at' => Helper::getFormattedDateObject($assetmaintenance->asset->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($assetmaintenance->asset->updated_at, 'datetime'),
] : null,
+ 'image' => ($assetmaintenance->image != '') ? Storage::disk('public')->url('asset_maintenances/'.e($assetmaintenance->image)) : null,
'model' => (($assetmaintenance->asset) && ($assetmaintenance->asset->model)) ? [
'id' => (int) $assetmaintenance->asset->model->id,
'name'=> ($assetmaintenance->asset->model->name) ? e($assetmaintenance->asset->model->name).' '.e($assetmaintenance->asset->model->model_number) : null,
diff --git a/app/Presenters/AssetMaintenancesPresenter.php b/app/Presenters/AssetMaintenancesPresenter.php
index 90d1ffe1f8f1..720b912c2373 100644
--- a/app/Presenters/AssetMaintenancesPresenter.php
+++ b/app/Presenters/AssetMaintenancesPresenter.php
@@ -30,6 +30,15 @@ public static function dataTableLayout()
'visible' => true,
'formatter' => 'maintenancesLinkFormatter',
],
+ [
+ 'field' => 'image',
+ 'searchable' => false,
+ 'sortable' => true,
+ 'switchable' => true,
+ 'title' => trans('general.image'),
+ 'visible' => true,
+ 'formatter' => 'imageFormatter',
+ ],
[
'field' => 'company',
'searchable' => true,
diff --git a/app/Providers/SettingsServiceProvider.php b/app/Providers/SettingsServiceProvider.php
index 9a533b9fb39b..2bb530de4ef3 100644
--- a/app/Providers/SettingsServiceProvider.php
+++ b/app/Providers/SettingsServiceProvider.php
@@ -31,7 +31,7 @@ public function boot()
// Make sure the limit is actually set, is an integer and does not exceed system limits
- \App::singleton('api_limit_value', function () {
+ app()->singleton('api_limit_value', function () {
$limit = config('app.max_results');
$int_limit = intval(request('limit'));
@@ -43,7 +43,7 @@ public function boot()
});
// Make sure the offset is actually set and is an integer
- \App::singleton('api_offset_value', function () {
+ app()->singleton('api_offset_value', function () {
$offset = intval(request('offset'));
return $offset;
});
@@ -57,117 +57,121 @@ public function boot()
// Model paths and URLs
- \App::singleton('eula_pdf_path', function () {
+ app()->singleton('eula_pdf_path', function () {
return 'eula_pdf_path/';
});
- \App::singleton('assets_upload_path', function () {
+ app()->singleton('assets_upload_path', function () {
return 'assets/';
});
- \App::singleton('audits_upload_path', function () {
+ app()->singleton('asset_maintenances_path', function () {
+ return 'asset_maintenances/';
+ });
+
+ app()->singleton('audits_upload_path', function () {
return 'audits/';
});
- \App::singleton('accessories_upload_path', function () {
+ app()->singleton('accessories_upload_path', function () {
return 'public/uploads/accessories/';
});
- \App::singleton('models_upload_path', function () {
+ app()->singleton('models_upload_path', function () {
return 'models/';
});
- \App::singleton('models_upload_url', function () {
+ app()->singleton('models_upload_url', function () {
return 'models/';
});
// Categories
- \App::singleton('categories_upload_path', function () {
+ app()->singleton('categories_upload_path', function () {
return 'categories/';
});
- \App::singleton('categories_upload_url', function () {
+ app()->singleton('categories_upload_url', function () {
return 'categories/';
});
// Locations
- \App::singleton('locations_upload_path', function () {
+ app()->singleton('locations_upload_path', function () {
return 'locations/';
});
- \App::singleton('locations_upload_url', function () {
+ app()->singleton('locations_upload_url', function () {
return 'locations/';
});
// Users
- \App::singleton('users_upload_path', function () {
+ app()->singleton('users_upload_path', function () {
return 'avatars/';
});
- \App::singleton('users_upload_url', function () {
+ app()->singleton('users_upload_url', function () {
return 'users/';
});
// Manufacturers
- \App::singleton('manufacturers_upload_path', function () {
+ app()->singleton('manufacturers_upload_path', function () {
return 'manufacturers/';
});
- \App::singleton('manufacturers_upload_url', function () {
+ app()->singleton('manufacturers_upload_url', function () {
return 'manufacturers/';
});
// Suppliers
- \App::singleton('suppliers_upload_path', function () {
+ app()->singleton('suppliers_upload_path', function () {
return 'suppliers/';
});
- \App::singleton('suppliers_upload_url', function () {
+ app()->singleton('suppliers_upload_url', function () {
return 'suppliers/';
});
// Departments
- \App::singleton('departments_upload_path', function () {
+ app()->singleton('departments_upload_path', function () {
return 'departments/';
});
- \App::singleton('departments_upload_url', function () {
+ app()->singleton('departments_upload_url', function () {
return 'departments/';
});
// Company paths and URLs
- \App::singleton('companies_upload_path', function () {
+ app()->singleton('companies_upload_path', function () {
return 'companies/';
});
- \App::singleton('companies_upload_url', function () {
+ app()->singleton('companies_upload_url', function () {
return 'companies/';
});
// Accessories paths and URLs
- \App::singleton('accessories_upload_path', function () {
+ app()->singleton('accessories_upload_path', function () {
return 'accessories/';
});
- \App::singleton('accessories_upload_url', function () {
+ app()->singleton('accessories_upload_url', function () {
return 'accessories/';
});
// Consumables paths and URLs
- \App::singleton('consumables_upload_path', function () {
+ app()->singleton('consumables_upload_path', function () {
return 'consumables/';
});
- \App::singleton('consumables_upload_url', function () {
+ app()->singleton('consumables_upload_url', function () {
return 'consumables/';
});
// Components paths and URLs
- \App::singleton('components_upload_path', function () {
+ app()->singleton('components_upload_path', function () {
return 'components/';
});
- \App::singleton('components_upload_url', function () {
+ app()->singleton('components_upload_url', function () {
return 'components/';
});
diff --git a/database/migrations/2025_08_06_192954_add_image_to_maintenances.php b/database/migrations/2025_08_06_192954_add_image_to_maintenances.php
new file mode 100644
index 000000000000..ab1bb424b4f1
--- /dev/null
+++ b/database/migrations/2025_08_06_192954_add_image_to_maintenances.php
@@ -0,0 +1,30 @@
+text('image')->after('notes')->nullable()->default(null);
+ }
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void
+ {
+ Schema::table('asset_maintenances', function (Blueprint $table) {
+ $table->dropColumn('image');
+ });
+ }
+};
diff --git a/resources/views/asset_maintenances/edit.blade.php b/resources/views/asset_maintenances/edit.blade.php
index 6ff7d7001bbd..0f270009e6a0 100644
--- a/resources/views/asset_maintenances/edit.blade.php
+++ b/resources/views/asset_maintenances/edit.blade.php
@@ -23,10 +23,10 @@
+ @include ('partials.forms.edit.image-upload', ['image_path' => app('asset_maintenances_path')])
+
+
-
+
+
+ @if ($assetMaintenance->image!='')
+
+
->url(app('asset_maintenances_path').e($assetMaintenance->image)) }})
+
+ @endif
+
+
+
+
+
+ @if ($assetMaintenance->notes)
+ -
+ {{ trans('general.notes') }}:
+ {!! nl2br(Helper::parseEscapedMarkedownInline($assetMaintenance->notes)) !!}
+
+ @endif
+
+ @if ($assetMaintenance->address!='')
+ - {{ $assetMaintenance->address }}
+ @endif
+ @if ($assetMaintenance->address2!='')
+ - {{ $assetMaintenance->address2 }}
+ @endif
+ @if (($assetMaintenance->city!='') || ($assetMaintenance->state!='') || ($assetMaintenance->zip!=''))
+ - {{ $assetMaintenance->city }} {{ $assetMaintenance->state }} {{ $assetMaintenance->zip }}
+ @endif
+ @if ($assetMaintenance->manager)
+ - {{ trans('admin/users/table.manager') }}: {!! $assetMaintenance->manager->present()->nameUrl() !!}
+ @endif
+ @if ($assetMaintenance->company)
+ - {{ trans('admin/companies/table.name') }}: {!! $assetMaintenance->company->present()->nameUrl() !!}
+ @endif
+ @if ($assetMaintenance->parent)
+ - {{ trans('admin/locations/table.parent') }}: {!! $assetMaintenance->parent->present()->nameUrl() !!}
+ @endif
+ @if ($assetMaintenance->ldap_ou)
+ - {{ trans('admin/locations/table.ldap_ou') }}: {{ $assetMaintenance->ldap_ou }}
+ @endif
+
+
+ @if ((($assetMaintenance->address!='') && ($assetMaintenance->city!='')) || ($assetMaintenance->state!='') || ($assetMaintenance->country!=''))
+ -
+
+ {!! trans('admin/locations/message.open_map', ['map_provider_icon' => '']) !!}
+
+
+
+ -
+
+ {!! trans('admin/locations/message.open_map', ['map_provider_icon' => '']) !!}
+
+
+ @endif
+
+
+
+
+ @can('update', $assetMaintenance)
+
+ @endcan
+
+
+
@stop
diff --git a/tests/Feature/AssetMaintenances/Api/CreateAssetMaintenanceTest.php b/tests/Feature/AssetMaintenances/Api/CreateAssetMaintenanceTest.php
new file mode 100644
index 000000000000..039ba8656c89
--- /dev/null
+++ b/tests/Feature/AssetMaintenances/Api/CreateAssetMaintenanceTest.php
@@ -0,0 +1,73 @@
+actingAsForApi(User::factory()->create())
+ ->postJson(route('api.maintenances.store'))
+ ->assertForbidden();
+ }
+ public function testCanCreateAssetMaintenance()
+ {
+
+ Storage::fake('public');
+ $actor = User::factory()->superuser()->create();
+
+ $asset = Asset::factory()->create();
+ $supplier = Supplier::factory()->create();
+
+ $response = $this->actingAsForApi($actor)
+ ->postJson(route('api.maintenances.store'), [
+ 'title' => 'Test Maintenance',
+ 'asset_id' => $asset->id,
+ 'supplier_id' => $supplier->id,
+ 'asset_maintenance_type' => 'Maintenance',
+ 'start_date' => '2021-01-01',
+ 'completion_date' => '2021-01-10',
+ 'is_warranty' => '1',
+ 'cost' => '100.00',
+ 'image' => UploadedFile::fake()->image('test_image.png'),
+ 'notes' => 'A note',
+ ])
+ ->assertOk()
+ ->assertStatus(200);
+
+ \Log::error($response->json());
+ // Since we rename the file in the ImageUploadRequest, we have to fetch the record from the database
+ $assetMaintenance = AssetMaintenance::where('title', 'Test Maintenance')->first();
+
+ // Assert file was stored...
+ Storage::disk('public')->assertExists(app('asset_maintenances_path').$assetMaintenance->image);
+
+ $this->assertDatabaseHas('asset_maintenances', [
+ 'asset_id' => $asset->id,
+ 'supplier_id' => $supplier->id,
+ 'asset_maintenance_type' => 'Maintenance',
+ 'title' => 'Test Maintenance',
+ 'is_warranty' => 1,
+ 'start_date' => '2021-01-01',
+ 'completion_date' => '2021-01-10',
+ 'notes' => 'A note',
+ 'image' => $assetMaintenance->image,
+ 'created_by' => $actor->id,
+ ]);
+ }
+
+
+
+}
diff --git a/tests/Feature/AssetMaintenances/Api/EditAssetMaintenanceTest.php b/tests/Feature/AssetMaintenances/Api/EditAssetMaintenanceTest.php
new file mode 100644
index 000000000000..e6c84f3088cc
--- /dev/null
+++ b/tests/Feature/AssetMaintenances/Api/EditAssetMaintenanceTest.php
@@ -0,0 +1,64 @@
+actingAs(User::factory()->superuser()->create())
+ ->get(route('maintenances.update', AssetMaintenance::factory()->create()->id))
+ ->assertOk();
+ }
+
+
+ public function testCanEditAssetMaintenance()
+ {
+ Storage::fake('public');
+ $actor = User::factory()->superuser()->create();
+ $asset = Asset::factory()->create();
+ $supplier = Supplier::factory()->create();
+ $maintenance = AssetMaintenance::factory()->create();
+
+ $response = $this->actingAs($actor)
+ ->followingRedirects()
+ ->patch(route('maintenances.update', $maintenance), [
+ 'title' => 'Test Maintenance',
+ 'supplier_id' => $supplier->id,
+ 'asset_maintenance_type' => 'Maintenance',
+ 'start_date' => '2021-01-01',
+ 'completion_date' => '2021-01-10',
+ 'is_warranty' => '1',
+ 'image' => UploadedFile::fake()->image('test_image.png'),
+ 'notes' => 'A note',
+ ])
+ ->assertOk();
+
+ $this->followRedirects($response)->assertSee('alert-success');
+
+ $maintenance->refresh();
+ // Assert file was stored...
+ Storage::disk('public')->assertExists(app('asset_maintenances_path').$maintenance->image);
+
+
+ $this->assertDatabaseHas('asset_maintenances', [
+ 'supplier_id' => $supplier->id,
+ 'asset_maintenance_type' => 'Maintenance',
+ 'title' => 'Test Maintenance',
+ 'is_warranty' => 1,
+ 'start_date' => '2021-01-01',
+ 'completion_date' => '2021-01-10',
+ 'asset_maintenance_time' => '9',
+ 'notes' => 'A note',
+ 'image' => $maintenance->image,
+ ]);
+ }
+}
diff --git a/tests/Feature/AssetMaintenances/Ui/CreateAssetMaintenanceTest.php b/tests/Feature/AssetMaintenances/Ui/CreateAssetMaintenanceTest.php
index 23227c7e6a3a..5ccf70eddba7 100644
--- a/tests/Feature/AssetMaintenances/Ui/CreateAssetMaintenanceTest.php
+++ b/tests/Feature/AssetMaintenances/Ui/CreateAssetMaintenanceTest.php
@@ -3,8 +3,11 @@
namespace Tests\Feature\AssetMaintenances\Ui;
use App\Models\Asset;
+use App\Models\AssetMaintenance;
use App\Models\Supplier;
use App\Models\User;
+use Illuminate\Http\UploadedFile;
+use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
class CreateAssetMaintenanceTest extends TestCase
@@ -19,6 +22,7 @@ public function testPageRenders()
public function testCanCreateAssetMaintenance()
{
+ Storage::fake('public');
$actor = User::factory()->superuser()->create();
$asset = Asset::factory()->create();
@@ -35,10 +39,18 @@ public function testCanCreateAssetMaintenance()
'completion_date' => '2021-01-10',
'is_warranty' => '1',
'cost' => '100.00',
+ 'image' => UploadedFile::fake()->image('test_image.png'),
'notes' => 'A note',
])
->assertOk();
+ // Since we rename the file in the ImageUploadRequest, we have to fetch the record from the database
+ $assetMaintenance = AssetMaintenance::where('title', 'Test Maintenance')->first();
+
+ // Assert file was stored...
+ Storage::disk('public')->assertExists(app('asset_maintenances_path').$assetMaintenance->image);
+
+
$this->assertDatabaseHas('asset_maintenances', [
'asset_id' => $asset->id,
'supplier_id' => $supplier->id,
@@ -50,6 +62,7 @@ public function testCanCreateAssetMaintenance()
'asset_maintenance_time' => '9',
'notes' => 'A note',
'cost' => '100.00',
+ 'image' => $assetMaintenance->image,
'created_by' => $actor->id,
]);
}
diff --git a/tests/Feature/AssetMaintenances/Ui/EditAssetMaintenanceTest.php b/tests/Feature/AssetMaintenances/Ui/EditAssetMaintenanceTest.php
index a622a5dec731..e898cc49904a 100644
--- a/tests/Feature/AssetMaintenances/Ui/EditAssetMaintenanceTest.php
+++ b/tests/Feature/AssetMaintenances/Ui/EditAssetMaintenanceTest.php
@@ -6,6 +6,8 @@
use App\Models\AssetMaintenance;
use App\Models\Supplier;
use App\Models\User;
+use Illuminate\Http\UploadedFile;
+use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
class EditAssetMaintenanceTest extends TestCase
@@ -34,11 +36,17 @@ public function testCanUpdateAssetMaintenance()
'start_date' => '2021-01-01',
'completion_date' => '2021-01-10',
'is_warranty' => 1,
+ 'image' => UploadedFile::fake()->image('test_image.png'),
'cost' => '100.99',
'notes' => 'A note',
])
->assertOk();
+ // Since we rename the file in the ImageUploadRequest, we have to fetch the record from the database
+ $assetMaintenance = AssetMaintenance::where('title', 'Test Maintenance')->first();
+
+ // Assert file was stored...
+ Storage::disk('public')->assertExists(app('asset_maintenances_path').$assetMaintenance->image);
$this->assertDatabaseHas('asset_maintenances', [
'asset_id' => $asset->id,
diff --git a/tests/Feature/Settings/BrandingSettingsTest.php b/tests/Feature/Settings/BrandingSettingsTest.php
index d751a1ab47a5..2cb052437cb9 100644
--- a/tests/Feature/Settings/BrandingSettingsTest.php
+++ b/tests/Feature/Settings/BrandingSettingsTest.php
@@ -44,26 +44,29 @@ public function testLogoCanBeUploaded()
$response = $this->actingAs(User::factory()->superuser()->create())
->post(route('settings.branding.save',
- ['logo' => UploadedFile::fake()->image('test_logo.png')->storeAs('', 'test_logo.png', 'public')]
+ ['logo' => UploadedFile::fake()->image('test_logo.png')]
))
->assertValid('logo')
->assertStatus(302)
->assertRedirect(route('settings.index'))
->assertSessionHasNoErrors();
+ // Assert files was stored...
+ Storage::disk('public')->assertExists( $setting->logo);
+
$this->followRedirects($response)->assertSee('alert-success');
$setting->refresh();
- Storage::disk('public')->assertExists($setting->logo);
}
+
public function testLogoCanBeDeleted()
{
Storage::fake('public');
+ UploadedFile::fake()->image('new_test_logo.png')->storeAs('uploads', 'new_test_logo.png', 'public');
$setting = Setting::factory()->create(['logo' => 'new_test_logo.png']);
- $original_file = UploadedFile::fake()->image('new_test_logo.png')->storeAs('uploads', 'new_test_logo.png', 'public');
- Storage::disk('public')->assertExists($original_file);
+ Storage::disk('public')->assertExists('uploads/'.$setting->logo);
$this->assertNotNull($setting->logo);
@@ -78,17 +81,13 @@ public function testLogoCanBeDeleted()
$this->followRedirects($response)->assertSee(trans('alert-success'));
$this->assertDatabaseHas('settings', ['logo' => null]);
- //Storage::disk('public')->assertMissing($original_file);
+ Storage::disk('public')->assertMissing($setting->logo);
}
public function testEmailLogoCanBeUploaded()
{
Storage::fake('public');
-
- $original_file = UploadedFile::fake()->image('before_test_email_logo.png')->storeAs('', 'before_test_email_logo.png', 'public');
-
- Storage::disk('public')->assertExists($original_file);
- Setting::factory()->create(['email_logo' => $original_file]);
+ Setting::factory()->create(['email_logo' => null]);
$response = $this->actingAs(User::factory()->superuser()->create())
->from(route('settings.branding.index'))
@@ -104,16 +103,14 @@ public function testEmailLogoCanBeUploaded()
$this->followRedirects($response)->assertSee(trans('alert-success'));
Storage::disk('public')->assertExists('new_test_email_logo.png');
- // Storage::disk('public')->assertMissing($original_file);
}
public function testEmailLogoCanBeDeleted()
{
Storage::fake('public');
-
- $setting = Setting::factory()->create(['email_logo' => 'new_test_email_logo.png']);
- $original_file = UploadedFile::fake()->image('new_test_email_logo.png')->storeAs('', 'new_test_email_logo.png', 'public');
- Storage::disk('public')->assertExists($original_file);
+ UploadedFile::fake()->image('new_test_logo.png')->storeAs('uploads', 'new_test_logo.png', 'public');
+ $setting = Setting::factory()->create(['email_logo' => 'new_test_logo.png']);
+ Storage::disk('public')->assertExists('uploads/'.$setting->email_logo);
$this->assertNotNull($setting->email_logo);
@@ -125,11 +122,12 @@ public function testEmailLogoCanBeDeleted()
->assertValid('email_logo')
->assertStatus(302)
->assertRedirect(route('settings.index'));
+
$setting->refresh();
$this->followRedirects($response)->assertSee(trans('alert-success'));
$this->assertDatabaseHas('settings', ['email_logo' => null]);
- //Storage::disk('public')->assertMissing('new_test_email_logo.png');
+ Storage::disk('public')->assertMissing('new_test_email_logo.png');
}
@@ -168,9 +166,9 @@ public function testLabelLogoCanBeDeleted()
Storage::fake('public');
+ UploadedFile::fake()->image('new_test_label_logo.png')->storeAs('uploads', 'new_test_label_logo.png', 'public');
$setting = Setting::factory()->create(['label_logo' => 'new_test_label_logo.png']);
- $original_file = UploadedFile::fake()->image('new_test_label_logo.png')->storeAs('', 'new_test_label_logo.png', 'public');
- Storage::disk('public')->assertExists($original_file);
+ Storage::disk('public')->assertExists('uploads/'.$setting->label_logo);
$this->assertNotNull($setting->label_logo);
@@ -185,8 +183,7 @@ public function testLabelLogoCanBeDeleted()
$setting->refresh();
$this->followRedirects($response)->assertSee(trans('alert-success'));
- // $this->assertNull($setting->refresh()->logo);
- // Storage::disk('public')->assertMissing($original_file);
+ Storage::disk('public')->assertMissing('new_test_label_logo.png');
}