Skip to content

[5.x] Fix broken revision links on unpublished entries #10330

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

Merged
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
14 changes: 6 additions & 8 deletions src/Http/Controllers/CP/Collections/EntryRevisionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
57 changes: 57 additions & 0 deletions tests/Feature/Entries/EntryRevisionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Loading