]> BookStack Code Mirror - bookstack/blobdiff - tests/Entity/PageRevisionTest.php
Changes as per code review, and fixes failing test cases.
[bookstack] / tests / Entity / PageRevisionTest.php
index beebc7adf4e9682667fa9044a73e3579f4ba70e5..08b379107f3bf049c6b26f8efc3a48662ba9c755 100644 (file)
@@ -11,7 +11,6 @@ class PageRevisionTest extends TestCase
     {
         $page = Page::first();
         $startCount = $page->revision_count;
-
         $resp = $this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']);
         $resp->assertStatus(302);
 
@@ -22,11 +21,43 @@ class PageRevisionTest extends TestCase
     {
         $page = Page::first();
         $this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']);
-        $this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']);
+
         $page = Page::find($page->id);
+        $this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']);
 
+        $page = Page::find($page->id);
         $pageView = $this->get($page->getUrl());
         $pageView->assertSee('Revision #' . $page->revision_count);
     }
 
+    public function test_revision_deletion() {
+        $page = Page::first();
+        $this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']);
+
+        $page = Page::find($page->id);
+        $this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']);
+
+        $page = Page::find($page->id);
+        $beforeRevisionCount = $page->revisions->count();
+
+        // Delete the first revision
+        $revision = $page->revisions->get(1);
+        $resp = $this->asEditor()->delete($revision->getUrl('/delete/'));
+        $resp->assertStatus(200);
+
+        $page = Page::find($page->id);
+        $afterRevisionCount = $page->revisions->count();
+
+        $this->assertTrue($beforeRevisionCount === ($afterRevisionCount + 1));
+
+        // Try to delete the latest revision
+        $beforeRevisionCount = $page->revisions->count();
+        $currentRevision = $page->getCurrentRevision();
+        $resp = $this->asEditor()->delete($currentRevision->getUrl('/delete/'));
+        $resp->assertStatus(400);
+
+        $page = Page::find($page->id);
+        $afterRevisionCount = $page->revisions->count();
+        $this->assertTrue($beforeRevisionCount === $afterRevisionCount);
+    }
 }
\ No newline at end of file