diff --git a/src/Http/Controllers/CP/Collections/EntryRevisionsController.php b/src/Http/Controllers/CP/Collections/EntryRevisionsController.php index 57d5554984..c1ef85e20f 100644 --- a/src/Http/Controllers/CP/Collections/EntryRevisionsController.php +++ b/src/Http/Controllers/CP/Collections/EntryRevisionsController.php @@ -15,15 +15,13 @@ public function index(Request $request, $collection, $entry) $revisions = $entry ->revisions() ->reverse() + ->each(fn ($revision) => $revision->attribute('item_url', cp_route('collections.entries.revisions.show', [ + 'collection' => $collection, + 'entry' => $entry->id(), + 'revision' => $revision->id(), + ]))) ->prepend($this->workingCopy($entry)) - ->filter() - ->each(function ($revision) use ($collection, $entry) { - $revision->attribute('item_url', cp_route('collections.entries.revisions.show', [ - 'collection' => $collection, - 'entry' => $entry->id(), - 'revision' => $revision->id(), - ])); - }); + ->filter(); // The first non manually created revision would be considered the "current" // version. It's what corresponds to what's in the content directory. diff --git a/tests/Feature/Entries/EntryRevisionsTest.php b/tests/Feature/Entries/EntryRevisionsTest.php index 1f639e8c72..4f7952481b 100644 --- a/tests/Feature/Entries/EntryRevisionsTest.php +++ b/tests/Feature/Entries/EntryRevisionsTest.php @@ -39,6 +39,63 @@ public function tearDown(): void parent::tearDown(); } + /** @test */ + public function it_gets_revisions() + { + $now = Carbon::parse('2017-02-03'); + Carbon::setTestNow($now); + $this->setTestBlueprint('test', ['foo' => ['type' => 'text']]); + $this->setTestRoles(['test' => ['access cp', 'publish blog entries']]); + $user = User::make()->id('user-1')->assignRole('test')->save(); + + $entry = EntryFactory::id('1') + ->slug('test') + ->collection('blog') + ->published(true) + ->date('2010-12-25') + ->data([ + 'blueprint' => 'test', + 'title' => 'Original title', + 'foo' => 'bar', + ])->create(); + + tap($entry->makeRevision(), function ($copy) { + $copy->message('Revision one'); + $copy->date(Carbon::parse('2017-02-01')); + })->save(); + + tap($entry->makeRevision(), function ($copy) { + $copy->message('Revision two'); + $copy->date(Carbon::parse('2017-02-03')); + })->save(); + + tap($entry->makeWorkingCopy(), function ($copy) { + $attrs = $copy->attributes(); + $attrs['data']['title'] = 'Title modified in working copy'; + $attrs['data']['foo'] = 'baz'; + $copy->attributes($attrs); + })->save(); + + $this + ->actingAs($user) + ->get($entry->revisionsUrl()) + ->assertOk() + ->assertJsonPath('0.revisions.0.action', 'revision') + ->assertJsonPath('0.revisions.0.message', 'Revision one') + ->assertJsonPath('0.revisions.0.attributes.data.title', 'Original title') + ->assertJsonPath('0.revisions.0.attributes.item_url', 'http://localhost/cp/collections/blog/entries/1/revisions/'.Carbon::parse('2017-02-01')->timestamp) + + ->assertJsonPath('1.revisions.0.action', 'revision') + ->assertJsonPath('1.revisions.0.message', false) + ->assertJsonPath('1.revisions.0.attributes.data.title', 'Title modified in working copy') + ->assertJsonPath('1.revisions.0.attributes.item_url', null) + + ->assertJsonPath('1.revisions.1.action', 'revision') + ->assertJsonPath('1.revisions.1.message', 'Revision two') + ->assertJsonPath('1.revisions.1.attributes.data.title', 'Original title') + ->assertJsonPath('1.revisions.1.attributes.item_url', 'http://localhost/cp/collections/blog/entries/1/revisions/'.Carbon::parse('2017-02-03')->timestamp); + } + /** @test */ public function it_publishes_an_entry() {