3 use BookStack\JointPermission;
5 use BookStack\Repos\EntityRepo;
7 class CommandsTest extends TestCase
10 public function test_clear_views_command()
13 $page = Page::first();
15 $this->get($page->getUrl());
17 $this->assertDatabaseHas('views', [
18 'user_id' => $this->getEditor()->id,
19 'viewable_id' => $page->id,
23 $exitCode = \Artisan::call('bookstack:clear-views');
24 $this->assertTrue($exitCode === 0, 'Command executed successfully');
26 $this->assertDatabaseMissing('views', [
27 'user_id' => $this->getEditor()->id
31 public function test_clear_activity_command()
34 $page = Page::first();
35 \Activity::add($page, 'page_update', $page->book->id);
37 $this->assertDatabaseHas('activities', [
38 'key' => 'page_update',
39 'entity_id' => $page->id,
40 'user_id' => $this->getEditor()->id
43 $exitCode = \Artisan::call('bookstack:clear-activity');
44 $this->assertTrue($exitCode === 0, 'Command executed successfully');
47 $this->assertDatabaseMissing('activities', [
48 'key' => 'page_update'
52 public function test_clear_revisions_command()
55 $entityRepo = $this->app[EntityRepo::class];
56 $page = Page::first();
57 $entityRepo->updatePage($page, $page->book_id, ['name' => 'updated page', 'html' => '<p>new content</p>', 'summary' => 'page revision testing']);
58 $entityRepo->updatePageDraft($page, ['name' => 'updated page', 'html' => '<p>new content in draft</p>', 'summary' => 'page revision testing']);
60 $this->assertDatabaseHas('page_revisions', [
61 'page_id' => $page->id,
64 $this->assertDatabaseHas('page_revisions', [
65 'page_id' => $page->id,
66 'type' => 'update_draft'
69 $exitCode = \Artisan::call('bookstack:clear-revisions');
70 $this->assertTrue($exitCode === 0, 'Command executed successfully');
72 $this->assertDatabaseMissing('page_revisions', [
73 'page_id' => $page->id,
76 $this->assertDatabaseHas('page_revisions', [
77 'page_id' => $page->id,
78 'type' => 'update_draft'
81 $exitCode = \Artisan::call('bookstack:clear-revisions', ['--all' => true]);
82 $this->assertTrue($exitCode === 0, 'Command executed successfully');
84 $this->assertDatabaseMissing('page_revisions', [
85 'page_id' => $page->id,
86 'type' => 'update_draft'
90 public function test_regen_permissions_command()
92 JointPermission::query()->truncate();
93 $page = Page::first();
95 $this->assertDatabaseMissing('joint_permissions', ['entity_id' => $page->id]);
97 $exitCode = \Artisan::call('bookstack:regenerate-permissions');
98 $this->assertTrue($exitCode === 0, 'Command executed successfully');
100 $this->assertDatabaseHas('joint_permissions', ['entity_id' => $page->id]);