Added testing to cover.
Closes #2668
/**
* Get the associated page revisions, ordered by created date.
- * @return mixed
+ * Only provides actual saved page revision instances, Not drafts.
+ */
+ public function revisions(): HasMany
+ {
+ return $this->allRevisions()
+ ->where('type', '=', 'version')
+ ->orderBy('created_at', 'desc')
+ ->orderBy('id', 'desc');
+ }
+
+ /**
+ * Get all revision instances assigned to this page.
+ * Includes all types of revisions.
*/
- public function revisions()
+ public function allRevisions(): HasMany
{
- return $this->hasMany(PageRevision::class)->where('type', '=', 'version')->orderBy('created_at', 'desc')->orderBy('id', 'desc');
+ return $this->hasMany(PageRevision::class);
}
/**
protected function destroyPage(Page $page): int
{
$this->destroyCommonRelations($page);
+ $page->allRevisions()->delete();
// Delete Attached Files
$attachmentService = app(AttachmentService::class);
$redirectReq->assertNotificationContains('Page Successfully Deleted');
}
+ public function test_page_full_delete_removes_all_revisions()
+ {
+ /** @var Page $page */
+ $page = Page::query()->first();
+ $page->revisions()->create([
+ 'html' => '<p>ducks</p>',
+ 'name' => 'my page revision',
+ 'type' => 'draft',
+ ]);
+ $page->revisions()->create([
+ 'html' => '<p>ducks</p>',
+ 'name' => 'my page revision',
+ 'type' => 'revision',
+ ]);
+
+ $this->assertDatabaseHas('page_revisions', [
+ 'page_id' => $page->id,
+ ]);
+
+ $this->asEditor()->delete($page->getUrl());
+ $this->asAdmin()->post('/settings/recycle-bin/empty');
+
+ $this->assertDatabaseMissing('page_revisions', [
+ 'page_id' => $page->id,
+ ]);
+ }
+
public function test_page_copy()
{
$page = Page::first();