Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Query for entry origin within the same collection #11514

Merged
merged 2 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Entries/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ public static function __callStatic($method, $parameters)

protected function getOriginByString($origin)
{
return Facades\Entry::find($origin);
return $this->collection()->queryEntries()->where('id', $origin)->first();
}

protected function getOriginFallbackValues()
Expand Down
24 changes: 19 additions & 5 deletions tests/Data/Entries/EntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use PHPUnit\Framework\Attributes\Test;
use ReflectionClass;
use Statamic\Contracts\Data\Augmentable;
use Statamic\Contracts\Entries\QueryBuilder;
use Statamic\Data\AugmentedCollection;
use Statamic\Entries\AugmentedEntry;
use Statamic\Entries\Collection;
Expand Down Expand Up @@ -1727,7 +1728,12 @@ public function it_gets_file_contents_for_saving_a_localized_entry()
$originEntry = $this->mock(Entry::class);
$originEntry->shouldReceive('id')->andReturn('123');

Facades\Entry::shouldReceive('find')->with('123')->andReturn($originEntry);
$builder = $this->mock(QueryBuilder::class);
$builder->shouldReceive('where')->with('collection', 'test')->andReturnSelf();
$builder->shouldReceive('where')->with('id', 123)->andReturnSelf();
$builder->shouldReceive('first')->andReturn($originEntry);
Facades\Entry::shouldReceive('query')->andReturn($builder);

$originEntry->shouldReceive('values')->andReturn(collect([]));
$originEntry->shouldReceive('blueprint')->andReturn(
$this->mock(Blueprint::class)->shouldReceive('handle')->andReturn('test')->getMock()
Expand Down Expand Up @@ -1805,13 +1811,17 @@ public function the_blueprint_is_not_added_to_the_localized_file_contents()

$originEntry = $this->mock(Entry::class);
$originEntry->shouldReceive('id')->andReturn('123');

Facades\Entry::shouldReceive('find')->with('123')->andReturn($originEntry);
$originEntry->shouldReceive('values')->andReturn(collect([]));
$originEntry->shouldReceive('blueprint')->andReturn(
$this->mock(Blueprint::class)->shouldReceive('handle')->andReturn('another')->getMock()
);

$builder = $this->mock(QueryBuilder::class);
$builder->shouldReceive('where')->with('collection', 'test')->andReturnSelf();
$builder->shouldReceive('where')->with('id', 123)->andReturnSelf();
$builder->shouldReceive('first')->andReturn($originEntry);
Facades\Entry::shouldReceive('query')->andReturn($builder);

$entry = (new Entry)
->collection('test')
->origin('123'); // do not set blueprint.
Expand All @@ -1831,13 +1841,17 @@ public function the_blueprint_is_added_to_the_localized_file_contents_if_explici

$originEntry = $this->mock(Entry::class);
$originEntry->shouldReceive('id')->andReturn('123');

Facades\Entry::shouldReceive('find')->with('123')->andReturn($originEntry);
$originEntry->shouldReceive('values')->andReturn(collect([]));
$originEntry->shouldReceive('blueprint')->andReturn(
$this->mock(Blueprint::class)->shouldReceive('handle')->andReturn('another')->getMock()
);

$builder = $this->mock(QueryBuilder::class);
$builder->shouldReceive('where')->with('collection', 'test')->andReturnSelf();
$builder->shouldReceive('where')->with('id', 123)->andReturnSelf();
$builder->shouldReceive('first')->andReturn($originEntry);
Facades\Entry::shouldReceive('query')->andReturn($builder);

$entry = (new Entry)
->collection('test')
->origin('123')
Expand Down
Loading