Skip to content

Commit

Permalink
[5.x] Query for entry origin within the same collection (#11514)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonvarga authored Feb 28, 2025
1 parent f27f563 commit fbb4589
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
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

0 comments on commit fbb4589

Please sign in to comment.