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);