From a7f97df48366b89c9b995efe6e246ba8f38ba393 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Tue, 7 May 2024 22:26:05 +0100 Subject: [PATCH] [4.x] Include `alt` field in shallowly augmented assets (#10013) --- src/Assets/Asset.php | 2 +- tests/Fieldtypes/AssetsTest.php | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Assets/Asset.php b/src/Assets/Asset.php index 86f18026c3..d7004eebbe 100644 --- a/src/Assets/Asset.php +++ b/src/Assets/Asset.php @@ -1063,7 +1063,7 @@ public function defaultAugmentedArrayKeys() public function shallowAugmentedArrayKeys() { - return ['id', 'url', 'permalink', 'api_url']; + return ['id', 'url', 'permalink', 'api_url', 'alt']; } protected function defaultAugmentedRelations() diff --git a/tests/Fieldtypes/AssetsTest.php b/tests/Fieldtypes/AssetsTest.php index 1abd1d0548..8788cf0621 100644 --- a/tests/Fieldtypes/AssetsTest.php +++ b/tests/Fieldtypes/AssetsTest.php @@ -69,6 +69,20 @@ public function it_augments_to_a_single_asset_when_max_files_is_one() /** @test */ public function it_shallow_augments_to_a_collection_of_assets() { + AssetContainer::find('test') + ->queryAssets() + ->where('path', 'foo/one.txt') + ->first() + ->set('alt', 'Alt text for one') + ->save(); + + AssetContainer::find('test') + ->queryAssets() + ->where('path', 'bar/two.txt') + ->first() + ->set('alt', 'Alt text for two') + ->save(); + $augmented = $this->fieldtype()->shallowAugment(['foo/one.txt', 'bar/two.txt', 'unknown.txt']); $this->assertInstanceOf(Collection::class, $augmented); @@ -79,12 +93,14 @@ public function it_shallow_augments_to_a_collection_of_assets() 'url' => '/assets/foo/one.txt', 'permalink' => 'http://localhost/assets/foo/one.txt', 'api_url' => 'http://localhost/api/assets/test/foo/one.txt', + 'alt' => 'Alt text for one', ], [ 'id' => 'test::bar/two.txt', 'url' => '/assets/bar/two.txt', 'permalink' => 'http://localhost/assets/bar/two.txt', 'api_url' => 'http://localhost/api/assets/test/bar/two.txt', + 'alt' => 'Alt text for two', ], ], $augmented->toArray()); } @@ -92,6 +108,13 @@ public function it_shallow_augments_to_a_collection_of_assets() /** @test */ public function it_shallow_augments_to_a_single_asset_when_max_files_is_one() { + AssetContainer::find('test') + ->queryAssets() + ->where('path', 'foo/one.txt') + ->first() + ->set('alt', 'Alt text for one') + ->save(); + $augmented = $this->fieldtype(['max_files' => 1])->shallowAugment(['foo/one.txt']); $this->assertInstanceOf(AugmentedCollection::class, $augmented); @@ -100,6 +123,7 @@ public function it_shallow_augments_to_a_single_asset_when_max_files_is_one() 'url' => '/assets/foo/one.txt', 'permalink' => 'http://localhost/assets/foo/one.txt', 'api_url' => 'http://localhost/api/assets/test/foo/one.txt', + 'alt' => 'Alt text for one', ], $augmented->toArray()); }