]> BookStack Code Mirror - bookstack/blob - tests/Entity/PageRevisionTest.php
Adds tests and few fixes.
[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         $this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']);
25         $page = Page::find($page->id);
26
27         $pageView = $this->get($page->getUrl());
28         $pageView->assertSee('Revision #' . $page->revision_count);
29     }
30
31     public function test_revision_deletion() {
32         $page = Page::first();
33         $this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']);
34         $this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']);
35         $page = Page::find($page->id);
36         $beforeRevisionCount = $page->revisions->count();
37
38         // Delete the first revision
39         $revision = $page->revisions->get(0);
40         $resp = $this->asEditor()->delete($revision->getUrl('/delete/'));
41         $resp->assertStatus(200);
42
43         $page = Page::find($page->id);
44         $afterRevisionCount = $page->revisions->count();
45
46         $this->assertTrue($beforeRevisionCount === ($afterRevisionCount + 1));
47
48         // Try to delete the latest revision
49         $revision = $page->revisions->get($page->revisions->count() - 1);
50         $resp = $this->asEditor()->delete($revision->getUrl('/delete/'));
51         $resp->assertSee('Cannot delete the latest revision');
52     }
53 }