Skip to content

Commit

Permalink
[4.x] Include alt field in shallowly augmented assets (#10013)
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanmcclean authored May 7, 2024
1 parent 7dabbac commit a7f97df
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Assets/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
24 changes: 24 additions & 0 deletions tests/Fieldtypes/AssetsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -79,19 +93,28 @@ 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());
}

/** @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);
Expand All @@ -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());
}

Expand Down

0 comments on commit a7f97df

Please sign in to comment.