From 5a6cf2a2969a9286d30f1cc78b2aafa45c8bf2e8 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 12 May 2025 11:44:25 -0700 Subject: [PATCH] Add test for existing functionality --- tests/Unit/AssetTest.php | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/Unit/AssetTest.php b/tests/Unit/AssetTest.php index aea894f9fb..743545d9da 100644 --- a/tests/Unit/AssetTest.php +++ b/tests/Unit/AssetTest.php @@ -199,4 +199,45 @@ class AssetTest extends TestCase ]); $this->assertModelMissing($asset); } + + public function testGetImageUrlMethod() + { + $urlBase = config('filesystems.disks.public.url'); + + $category = Category::factory()->create([ + 'image' => 'category-image.jpg', + ]); + + $model = AssetModel::factory()->for($category)->create([ + 'image' => 'asset-model-image.jpg', + ]); + + $asset = Asset::factory()->for($model, 'model')->create([ + 'image' => 'asset-image.jpg', + ]); + + $this->assertEquals( + "{$urlBase}/assets/asset-image.jpg", + $asset->getImageUrl() + ); + + $asset->update(['image' => null]); + + $this->assertEquals( + "{$urlBase}/models/asset-model-image.jpg", + $asset->refresh()->getImageUrl() + ); + + $model->update(['image' => null]); + + $this->assertEquals( + "{$urlBase}/categories/category-image.jpg", + $asset->refresh()->getImageUrl() + ); + + $category->image = null; + $category->save(); + + $this->assertFalse($asset->refresh()->getImageUrl()); + } }