| 
									
										
										
										
											2017-04-21 03:58:54 +08:00
										 |  |  | <?php namespace Entity; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-25 19:30:50 +08:00
										 |  |  | use BookStack\Entities\Page; | 
					
						
							| 
									
										
										
										
											2017-04-21 03:58:54 +08:00
										 |  |  | use Tests\TestCase; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class PageRevisionTest extends TestCase | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function test_page_revision_count_increments_on_update() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $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); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->assertTrue(Page::find($page->id)->revision_count === $startCount+1); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function test_revision_count_shown_in_page_meta() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $page = Page::first(); | 
					
						
							|  |  |  |         $this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']); | 
					
						
							| 
									
										
										
										
											2018-09-16 23:14:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-21 03:58:54 +08:00
										 |  |  |         $page = Page::find($page->id); | 
					
						
							| 
									
										
										
										
											2018-09-16 23:14:09 +08:00
										 |  |  |         $this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']); | 
					
						
							| 
									
										
										
										
											2017-04-21 03:58:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-16 23:14:09 +08:00
										 |  |  |         $page = Page::find($page->id); | 
					
						
							| 
									
										
										
										
											2017-04-21 03:58:54 +08:00
										 |  |  |         $pageView = $this->get($page->getUrl()); | 
					
						
							|  |  |  |         $pageView->assertSee('Revision #' . $page->revision_count); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-15 23:35:51 +08:00
										 |  |  |     public function test_revision_deletion() { | 
					
						
							|  |  |  |         $page = Page::first(); | 
					
						
							|  |  |  |         $this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']); | 
					
						
							| 
									
										
										
										
											2018-09-16 23:14:09 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $page = Page::find($page->id); | 
					
						
							| 
									
										
										
										
											2018-09-15 23:35:51 +08:00
										 |  |  |         $this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']); | 
					
						
							| 
									
										
										
										
											2018-09-16 23:14:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-15 23:35:51 +08:00
										 |  |  |         $page = Page::find($page->id); | 
					
						
							|  |  |  |         $beforeRevisionCount = $page->revisions->count(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Delete the first revision
 | 
					
						
							| 
									
										
										
										
											2018-09-16 23:14:09 +08:00
										 |  |  |         $revision = $page->revisions->get(1); | 
					
						
							| 
									
										
										
										
											2018-09-15 23:35:51 +08:00
										 |  |  |         $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
 | 
					
						
							| 
									
										
										
										
											2018-09-16 03:42:36 +08:00
										 |  |  |         $beforeRevisionCount = $page->revisions->count(); | 
					
						
							|  |  |  |         $currentRevision = $page->getCurrentRevision(); | 
					
						
							| 
									
										
										
										
											2018-09-16 23:14:09 +08:00
										 |  |  |         $resp = $this->asEditor()->delete($currentRevision->getUrl('/delete/')); | 
					
						
							|  |  |  |         $resp->assertStatus(400); | 
					
						
							| 
									
										
										
										
											2018-09-16 03:42:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $page = Page::find($page->id); | 
					
						
							|  |  |  |         $afterRevisionCount = $page->revisions->count(); | 
					
						
							|  |  |  |         $this->assertTrue($beforeRevisionCount === $afterRevisionCount); | 
					
						
							| 
									
										
										
										
											2018-09-15 23:35:51 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-09-23 00:30:42 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     public function test_revision_limit_enforced() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         config()->set('app.revision_limit', 2); | 
					
						
							|  |  |  |         $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']); | 
					
						
							|  |  |  |         for ($i = 0; $i < 10; $i++) { | 
					
						
							|  |  |  |             $this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $revisionCount = $page->revisions()->count(); | 
					
						
							|  |  |  |         $this->assertEquals(2, $revisionCount); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function test_false_revision_limit_allows_many_revisions() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         config()->set('app.revision_limit', false); | 
					
						
							|  |  |  |         $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']); | 
					
						
							|  |  |  |         for ($i = 0; $i < 10; $i++) { | 
					
						
							|  |  |  |             $this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $revisionCount = $page->revisions()->count(); | 
					
						
							|  |  |  |         $this->assertEquals(12, $revisionCount); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-04-21 03:58:54 +08:00
										 |  |  | } |