]> BookStack Code Mirror - bookstack/blob - tests/Entity/PageRevisionTest.php
Changes as per code review, and fixes failing test cases.
[bookstack] / tests / Entity / PageRevisionTest.php
1 <?php namespace Entity;
2
3
4 use BookStack\Page;
5 use Tests\TestCase;
6
7 class PageRevisionTest extends TestCase
8 {
9
10     public function test_page_revision_count_increments_on_update()
11     {
12         $page = Page::first();
13         $startCount = $page->revision_count;
14         $resp = $this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']);
15         $resp->assertStatus(302);
16
17         $this->assertTrue(Page::find($page->id)->revision_count === $startCount+1);
18     }
19
20     public function test_revision_count_shown_in_page_meta()
21     {
22         $page = Page::first();
23         $this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']);
24
25         $page = Page::find($page->id);
26         $this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']);
27
28         $page = Page::find($page->id);
29         $pageView = $this->get($page->getUrl());
30         $pageView->assertSee('Revision #' . $page->revision_count);
31     }
32
33     public function test_revision_deletion() {
34         $page = Page::first();
35         $this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']);
36
37         $page = Page::find($page->id);
38         $this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']);
39
40         $page = Page::find($page->id);
41         $beforeRevisionCount = $page->revisions->count();
42
43         // Delete the first revision
44         $revision = $page->revisions->get(1);
45         $resp = $this->asEditor()->delete($revision->getUrl('/delete/'));
46         $resp->assertStatus(200);
47
48         $page = Page::find($page->id);
49         $afterRevisionCount = $page->revisions->count();
50
51         $this->assertTrue($beforeRevisionCount === ($afterRevisionCount + 1));
52
53         // Try to delete the latest revision
54         $beforeRevisionCount = $page->revisions->count();
55         $currentRevision = $page->getCurrentRevision();
56         $resp = $this->asEditor()->delete($currentRevision->getUrl('/delete/'));
57         $resp->assertStatus(400);
58
59         $page = Page::find($page->id);
60         $afterRevisionCount = $page->revisions->count();
61         $this->assertTrue($beforeRevisionCount === $afterRevisionCount);
62     }
63 }