diff --git a/src/Assets/AssetReferenceUpdater.php b/src/Assets/AssetReferenceUpdater.php index e0e86c1c77f..0ba43d6cd0f 100644 --- a/src/Assets/AssetReferenceUpdater.php +++ b/src/Assets/AssetReferenceUpdater.php @@ -4,7 +4,10 @@ use Statamic\Data\DataReferenceUpdater; use Statamic\Facades\AssetContainer; +use Statamic\Fieldtypes\Sets; use Statamic\Support\Arr; +use Statamic\Support\Str; +use Statamic\Tags\Set; class AssetReferenceUpdater extends DataReferenceUpdater { @@ -333,4 +336,69 @@ private function updateStatamicUrlsInLinkNodes($field, $dottedPrefix) $this->updated = true; } + + /** + * Update fields in blueprints and fieldsets. + * + * @return void + */ + protected function updateBlueprintFields() + { + if ( + ! Sets::previewImageConfig() + || ! Str::startsWith($this->originalValue, Sets::previewImageConfig()['folder'].'/') + ) { + return; + } + + $contents = $this->item->contents(); + + $fieldPaths = $this->findFieldsInBlueprintContents($contents, fieldtypes: ['bard', 'replicator']); + + foreach ($fieldPaths as $fieldPath) { + $fieldContents = Arr::get($contents, $fieldPath); + + if (! isset($fieldContents['sets'])) { + continue; + } + + $fieldContents['sets'] = collect($fieldContents['sets']) + ->map(function ($setGroup) { + if (! isset($setGroup['sets'])) { + return $setGroup; + } + + $setGroup['sets'] = collect($setGroup['sets']) + ->map(function ($set) { + if (isset($set['image'])) { + $fullPath = Sets::previewImageConfig()['folder'].'/'.$set['image']; + + if ($fullPath !== $this->originalValue) { + return $set; + } + + if (Str::startsWith($this->newValue, Sets::previewImageConfig()['folder'].'/')) { + $set['image'] = Str::after($this->newValue, Sets::previewImageConfig()['folder'].'/'); + } else { + unset($set['image']); + } + + $this->updated = true; + } + + return $set; + }) + ->all(); + + return $setGroup; + }) + ->all(); + + Arr::set($contents, $fieldPath, $fieldContents); + } + + if ($this->updated) { + $this->item->setContents($contents); + } + } } diff --git a/src/Data/DataReferenceUpdater.php b/src/Data/DataReferenceUpdater.php index 8c5cc343a5b..5f5c094a271 100644 --- a/src/Data/DataReferenceUpdater.php +++ b/src/Data/DataReferenceUpdater.php @@ -2,7 +2,9 @@ namespace Statamic\Data; +use Statamic\Fields\Blueprint; use Statamic\Fields\Fields; +use Statamic\Fields\Fieldset; use Statamic\Git\Subscriber as GitSubscriber; use Statamic\Support\Arr; @@ -60,7 +62,11 @@ public function updateReferences($originalValue, $newValue) $this->originalValue = $originalValue; $this->newValue = $newValue; - $this->recursivelyUpdateFields($this->getTopLevelFields()); + if ($this->item instanceof Blueprint || $this->item instanceof Fieldset) { + $this->updateBlueprintFields(); + } else { + $this->recursivelyUpdateFields($this->getTopLevelFields()); + } if ($this->updated) { $this->saveItem(); @@ -317,6 +323,39 @@ protected function updateArrayValue($field, $dottedPrefix) $this->updated = true; } + /** + * Update fields in blueprints and fieldsets. + * + * @return void + */ + abstract protected function updateBlueprintFields(); + + /** + * Finds fields of a given type in the contents of a blueprint. + * Returns dot-notation paths to the fields. + * + * @param array $array + * @param array $fieldtypes + * @param string|null $dottedPrefix + * @param array $fieldPaths + * @return array + */ + protected function findFieldsInBlueprintContents($array, $fieldtypes, $dottedPrefix = '', &$fieldPaths = []) + { + foreach ($array as $key => $value) { + if (is_array($value)) { + $fieldPath = $dottedPrefix ? "$dottedPrefix.$key" : $key; + $this->findFieldsInBlueprintContents($value, $fieldtypes, $fieldPath, $fieldPaths); + } + + if (is_string($value) && $key === 'type' && in_array($value, $fieldtypes)) { + $fieldPaths[] = $dottedPrefix; + } + } + + return $fieldPaths; + } + /** * Save item without triggering individual git commits, as these should be batched into one larger commit. */ diff --git a/src/Fields/BlueprintRepository.php b/src/Fields/BlueprintRepository.php index 2db699c46a2..a817e4900aa 100644 --- a/src/Fields/BlueprintRepository.php +++ b/src/Fields/BlueprintRepository.php @@ -6,6 +6,7 @@ use Exception; use Illuminate\Support\Collection; use Statamic\Exceptions\BlueprintNotFoundException; +use Statamic\Facades; use Statamic\Facades\Blink; use Statamic\Facades\File; use Statamic\Facades\Path; @@ -23,6 +24,18 @@ class BlueprintRepository protected $fallbacks = []; protected $additionalNamespaces = []; + public function all() + { + $namespaces = [ + ...Facades\Collection::all()->map(fn ($collection) => "collections/{$collection->handle()}")->all(), + ...Facades\Taxonomy::all()->map(fn ($taxonomy) => "taxonomies/{$taxonomy->handle()}")->all(), + 'navigation', 'assets', 'globals', 'forms', + ...$this->getAdditionalNamespaces()->keys()->all(), + ]; + + return collect($namespaces)->flatMap(fn ($namespace) => $this->in($namespace)->values()); + } + public function setDirectories(string|array $directories) { if (is_string($directories)) { @@ -334,7 +347,7 @@ protected function makeBlueprintFromFile($path, $namespace = null) ->setInitialPath($path) ->setNamespace($namespace ?? null) ->setContents($contents); - }); + })->setParent(null); } protected function getNamespaceAndHandle($blueprint) diff --git a/src/Fields/FieldsetRepository.php b/src/Fields/FieldsetRepository.php index 0d0df4ce586..b9ba607d6ca 100644 --- a/src/Fields/FieldsetRepository.php +++ b/src/Fields/FieldsetRepository.php @@ -172,6 +172,8 @@ public function save(Fieldset $fieldset) "{$directory}/{$handle}.yaml", YAML::dump($fieldset->contents()) ); + + $this->fieldsets[$fieldset->handle()] = $fieldset; } public function delete(Fieldset $fieldset) @@ -181,6 +183,8 @@ public function delete(Fieldset $fieldset) } File::delete($fieldset->path()); + + unset($this->fieldsets[$fieldset->handle()]); } public function reset(Fieldset $fieldset) diff --git a/src/Listeners/UpdateAssetReferences.php b/src/Listeners/UpdateAssetReferences.php index a7deae9e6fb..28ef9ef8075 100644 --- a/src/Listeners/UpdateAssetReferences.php +++ b/src/Listeners/UpdateAssetReferences.php @@ -9,6 +9,8 @@ use Statamic\Events\AssetReplaced; use Statamic\Events\AssetSaved; use Statamic\Events\Subscriber; +use Statamic\Facades\Blueprint; +use Statamic\Facades\Fieldset; class UpdateAssetReferences extends Subscriber implements ShouldQueue { @@ -99,6 +101,26 @@ protected function replaceReferences($asset, $originalPath, $newPath) } }); + Blueprint::all() + ->each(function ($blueprint) use ($originalPath, $newPath, &$hasUpdatedItems) { + $updated = AssetReferenceUpdater::item($blueprint) + ->updateReferences($originalPath, $newPath); + + if ($updated) { + $hasUpdatedItems = true; + } + }); + + Fieldset::all() + ->each(function ($fieldset) use ($originalPath, $newPath, &$hasUpdatedItems) { + $updated = AssetReferenceUpdater::item($fieldset) + ->updateReferences($originalPath, $newPath); + + if ($updated) { + $hasUpdatedItems = true; + } + }); + if ($hasUpdatedItems) { AssetReferencesUpdated::dispatch($asset); } diff --git a/src/Taxonomies/TermReferenceUpdater.php b/src/Taxonomies/TermReferenceUpdater.php index 633ccfaf405..900bca925c1 100644 --- a/src/Taxonomies/TermReferenceUpdater.php +++ b/src/Taxonomies/TermReferenceUpdater.php @@ -112,4 +112,14 @@ protected function newValue() { return $this->scope.$this->newValue; } + + /** + * Update fields in blueprints and fieldsets. + * + * @return void + */ + protected function updateBlueprintFields() + { + // + } } diff --git a/tests/Assets/AssetFolderTest.php b/tests/Assets/AssetFolderTest.php index e9e6093ba93..e2101a4947e 100644 --- a/tests/Assets/AssetFolderTest.php +++ b/tests/Assets/AssetFolderTest.php @@ -1174,6 +1174,7 @@ private function containerWithDisk() Storage::fake('local'); $container = Facades\AssetContainer::make('test')->disk('local'); + Facades\AssetContainer::shouldReceive('find')->with('assets')->andReturn(null); Facades\AssetContainer::shouldReceive('findByHandle')->with('test')->andReturn($container); Facades\AssetContainer::shouldReceive('save')->with($container); diff --git a/tests/Assets/AssetTest.php b/tests/Assets/AssetTest.php index 10b6f055eed..ba64fd3a96d 100644 --- a/tests/Assets/AssetTest.php +++ b/tests/Assets/AssetTest.php @@ -1162,6 +1162,7 @@ public function it_can_be_moved_to_another_folder_with_a_new_filename() $disk->put('old/asset.txt', 'The asset contents'); $container = Facades\AssetContainer::make('test')->disk('local'); Facades\AssetContainer::shouldReceive('save')->with($container); + Facades\AssetContainer::shouldReceive('find')->with('assets')->andReturnNull(); Facades\AssetContainer::shouldReceive('findByHandle')->with('test')->andReturn($container); $asset = $container->makeAsset('old/asset.txt')->data(['foo' => 'bar']); $asset->save(); @@ -1202,6 +1203,7 @@ public function it_lowercases_when_moving_to_another_folder_with_a_new_filename( $disk->put('old/asset.txt', 'The asset contents'); $container = Facades\AssetContainer::make('test')->disk('local'); Facades\AssetContainer::shouldReceive('save')->with($container); + Facades\AssetContainer::shouldReceive('find')->with('assets')->andReturnNull(); Facades\AssetContainer::shouldReceive('findByHandle')->with('test')->andReturn($container); $asset = $container->makeAsset('old/asset.txt'); $asset->save(); @@ -1225,6 +1227,7 @@ public function it_doesnt_lowercase_moved_files_when_configured() $disk->put('old/asset.txt', 'The asset contents'); $container = Facades\AssetContainer::make('test')->disk('local'); Facades\AssetContainer::shouldReceive('save')->with($container); + Facades\AssetContainer::shouldReceive('find')->with('assets')->andReturnNull(); Facades\AssetContainer::shouldReceive('findByHandle')->with('test')->andReturn($container); $asset = $container->makeAsset('old/asset.txt'); $asset->save(); diff --git a/tests/Fields/BlueprintRepositoryTest.php b/tests/Fields/BlueprintRepositoryTest.php index 80571d8c0f7..aa575f19cbb 100644 --- a/tests/Fields/BlueprintRepositoryTest.php +++ b/tests/Fields/BlueprintRepositoryTest.php @@ -10,10 +10,13 @@ use Statamic\Fields\Blueprint; use Statamic\Fields\BlueprintRepository; use Statamic\Support\FileCollection; +use Tests\PreventSavingStacheItemsToDisk; use Tests\TestCase; class BlueprintRepositoryTest extends TestCase { + use PreventSavingStacheItemsToDisk; + private $repo; public function setUp(): void @@ -26,6 +29,42 @@ public function setUp(): void Facades\Blueprint::swap($this->repo); } + #[Test] + public function it_gets_all_blueprints() + { + $this->repo->setDirectories($this->fakeStacheDirectory.'/dev-null/blueprints'); + + $collection = tap(Facades\Collection::make('test'))->save(); + $collection->entryBlueprint()->save(); + + $taxonomy = tap(Facades\Taxonomy::make('test'))->save(); + $taxonomy->termBlueprint()->save(); + + $nav = tap(Facades\Nav::make('test'))->save(); + $nav->blueprint()->save(); + + $assetContainer = tap(Facades\AssetContainer::make('test'))->save(); + $assetContainer->blueprint()->save(); + + Facades\GlobalSet::make('test')->save(); + $this->repo->make('test')->setNamespace('globals')->save(); + + $form = tap(Facades\Form::make('test'))->save(); + $form->blueprint()->save(); + + $all = $this->repo->all(); + + $this->assertEveryItemIsInstanceOf(Blueprint::class, $all); + $this->assertEquals([ + 'collections.test.test', + 'taxonomies.test.test', + 'navigation.test', + 'assets.test', + 'globals.test', + 'forms.test', + ], $all->map->fullyQualifiedHandle()->all()); + } + #[Test] public function it_gets_a_blueprint() { diff --git a/tests/Git/GitEventTest.php b/tests/Git/GitEventTest.php index d4ccce55e5b..3156cbf2e20 100644 --- a/tests/Git/GitEventTest.php +++ b/tests/Git/GitEventTest.php @@ -613,6 +613,7 @@ public function it_batches_asset_references_changes_into_one_commit() ], ]); + BlueprintRepository::shouldReceive('all')->andReturn(collect([$blueprint])); BlueprintRepository::shouldReceive('in')->with('collections/pages')->andReturn(collect([$blueprint])); foreach (range(1, 3) as $i) { diff --git a/tests/Listeners/UpdateAssetReferencesTest.php b/tests/Listeners/UpdateAssetReferencesTest.php index 8c578992922..affa798423c 100644 --- a/tests/Listeners/UpdateAssetReferencesTest.php +++ b/tests/Listeners/UpdateAssetReferencesTest.php @@ -1865,10 +1865,323 @@ public function it_gets_items_from_a_hook() $this->assertContains('additional-2', $items); } + #[Test] + public function it_updates_references_in_set_configs_in_blueprints() + { + $this->assetHoff->path('set-previews/hoff.jpg')->save(); + + config()->set('statamic.assets.set_preview_images', [ + 'container' => 'test_container', + 'folder' => 'set-previews', + ]); + + $collection = tap(Facades\Collection::make('articles'))->save(); + $blueprint = $collection->entryBlueprint(); + + $blueprint->setContents([ + 'fields' => [ + [ + 'handle' => 'content', + 'field' => [ + 'type' => 'bard', + 'sets' => [ + 'set_group' => [ + 'sets' => [ + 'first_set' => [ + 'image' => 'hoff.jpg', + 'fields' => [['handle' => 'foo', 'field' => ['type' => 'text']]], + ], + 'second_set' => [ + 'image' => 'marty.png', + 'fields' => [['handle' => 'bar', 'field' => ['type' => 'text']]], + ], + ], + ], + ], + ], + ], + [ + 'handle' => 'page_builder', + 'field' => [ + 'type' => 'replicator', + 'sets' => [ + 'set_group' => [ + 'sets' => [ + 'first_set' => [ + 'image' => 'hoff.jpg', + 'fields' => [['handle' => 'foo', 'field' => ['type' => 'text']]], + ], + 'second_set' => [ + 'image' => 'marty.png', + 'fields' => [['handle' => 'bar', 'field' => ['type' => 'text']]], + ], + ], + ], + ], + ], + ], + ], + ])->save(); + + $blueprint = Facades\Blueprint::find($blueprint->fullyQualifiedHandle()); + $this->assertEquals('hoff.jpg', Arr::get($blueprint->contents(), 'tabs.main.sections.0.fields.1.field.sets.set_group.sets.first_set.image')); + $this->assertEquals('marty.png', Arr::get($blueprint->contents(), 'tabs.main.sections.0.fields.1.field.sets.set_group.sets.second_set.image')); + $this->assertEquals('hoff.jpg', Arr::get($blueprint->contents(), 'tabs.main.sections.0.fields.2.field.sets.set_group.sets.first_set.image')); + $this->assertEquals('marty.png', Arr::get($blueprint->contents(), 'tabs.main.sections.0.fields.2.field.sets.set_group.sets.second_set.image')); + + $this->assetHoff->path('set-previews/renamed-hoff.jpg')->save(); + + $blueprint = Facades\Blueprint::find($blueprint->fullyQualifiedHandle()); + $this->assertEquals('renamed-hoff.jpg', Arr::get($blueprint->contents(), 'tabs.main.sections.0.fields.1.field.sets.set_group.sets.first_set.image')); // changed + $this->assertEquals('marty.png', Arr::get($blueprint->contents(), 'tabs.main.sections.0.fields.1.field.sets.set_group.sets.second_set.image')); + $this->assertEquals('renamed-hoff.jpg', Arr::get($blueprint->contents(), 'tabs.main.sections.0.fields.2.field.sets.set_group.sets.first_set.image')); // changed + $this->assertEquals('marty.png', Arr::get($blueprint->contents(), 'tabs.main.sections.0.fields.2.field.sets.set_group.sets.second_set.image')); + } + + #[Test] + public function it_updates_references_in_set_configs_in_fieldsets() + { + $this->assetHoff->path('set-previews/hoff.jpg')->save(); + + config()->set('statamic.assets.set_preview_images', [ + 'container' => 'test_container', + 'folder' => 'set-previews', + ]); + + $fieldset = Facades\Fieldset::make('stuff'); + + $fieldset->setContents([ + 'fields' => [ + [ + 'handle' => 'content', + 'field' => [ + 'type' => 'bard', + 'sets' => [ + 'set_group' => [ + 'sets' => [ + 'first_set' => [ + 'image' => 'hoff.jpg', + 'fields' => [['handle' => 'foo', 'field' => ['type' => 'text']]], + ], + 'second_set' => [ + 'image' => 'marty.png', + 'fields' => [['handle' => 'bar', 'field' => ['type' => 'text']]], + ], + ], + ], + ], + ], + ], + [ + 'handle' => 'page_builder', + 'field' => [ + 'type' => 'replicator', + 'sets' => [ + 'set_group' => [ + 'sets' => [ + 'first_set' => [ + 'image' => 'hoff.jpg', + 'fields' => [['handle' => 'foo', 'field' => ['type' => 'text']]], + ], + 'second_set' => [ + 'image' => 'marty.png', + 'fields' => [['handle' => 'bar', 'field' => ['type' => 'text']]], + ], + ], + ], + ], + ], + ], + ], + ])->save(); + + $fieldset = Facades\Fieldset::find('stuff'); + $this->assertEquals('hoff.jpg', Arr::get($fieldset->contents(), 'fields.0.field.sets.set_group.sets.first_set.image')); + $this->assertEquals('marty.png', Arr::get($fieldset->contents(), 'fields.0.field.sets.set_group.sets.second_set.image')); + $this->assertEquals('hoff.jpg', Arr::get($fieldset->contents(), 'fields.1.field.sets.set_group.sets.first_set.image')); + $this->assertEquals('marty.png', Arr::get($fieldset->contents(), 'fields.1.field.sets.set_group.sets.second_set.image')); + + $this->assetHoff->path('set-previews/renamed-hoff.jpg')->save(); + + $fieldset = Facades\Fieldset::find('stuff'); + $this->assertEquals('renamed-hoff.jpg', Arr::get($fieldset->contents(), 'fields.0.field.sets.set_group.sets.first_set.image')); // changed + $this->assertEquals('marty.png', Arr::get($fieldset->contents(), 'fields.0.field.sets.set_group.sets.second_set.image')); + $this->assertEquals('renamed-hoff.jpg', Arr::get($fieldset->contents(), 'fields.1.field.sets.set_group.sets.first_set.image')); // changed + $this->assertEquals('marty.png', Arr::get($fieldset->contents(), 'fields.1.field.sets.set_group.sets.second_set.image')); + } + + #[Test] + public function it_removes_preview_image_from_set_config_when_asset_is_moved_out_of_configured_folder() + { + $this->assetHoff->path('set-previews/hoff.jpg')->save(); + + config()->set('statamic.assets.set_preview_images', [ + 'container' => 'test_container', + 'folder' => 'set-previews', + ]); + + $collection = tap(Facades\Collection::make('articles'))->save(); + $blueprint = $collection->entryBlueprint(); + + $blueprint->setContents([ + 'fields' => [ + [ + 'handle' => 'content', + 'field' => [ + 'type' => 'bard', + 'sets' => [ + 'set_group' => [ + 'sets' => [ + 'first_set' => [ + 'image' => 'hoff.jpg', + 'fields' => [['handle' => 'foo', 'field' => ['type' => 'text']]], + ], + ], + ], + ], + ], + ], + ], + ])->save(); + + $blueprint = Facades\Blueprint::find($blueprint->fullyQualifiedHandle()); + $this->assertEquals('hoff.jpg', Arr::get($blueprint->contents(), 'tabs.main.sections.0.fields.1.field.sets.set_group.sets.first_set.image')); + + $this->assetHoff->path('other-folder/hoff.jpg')->save(); + + $blueprint = Facades\Blueprint::find($blueprint->fullyQualifiedHandle()); + $this->assertFalse(Arr::has($blueprint->contents(), 'tabs.main.sections.0.fields.1.field.sets.set_group.sets.first_set.image')); + } + + #[Test] + public function it_removes_preview_image_from_set_config_when_asset_is_deleted() + { + $this->assetHoff->path('set-previews/hoff.jpg')->save(); + + config()->set('statamic.assets.set_preview_images', [ + 'container' => 'test_container', + 'folder' => 'set-previews', + ]); + + $collection = tap(Facades\Collection::make('articles'))->save(); + $blueprint = $collection->entryBlueprint(); + + $blueprint->setContents([ + 'fields' => [ + [ + 'handle' => 'content', + 'field' => [ + 'type' => 'bard', + 'sets' => [ + 'set_group' => [ + 'sets' => [ + 'first_set' => [ + 'image' => 'hoff.jpg', + 'fields' => [['handle' => 'foo', 'field' => ['type' => 'text']]], + ], + ], + ], + ], + ], + ], + ], + ])->save(); + + $blueprint = Facades\Blueprint::find($blueprint->fullyQualifiedHandle()); + $this->assertEquals('hoff.jpg', Arr::get($blueprint->contents(), 'tabs.main.sections.0.fields.1.field.sets.set_group.sets.first_set.image')); + + $this->assetHoff->delete(); + + $blueprint = Facades\Blueprint::find($blueprint->fullyQualifiedHandle()); + $this->assertFalse(Arr::has($blueprint->contents(), 'tabs.main.sections.0.fields.1.field.sets.set_group.sets.first_set.image')); + } + + #[Test] + public function it_doesnt_update_references_in_set_configs_unless_path_contains_set_preview_images_folder() + { + config()->set('statamic.assets.set_preview_images', [ + 'container' => 'test_container', + 'folder' => 'set-previews', + ]); + + $collection = tap(Facades\Collection::make('articles'))->save(); + $blueprint = $collection->entryBlueprint(); + + $blueprint->setContents([ + 'fields' => [ + [ + 'handle' => 'content', + 'field' => [ + 'type' => 'bard', + 'sets' => [ + 'set_group' => [ + 'sets' => [ + 'first_set' => [ + 'image' => 'hoff.jpg', // asset exists in the base folder + 'fields' => [['handle' => 'foo', 'field' => ['type' => 'text']]], + ], + ], + ], + ], + ], + ], + ], + ])->save(); + + $blueprint = Facades\Blueprint::find($blueprint->fullyQualifiedHandle()); + $this->assertEquals('hoff.jpg', Arr::get($blueprint->contents(), 'tabs.main.sections.0.fields.1.field.sets.set_group.sets.first_set.image')); + + $this->assetHoff->path('renamed-hoff.jpg')->save(); + + $blueprint = Facades\Blueprint::find($blueprint->fullyQualifiedHandle()); + $this->assertEquals('hoff.jpg', Arr::get($blueprint->contents(), 'tabs.main.sections.0.fields.1.field.sets.set_group.sets.first_set.image')); + } + + #[Test] + public function it_doesnt_update_references_in_set_configs_when_set_preview_images_arent_configured() + { + $this->assetHoff->path('set-previews/hoff.jpg')->save(); + + config()->set('statamic.assets.set_preview_images', null); + + $collection = tap(Facades\Collection::make('articles'))->save(); + $blueprint = $collection->entryBlueprint(); + + $blueprint->setContents([ + 'fields' => [ + [ + 'handle' => 'content', + 'field' => [ + 'type' => 'bard', + 'sets' => [ + 'set_group' => [ + 'sets' => [ + 'first_set' => [ + 'image' => 'hoff.jpg', + 'fields' => [['handle' => 'foo', 'field' => ['type' => 'text']]], + ], + ], + ], + ], + ], + ], + ], + ])->save(); + + $blueprint = Facades\Blueprint::find($blueprint->fullyQualifiedHandle()); + $this->assertEquals('hoff.jpg', Arr::get($blueprint->contents(), 'tabs.main.sections.0.fields.1.field.sets.set_group.sets.first_set.image')); + + $this->assetHoff->path('set-previews/renamed-hoff.jpg')->save(); + + $blueprint = Facades\Blueprint::find($blueprint->fullyQualifiedHandle()); + $this->assertEquals('hoff.jpg', Arr::get($blueprint->contents(), 'tabs.main.sections.0.fields.1.field.sets.set_group.sets.first_set.image')); + } + protected function setSingleBlueprint($namespace, $blueprintContents) { $blueprint = tap(Facades\Blueprint::make('single-blueprint')->setContents($blueprintContents))->save(); + Facades\Blueprint::shouldReceive('all')->andReturn(collect([$blueprint])); Facades\Blueprint::shouldReceive('find')->with($namespace)->andReturn($blueprint); } @@ -1876,6 +2189,7 @@ protected function setInBlueprints($namespace, $blueprintContents) { $blueprint = tap(Facades\Blueprint::make('set-in-blueprints')->setContents($blueprintContents))->save(); + Facades\Blueprint::shouldReceive('all')->andReturn(collect([$blueprint])); Facades\Blueprint::shouldReceive('in')->with($namespace)->andReturn(collect([$blueprint])); }