3 use BookStack\JointPermission;
5 use BookStack\Repos\EntityRepo;
8 class CommandsTest extends TestCase
11 public function test_clear_views_command()
14 $page = Page::first();
16 $this->get($page->getUrl());
18 $this->assertDatabaseHas('views', [
19 'user_id' => $this->getEditor()->id,
20 'viewable_id' => $page->id,
24 $exitCode = \Artisan::call('bookstack:clear-views');
25 $this->assertTrue($exitCode === 0, 'Command executed successfully');
27 $this->assertDatabaseMissing('views', [
28 'user_id' => $this->getEditor()->id
32 public function test_clear_activity_command()
35 $page = Page::first();
36 \Activity::add($page, 'page_update', $page->book->id);
38 $this->assertDatabaseHas('activities', [
39 'key' => 'page_update',
40 'entity_id' => $page->id,
41 'user_id' => $this->getEditor()->id
44 $exitCode = \Artisan::call('bookstack:clear-activity');
45 $this->assertTrue($exitCode === 0, 'Command executed successfully');
48 $this->assertDatabaseMissing('activities', [
49 'key' => 'page_update'
53 public function test_clear_revisions_command()
56 $entityRepo = $this->app[EntityRepo::class];
57 $page = Page::first();
58 $entityRepo->updatePage($page, $page->book_id, ['name' => 'updated page', 'html' => '<p>new content</p>', 'summary' => 'page revision testing']);
59 $entityRepo->updatePageDraft($page, ['name' => 'updated page', 'html' => '<p>new content in draft</p>', 'summary' => 'page revision testing']);
61 $this->assertDatabaseHas('page_revisions', [
62 'page_id' => $page->id,
65 $this->assertDatabaseHas('page_revisions', [
66 'page_id' => $page->id,
67 'type' => 'update_draft'
70 $exitCode = \Artisan::call('bookstack:clear-revisions');
71 $this->assertTrue($exitCode === 0, 'Command executed successfully');
73 $this->assertDatabaseMissing('page_revisions', [
74 'page_id' => $page->id,
77 $this->assertDatabaseHas('page_revisions', [
78 'page_id' => $page->id,
79 'type' => 'update_draft'
82 $exitCode = \Artisan::call('bookstack:clear-revisions', ['--all' => true]);
83 $this->assertTrue($exitCode === 0, 'Command executed successfully');
85 $this->assertDatabaseMissing('page_revisions', [
86 'page_id' => $page->id,
87 'type' => 'update_draft'
91 public function test_regen_permissions_command()
93 JointPermission::query()->truncate();
94 $page = Page::first();
96 $this->assertDatabaseMissing('joint_permissions', ['entity_id' => $page->id]);
98 $exitCode = \Artisan::call('bookstack:regenerate-permissions');
99 $this->assertTrue($exitCode === 0, 'Command executed successfully');
101 $this->assertDatabaseHas('joint_permissions', ['entity_id' => $page->id]);
104 public function test_add_admin_command()
106 $exitCode = \Artisan::call('bookstack:create-admin', [
107 '--email' => 'admintest@example.com',
108 '--name' => 'Admin Test',
109 '--password' => 'testing-4',
111 $this->assertTrue($exitCode === 0, 'Command executed successfully');
113 $this->assertDatabaseHas('users', [
114 'email' => 'admintest@example.com',
115 'name' => 'Admin Test'
118 $this->assertTrue(User::where('email', '=', 'admintest@example.com')->first()->hasSystemRole('admin'), 'User has admin role as expected');
119 $this->assertTrue(\Auth::attempt(['email' => 'admintest@example.com', 'password' => 'testing-4']), 'Password stored as expected');