]> BookStack Code Mirror - bookstack/commitdiff
Checked over recycle bin parent/child flows 2283/head
authorDan Brown <redacted>
Sat, 7 Nov 2020 15:05:13 +0000 (15:05 +0000)
committerDan Brown <redacted>
Sat, 7 Nov 2020 15:05:13 +0000 (15:05 +0000)
app/Entities/Entity.php
tests/RecycleBinTest.php

index 34cdb4b8c49e7722cf7f540c276f16f794889b9e..99922bcebe50047c18563da197091d3b9bca1215 100644 (file)
@@ -298,7 +298,7 @@ class Entity extends Ownable
             return $this->chapter_id ? $this->chapter()->withTrashed()->first() : $this->book()->withTrashed()->first();
         }
         if ($this->isA('chapter')) {
             return $this->chapter_id ? $this->chapter()->withTrashed()->first() : $this->book()->withTrashed()->first();
         }
         if ($this->isA('chapter')) {
-            return $this->book->withTrashed()->first();
+            return $this->book()->withTrashed()->first();
         }
         return null;
     }
         }
         return null;
     }
index ce8b644bd216a200503066adea829c437b00d654..b6a9dc791fa009ad8a398a7a37944a7175315f83 100644 (file)
@@ -199,4 +199,34 @@ class RecycleBinTest extends TestCase
         $this->assertDatabaseMissing('pages', ['id' => $page->id]);
         $this->assertEquals(0, Deletion::query()->count());
     }
         $this->assertDatabaseMissing('pages', ['id' => $page->id]);
         $this->assertEquals(0, Deletion::query()->count());
     }
+
+    public function test_restore_flow_when_restoring_nested_delete_first()
+    {
+        $book = Book::query()->whereHas('pages')->whereHas('chapters')->with(['pages', 'chapters'])->firstOrFail();
+        $chapter = $book->chapters->first();
+        $this->asEditor()->delete($chapter->getUrl());
+        $this->asEditor()->delete($book->getUrl());
+
+        $bookDeletion = $book->deletions()->first();
+        $chapterDeletion = $chapter->deletions()->first();
+
+        $chapterRestoreView = $this->asAdmin()->get("/settings/recycle-bin/{$chapterDeletion->id}/restore");
+        $chapterRestoreView->assertStatus(200);
+        $chapterRestoreView->assertSeeText($chapter->name);
+
+        $chapterRestore = $this->post("/settings/recycle-bin/{$chapterDeletion->id}/restore");
+        $chapterRestore->assertRedirect("/settings/recycle-bin");
+        $this->assertDatabaseMissing("deletions", ["id" => $chapterDeletion->id]);
+
+        $chapter->refresh();
+        $this->assertNotNull($chapter->deleted_at);
+
+        $bookRestoreView = $this->asAdmin()->get("/settings/recycle-bin/{$bookDeletion->id}/restore");
+        $bookRestoreView->assertStatus(200);
+        $bookRestoreView->assertSeeText($chapter->name);
+
+        $this->post("/settings/recycle-bin/{$bookDeletion->id}/restore");
+        $chapter->refresh();
+        $this->assertNull($chapter->deleted_at);
+    }
 }
\ No newline at end of file
 }
\ No newline at end of file