1 <?php namespace Entity;
7 class PageRevisionTest extends TestCase
10 public function test_page_revision_count_increments_on_update()
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);
17 $this->assertTrue(Page::find($page->id)->revision_count === $startCount+1);
20 public function test_revision_count_shown_in_page_meta()
22 $page = Page::first();
23 $this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']);
25 $page = Page::find($page->id);
26 $this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']);
28 $page = Page::find($page->id);
29 $pageView = $this->get($page->getUrl());
30 $pageView->assertSee('Revision #' . $page->revision_count);
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']);
37 $page = Page::find($page->id);
38 $this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']);
40 $page = Page::find($page->id);
41 $beforeRevisionCount = $page->revisions->count();
43 // Delete the first revision
44 $revision = $page->revisions->get(1);
45 $resp = $this->asEditor()->delete($revision->getUrl('/delete/'));
46 $resp->assertStatus(200);
48 $page = Page::find($page->id);
49 $afterRevisionCount = $page->revisions->count();
51 $this->assertTrue($beforeRevisionCount === ($afterRevisionCount + 1));
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);
59 $page = Page::find($page->id);
60 $afterRevisionCount = $page->revisions->count();
61 $this->assertTrue($beforeRevisionCount === $afterRevisionCount);
64 public function test_revision_limit_enforced()
66 config()->set('app.revision_limit', 2);
67 $page = Page::first();
68 $this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']);
69 $page = Page::find($page->id);
70 $this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']);
71 for ($i = 0; $i < 10; $i++) {
72 $this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']);
75 $revisionCount = $page->revisions()->count();
76 $this->assertEquals(2, $revisionCount);
79 public function test_false_revision_limit_allows_many_revisions()
81 config()->set('app.revision_limit', false);
82 $page = Page::first();
83 $this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']);
84 $page = Page::find($page->id);
85 $this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']);
86 for ($i = 0; $i < 10; $i++) {
87 $this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']);
90 $revisionCount = $page->revisions()->count();
91 $this->assertEquals(12, $revisionCount);