Skip to content

Commit

Permalink
test makeFromRevision
Browse files Browse the repository at this point in the history
  • Loading branch information
edalzell committed Dec 13, 2024
1 parent bc3645a commit d7cb176
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
37 changes: 37 additions & 0 deletions tests/Revisions/RevisableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,23 @@
use Statamic\Entries\Entry;
use Statamic\Facades\Blueprint;
use Statamic\Facades\Collection;
use Statamic\Revisions\RevisionRepository;
use Tests\PreventSavingStacheItemsToDisk;
use Tests\TestCase;

class RevisableTest extends TestCase
{
use PreventSavingStacheItemsToDisk;

private $repo;

protected function setUp(): void
{
parent::setUp();
config(['statamic.revisions.path' => __DIR__.'/__fixtures__']);
$this->repo = (new RevisionRepository);
}

#[Test]
public function it_gets_non_revisable_fields()
{
Expand Down Expand Up @@ -46,4 +56,31 @@ public function it_sets_proper_revision_attributes()

$this->assertEquals(['revisable' => 'see me'], $entry->makeRevision()->attributes()['data']);
}

#[Test]
public function it_can_make_entry_from_revision()
{
$blueprint = Blueprint::makeFromFields([
'revisable' => ['type' => 'text'],
'non_revisable' => ['type' => 'text', 'revisable' => false],
]);

BlueprintRepository::shouldReceive('in')->with('collections/blog')->andReturn(collect(['blog' => $blueprint]));
Collection::make('blog')->save();

$entry = (new Entry)->collection('blog')->id('123');
$entry->set('revisable', 'override me')->set('non_revisable', "don't override me");

$revision = $this->repo->whereKey('123')->first();

$revisedEntry = $entry->makeFromRevision($revision);

$this->assertEquals(
collect([
"revisable" => "overridden",
"non_revisable" => "don't override me",
]),
$entry->makeFromRevision($revision)->data()
);
}
}
8 changes: 7 additions & 1 deletion tests/Revisions/__fixtures__/123/1553546421.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
date: 1553546421
attributes: {}
attributes:
id: 123
slug: the-slug
published: true
date: 1633590000
data:
revisable: 'overridden'

0 comments on commit d7cb176

Please sign in to comment.