From d05dea95109e925e3f1f65c2042c23c8e5f077c0 Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Sat, 29 Jun 2024 15:03:17 +0100 Subject: [PATCH] Make `Asset::clearCaches` protected (#308) * Add asset blink test * Bump core requirement --- composer.json | 2 +- src/Assets/Asset.php | 2 +- tests/Assets/AssetTest.php | 54 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 tests/Assets/AssetTest.php diff --git a/composer.json b/composer.json index 0a6f7934..5b134ff9 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ }, "require": { "php": "^8.1", - "statamic/cms": "^5.7" + "statamic/cms": "^5.12" }, "require-dev": { "doctrine/dbal": "^3.8", diff --git a/src/Assets/Asset.php b/src/Assets/Asset.php index 6404c507..5d917cab 100644 --- a/src/Assets/Asset.php +++ b/src/Assets/Asset.php @@ -223,7 +223,7 @@ public function getCurrentDirtyStateAttributes(): array ]); } - private function clearCaches() + protected function clearCaches() { $this->meta = null; diff --git a/tests/Assets/AssetTest.php b/tests/Assets/AssetTest.php new file mode 100644 index 00000000..98a7fc8d --- /dev/null +++ b/tests/Assets/AssetTest.php @@ -0,0 +1,54 @@ + '/assets']); + + $this->container = tap(Facades\AssetContainer::make('test')->disk('test'))->save(); + + Storage::disk('test')->put('a.jpg', ''); + Facades\Asset::make()->container('test')->path('a.jpg')->save(); + + Storage::disk('test')->put('b.txt', ''); + Facades\Asset::make()->container('test')->path('b.txt')->save(); + + Storage::disk('test')->put('c.txt', ''); + Facades\Asset::make()->container('test')->path('c.txt')->save(); + + Storage::disk('test')->put('d.jpg', ''); + Facades\Asset::make()->container('test')->path('d.jpg')->save(); + + Storage::disk('test')->put('e.jpg', ''); + Facades\Asset::make()->container('test')->path('e.jpg')->save(); + + Storage::disk('test')->put('f.jpg', ''); + Facades\Asset::make()->container('test')->path('f.jpg')->save(); + } + + /** @test */ + public function saving_an_asset_clears_the_eloquent_blink_cache() + { + $asset = Facades\Asset::find('test::f.jpg'); + + $this->assertTrue(Facades\Blink::has("eloquent-asset-{$asset->id()}")); + + $asset->save(); + + $this->assertFalse(Facades\Blink::has("eloquent-asset-{$asset->id()}")); + } +}