| 
									
										
										
										
											2021-06-26 23:23:15 +08:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Tests\Entity; | 
					
						
							| 
									
										
										
										
											2017-04-21 03:58:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-18 00:56:55 +08:00
										 |  |  | use BookStack\Activity\ActivityType; | 
					
						
							| 
									
										
										
										
											2020-11-22 08:17:45 +08:00
										 |  |  | use BookStack\Entities\Models\Page; | 
					
						
							| 
									
										
										
										
											2017-04-21 03:58:54 +08:00
										 |  |  | use Tests\TestCase; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class PageRevisionTest extends TestCase | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2022-09-03 19:32:21 +08:00
										 |  |  |     public function test_revision_links_visible_to_viewer() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-09-30 00:31:38 +08:00
										 |  |  |         $page = $this->entities->page(); | 
					
						
							| 
									
										
										
										
											2022-09-03 19:32:21 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $html = $this->withHtml($this->asViewer()->get($page->getUrl())); | 
					
						
							|  |  |  |         $html->assertLinkExists($page->getUrl('/revisions')); | 
					
						
							|  |  |  |         $html->assertElementContains('a', 'Revisions'); | 
					
						
							|  |  |  |         $html->assertElementContains('a', 'Revision #1'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-20 20:25:16 +08:00
										 |  |  |     public function test_page_revision_views_viewable() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->asEditor(); | 
					
						
							| 
									
										
										
										
											2022-09-30 05:11:16 +08:00
										 |  |  |         $page = $this->entities->page(); | 
					
						
							| 
									
										
										
										
											2022-09-28 18:10:06 +08:00
										 |  |  |         $this->createRevisions($page, 1, ['name' => 'updated page', 'html' => '<p>new content</p>']); | 
					
						
							| 
									
										
										
										
											2019-04-20 20:25:16 +08:00
										 |  |  |         $pageRevision = $page->revisions->last(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-28 18:10:06 +08:00
										 |  |  |         $resp = $this->get($page->getUrl() . '/revisions/' . $pageRevision->id); | 
					
						
							|  |  |  |         $resp->assertStatus(200); | 
					
						
							|  |  |  |         $resp->assertSee('new content'); | 
					
						
							| 
									
										
										
										
											2019-04-20 20:25:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-28 18:10:06 +08:00
										 |  |  |         $resp = $this->get($page->getUrl() . '/revisions/' . $pageRevision->id . '/changes'); | 
					
						
							|  |  |  |         $resp->assertStatus(200); | 
					
						
							|  |  |  |         $resp->assertSee('new content'); | 
					
						
							| 
									
										
										
										
											2019-04-20 20:25:16 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-23 19:28:14 +08:00
										 |  |  |     public function test_page_revision_preview_shows_content_of_revision() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->asEditor(); | 
					
						
							| 
									
										
										
										
											2022-09-30 05:11:16 +08:00
										 |  |  |         $page = $this->entities->page(); | 
					
						
							| 
									
										
										
										
											2022-09-28 18:10:06 +08:00
										 |  |  |         $this->createRevisions($page, 1, ['name' => 'updated page', 'html' => '<p>new revision content</p>']); | 
					
						
							| 
									
										
										
										
											2020-05-23 19:28:14 +08:00
										 |  |  |         $pageRevision = $page->revisions->last(); | 
					
						
							| 
									
										
										
										
											2022-09-28 18:10:06 +08:00
										 |  |  |         $this->createRevisions($page, 1, ['name' => 'updated page', 'html' => '<p>Updated content</p>']); | 
					
						
							| 
									
										
										
										
											2020-05-23 19:28:14 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $revisionView = $this->get($page->getUrl() . '/revisions/' . $pageRevision->id); | 
					
						
							|  |  |  |         $revisionView->assertStatus(200); | 
					
						
							|  |  |  |         $revisionView->assertSee('new revision content'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-20 20:25:16 +08:00
										 |  |  |     public function test_page_revision_restore_updates_content() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->asEditor(); | 
					
						
							| 
									
										
										
										
											2022-09-30 05:11:16 +08:00
										 |  |  |         $page = $this->entities->page(); | 
					
						
							| 
									
										
										
										
											2022-09-28 18:10:06 +08:00
										 |  |  |         $this->createRevisions($page, 1, ['name' => 'updated page abc123', 'html' => '<p>new contente def456</p>']); | 
					
						
							|  |  |  |         $this->createRevisions($page, 1, ['name' => 'updated page again', 'html' => '<p>new content</p>']); | 
					
						
							| 
									
										
										
										
											2021-06-26 23:23:15 +08:00
										 |  |  |         $page = Page::find($page->id); | 
					
						
							| 
									
										
										
										
											2019-04-20 20:25:16 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $pageView = $this->get($page->getUrl()); | 
					
						
							|  |  |  |         $pageView->assertDontSee('abc123'); | 
					
						
							|  |  |  |         $pageView->assertDontSee('def456'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $revToRestore = $page->revisions()->where('name', 'like', '%abc123')->first(); | 
					
						
							|  |  |  |         $restoreReq = $this->put($page->getUrl() . '/revisions/' . $revToRestore->id . '/restore'); | 
					
						
							| 
									
										
										
										
											2021-06-26 23:23:15 +08:00
										 |  |  |         $page = Page::find($page->id); | 
					
						
							| 
									
										
										
										
											2019-04-20 20:25:16 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $restoreReq->assertStatus(302); | 
					
						
							|  |  |  |         $restoreReq->assertRedirect($page->getUrl()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $pageView = $this->get($page->getUrl()); | 
					
						
							|  |  |  |         $pageView->assertSee('abc123'); | 
					
						
							|  |  |  |         $pageView->assertSee('def456'); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-04-21 03:58:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-06 21:51:05 +08:00
										 |  |  |     public function test_page_revision_restore_with_markdown_retains_markdown_content() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->asEditor(); | 
					
						
							| 
									
										
										
										
											2022-09-30 05:11:16 +08:00
										 |  |  |         $page = $this->entities->page(); | 
					
						
							| 
									
										
										
										
											2022-09-28 18:10:06 +08:00
										 |  |  |         $this->createRevisions($page, 1, ['name' => 'updated page abc123', 'markdown' => '## New Content def456']); | 
					
						
							|  |  |  |         $this->createRevisions($page, 1, ['name' => 'updated page again', 'markdown' => '## New Content Updated']); | 
					
						
							| 
									
										
										
										
											2021-02-06 22:14:38 +08:00
										 |  |  |         $page = Page::find($page->id); | 
					
						
							| 
									
										
										
										
											2021-02-06 21:51:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $pageView = $this->get($page->getUrl()); | 
					
						
							|  |  |  |         $pageView->assertDontSee('abc123'); | 
					
						
							|  |  |  |         $pageView->assertDontSee('def456'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $revToRestore = $page->revisions()->where('name', 'like', '%abc123')->first(); | 
					
						
							|  |  |  |         $restoreReq = $this->put($page->getUrl() . '/revisions/' . $revToRestore->id . '/restore'); | 
					
						
							|  |  |  |         $page = Page::find($page->id); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $restoreReq->assertStatus(302); | 
					
						
							|  |  |  |         $restoreReq->assertRedirect($page->getUrl()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $pageView = $this->get($page->getUrl()); | 
					
						
							|  |  |  |         $this->assertDatabaseHas('pages', [ | 
					
						
							| 
									
										
										
										
											2021-06-26 23:23:15 +08:00
										 |  |  |             'id'       => $page->id, | 
					
						
							| 
									
										
										
										
											2021-02-06 22:14:38 +08:00
										 |  |  |             'markdown' => '## New Content def456', | 
					
						
							| 
									
										
										
										
											2021-02-06 21:51:05 +08:00
										 |  |  |         ]); | 
					
						
							|  |  |  |         $pageView->assertSee('abc123'); | 
					
						
							|  |  |  |         $pageView->assertSee('def456'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-03 00:42:05 +08:00
										 |  |  |     public function test_page_revision_restore_sets_new_revision_with_summary() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->asEditor(); | 
					
						
							| 
									
										
										
										
											2022-09-30 05:11:16 +08:00
										 |  |  |         $page = $this->entities->page(); | 
					
						
							| 
									
										
										
										
											2022-09-28 18:10:06 +08:00
										 |  |  |         $this->createRevisions($page, 1, ['name' => 'updated page abc123', 'html' => '<p>new contente def456</p>', 'summary' => 'My first update']); | 
					
						
							|  |  |  |         $this->createRevisions($page, 1, ['html' => '<p>new content</p>']); | 
					
						
							| 
									
										
										
										
											2021-01-03 00:42:05 +08:00
										 |  |  |         $page->refresh(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $revToRestore = $page->revisions()->where('name', 'like', '%abc123')->first(); | 
					
						
							|  |  |  |         $this->put($page->getUrl() . '/revisions/' . $revToRestore->id . '/restore'); | 
					
						
							|  |  |  |         $page->refresh(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->assertDatabaseHas('page_revisions', [ | 
					
						
							|  |  |  |             'page_id' => $page->id, | 
					
						
							| 
									
										
										
										
											2021-06-26 23:23:15 +08:00
										 |  |  |             'text'    => 'new contente def456', | 
					
						
							|  |  |  |             'type'    => 'version', | 
					
						
							| 
									
										
										
										
											2021-01-03 00:42:05 +08:00
										 |  |  |             'summary' => "Restored from #{$revToRestore->id}; My first update", | 
					
						
							|  |  |  |         ]); | 
					
						
							| 
									
										
										
										
											2022-08-09 20:25:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $detail = "Revision #{$revToRestore->revision_number} (ID: {$revToRestore->id}) for page ID {$revToRestore->page_id}"; | 
					
						
							|  |  |  |         $this->assertActivityExists(ActivityType::REVISION_RESTORE, null, $detail); | 
					
						
							| 
									
										
										
										
											2021-01-03 00:42:05 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-21 03:58:54 +08:00
										 |  |  |     public function test_page_revision_count_increments_on_update() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-09-30 05:11:16 +08:00
										 |  |  |         $page = $this->entities->page(); | 
					
						
							| 
									
										
										
										
											2017-04-21 03:58:54 +08:00
										 |  |  |         $startCount = $page->revision_count; | 
					
						
							| 
									
										
										
										
											2022-09-28 18:10:06 +08:00
										 |  |  |         $this->createRevisions($page, 1); | 
					
						
							| 
									
										
										
										
											2017-04-21 03:58:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-26 23:23:15 +08:00
										 |  |  |         $this->assertTrue(Page::find($page->id)->revision_count === $startCount + 1); | 
					
						
							| 
									
										
										
										
											2017-04-21 03:58:54 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function test_revision_count_shown_in_page_meta() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-09-30 05:11:16 +08:00
										 |  |  |         $page = $this->entities->page(); | 
					
						
							| 
									
										
										
										
											2022-09-28 18:10:06 +08:00
										 |  |  |         $this->createRevisions($page, 2); | 
					
						
							| 
									
										
										
										
											2018-09-16 23:14:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-16 20:18:35 +08:00
										 |  |  |         $pageView = $this->asViewer()->get($page->getUrl()); | 
					
						
							| 
									
										
										
										
											2017-04-21 03:58:54 +08:00
										 |  |  |         $pageView->assertSee('Revision #' . $page->revision_count); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-26 23:23:15 +08:00
										 |  |  |     public function test_revision_deletion() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-09-30 00:31:38 +08:00
										 |  |  |         $page = $this->entities->page(); | 
					
						
							| 
									
										
										
										
											2022-09-28 18:10:06 +08:00
										 |  |  |         $this->createRevisions($page, 2); | 
					
						
							| 
									
										
										
										
											2018-09-15 23:35:51 +08:00
										 |  |  |         $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/')); | 
					
						
							| 
									
										
										
										
											2019-08-26 00:21:25 +08:00
										 |  |  |         $resp->assertRedirect($page->getUrl('/revisions')); | 
					
						
							| 
									
										
										
										
											2018-09-15 23:35:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-27 00:44:34 +08:00
										 |  |  |         $page->refresh(); | 
					
						
							| 
									
										
										
										
											2018-09-15 23:35:51 +08:00
										 |  |  |         $afterRevisionCount = $page->revisions->count(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->assertTrue($beforeRevisionCount === ($afterRevisionCount + 1)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-09 20:25:18 +08:00
										 |  |  |         $detail = "Revision #{$revision->revision_number} (ID: {$revision->id}) for page ID {$revision->page_id}"; | 
					
						
							|  |  |  |         $this->assertActivityExists(ActivityType::REVISION_DELETE, null, $detail); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-15 23:35:51 +08:00
										 |  |  |         // Try to delete the latest revision
 | 
					
						
							| 
									
										
										
										
											2018-09-16 03:42:36 +08:00
										 |  |  |         $beforeRevisionCount = $page->revisions->count(); | 
					
						
							| 
									
										
										
										
											2022-03-27 00:44:34 +08:00
										 |  |  |         $resp = $this->asEditor()->delete($page->currentRevision->getUrl('/delete/')); | 
					
						
							| 
									
										
										
										
											2019-10-05 19:55:01 +08:00
										 |  |  |         $resp->assertRedirect($page->getUrl('/revisions')); | 
					
						
							| 
									
										
										
										
											2018-09-16 03:42:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-27 00:44:34 +08:00
										 |  |  |         $page->refresh(); | 
					
						
							| 
									
										
										
										
											2018-09-16 03:42:36 +08:00
										 |  |  |         $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); | 
					
						
							| 
									
										
										
										
											2022-09-30 05:11:16 +08:00
										 |  |  |         $page = $this->entities->page(); | 
					
						
							| 
									
										
										
										
											2022-09-28 18:10:06 +08:00
										 |  |  |         $this->createRevisions($page, 12); | 
					
						
							| 
									
										
										
										
											2018-09-23 00:30:42 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $revisionCount = $page->revisions()->count(); | 
					
						
							|  |  |  |         $this->assertEquals(2, $revisionCount); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function test_false_revision_limit_allows_many_revisions() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         config()->set('app.revision_limit', false); | 
					
						
							| 
									
										
										
										
											2022-09-30 05:11:16 +08:00
										 |  |  |         $page = $this->entities->page(); | 
					
						
							| 
									
										
										
										
											2022-09-28 18:10:06 +08:00
										 |  |  |         $this->createRevisions($page, 12); | 
					
						
							| 
									
										
										
										
											2018-09-23 00:30:42 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $revisionCount = $page->revisions()->count(); | 
					
						
							|  |  |  |         $this->assertEquals(12, $revisionCount); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-04-23 22:03:58 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     public function test_revision_list_shows_editor_type() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-09-30 05:11:16 +08:00
										 |  |  |         $page = $this->entities->page(); | 
					
						
							| 
									
										
										
										
											2022-09-28 18:10:06 +08:00
										 |  |  |         $this->createRevisions($page, 1, ['html' => 'new page html']); | 
					
						
							| 
									
										
										
										
											2022-04-23 22:03:58 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-28 18:10:06 +08:00
										 |  |  |         $resp = $this->asAdmin()->get($page->refresh()->getUrl('/revisions')); | 
					
						
							| 
									
										
										
										
											2022-11-01 22:53:36 +08:00
										 |  |  |         $this->withHtml($resp)->assertElementContains('.item-list-row > div:nth-child(2)', 'WYSIWYG)'); | 
					
						
							|  |  |  |         $this->withHtml($resp)->assertElementNotContains('.item-list-row > div:nth-child(2)', 'Markdown)'); | 
					
						
							| 
									
										
										
										
											2022-04-23 22:03:58 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-28 18:10:06 +08:00
										 |  |  |         $this->createRevisions($page, 1, ['markdown' => '# Some markdown content']); | 
					
						
							| 
									
										
										
										
											2022-04-23 22:03:58 +08:00
										 |  |  |         $resp = $this->get($page->refresh()->getUrl('/revisions')); | 
					
						
							| 
									
										
										
										
											2022-11-01 22:53:36 +08:00
										 |  |  |         $this->withHtml($resp)->assertElementContains('.item-list-row > div:nth-child(2)', 'Markdown)'); | 
					
						
							| 
									
										
										
										
											2022-04-23 22:03:58 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-09-28 18:10:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-16 19:59:42 +08:00
										 |  |  |     public function test_revision_changes_link_not_shown_for_oldest_revision() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $page = $this->entities->page(); | 
					
						
							|  |  |  |         $this->createRevisions($page, 3, ['html' => 'new page html']); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $resp = $this->asAdmin()->get($page->refresh()->getUrl('/revisions')); | 
					
						
							|  |  |  |         $html = $this->withHtml($resp); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $html->assertElementNotExists('.item-list > .item-list-row:last-child a[href*="/changes"]'); | 
					
						
							|  |  |  |         $html->assertElementContains('.item-list > .item-list-row:nth-child(2)', 'Changes'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-28 18:10:06 +08:00
										 |  |  |     public function test_revision_restore_action_only_visible_with_permission() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-09-30 00:31:38 +08:00
										 |  |  |         $page = $this->entities->page(); | 
					
						
							| 
									
										
										
										
											2022-09-28 18:10:06 +08:00
										 |  |  |         $this->createRevisions($page, 2); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-21 19:08:34 +08:00
										 |  |  |         $viewer = $this->users->viewer(); | 
					
						
							| 
									
										
										
										
											2022-09-28 18:10:06 +08:00
										 |  |  |         $this->actingAs($viewer); | 
					
						
							|  |  |  |         $respHtml = $this->withHtml($this->get($page->getUrl('/revisions'))); | 
					
						
							|  |  |  |         $respHtml->assertElementNotContains('.actions a', 'Restore'); | 
					
						
							|  |  |  |         $respHtml->assertElementNotExists('form[action$="/restore"]'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-21 19:08:34 +08:00
										 |  |  |         $this->permissions->grantUserRolePermissions($viewer, ['page-update-all']); | 
					
						
							| 
									
										
										
										
											2022-09-28 18:10:06 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $respHtml = $this->withHtml($this->get($page->getUrl('/revisions'))); | 
					
						
							|  |  |  |         $respHtml->assertElementContains('.actions a', 'Restore'); | 
					
						
							|  |  |  |         $respHtml->assertElementExists('form[action$="/restore"]'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function test_revision_delete_action_only_visible_with_permission() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-09-30 00:31:38 +08:00
										 |  |  |         $page = $this->entities->page(); | 
					
						
							| 
									
										
										
										
											2022-09-28 18:10:06 +08:00
										 |  |  |         $this->createRevisions($page, 2); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-21 19:08:34 +08:00
										 |  |  |         $viewer = $this->users->viewer(); | 
					
						
							| 
									
										
										
										
											2022-09-28 18:10:06 +08:00
										 |  |  |         $this->actingAs($viewer); | 
					
						
							|  |  |  |         $respHtml = $this->withHtml($this->get($page->getUrl('/revisions'))); | 
					
						
							|  |  |  |         $respHtml->assertElementNotContains('.actions a', 'Delete'); | 
					
						
							|  |  |  |         $respHtml->assertElementNotExists('form[action$="/delete"]'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-21 19:08:34 +08:00
										 |  |  |         $this->permissions->grantUserRolePermissions($viewer, ['page-delete-all']); | 
					
						
							| 
									
										
										
										
											2022-09-28 18:10:06 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $respHtml = $this->withHtml($this->get($page->getUrl('/revisions'))); | 
					
						
							|  |  |  |         $respHtml->assertElementContains('.actions a', 'Delete'); | 
					
						
							|  |  |  |         $respHtml->assertElementExists('form[action$="/delete"]'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     protected function createRevisions(Page $page, int $times, array $attrs = []) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $user = user(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for ($i = 0; $i < $times; $i++) { | 
					
						
							|  |  |  |             $data = ['name' => 'Page update' . $i, 'summary' => 'Update entry' . $i]; | 
					
						
							|  |  |  |             if (!isset($attrs['markdown'])) { | 
					
						
							|  |  |  |                 $data['html'] = '<p>My update page</p>'; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             $this->asAdmin()->put($page->getUrl(), array_merge($data, $attrs)); | 
					
						
							|  |  |  |             $page->refresh(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->actingAs($user); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-06-26 23:23:15 +08:00
										 |  |  | } |