]> BookStack Code Mirror - bookstack/blob - tests/CommandsTest.php
Update passwords.php
[bookstack] / tests / CommandsTest.php
1 <?php namespace Tests;
2
3 use BookStack\Auth\Permissions\JointPermission;
4 use BookStack\Entities\Page;
5 use BookStack\Entities\Repos\EntityRepo;
6 use BookStack\Auth\User;
7 use BookStack\Entities\Repos\PageRepo;
8
9 class CommandsTest extends TestCase
10 {
11
12     public function test_clear_views_command()
13     {
14         $this->asEditor();
15         $page = Page::first();
16
17         $this->get($page->getUrl());
18
19         $this->assertDatabaseHas('views', [
20             'user_id' => $this->getEditor()->id,
21             'viewable_id' => $page->id,
22             'views' => 1
23         ]);
24
25         $exitCode = \Artisan::call('bookstack:clear-views');
26         $this->assertTrue($exitCode === 0, 'Command executed successfully');
27
28         $this->assertDatabaseMissing('views', [
29             'user_id' => $this->getEditor()->id
30         ]);
31     }
32
33     public function test_clear_activity_command()
34     {
35         $this->asEditor();
36         $page = Page::first();
37         \Activity::add($page, 'page_update', $page->book->id);
38
39         $this->assertDatabaseHas('activities', [
40             'key' => 'page_update',
41             'entity_id' => $page->id,
42             'user_id' => $this->getEditor()->id
43         ]);
44
45         $exitCode = \Artisan::call('bookstack:clear-activity');
46         $this->assertTrue($exitCode === 0, 'Command executed successfully');
47
48
49         $this->assertDatabaseMissing('activities', [
50             'key' => 'page_update'
51         ]);
52     }
53
54     public function test_clear_revisions_command()
55     {
56         $this->asEditor();
57         $pageRepo = app(PageRepo::class);
58         $page = Page::first();
59         $pageRepo->updatePage($page, $page->book_id, ['name' => 'updated page', 'html' => '<p>new content</p>', 'summary' => 'page revision testing']);
60         $pageRepo->updatePageDraft($page, ['name' => 'updated page', 'html' => '<p>new content in draft</p>', 'summary' => 'page revision testing']);
61
62         $this->assertDatabaseHas('page_revisions', [
63             'page_id' => $page->id,
64             'type' => 'version'
65         ]);
66         $this->assertDatabaseHas('page_revisions', [
67             'page_id' => $page->id,
68             'type' => 'update_draft'
69         ]);
70
71         $exitCode = \Artisan::call('bookstack:clear-revisions');
72         $this->assertTrue($exitCode === 0, 'Command executed successfully');
73
74         $this->assertDatabaseMissing('page_revisions', [
75             'page_id' => $page->id,
76             'type' => 'version'
77         ]);
78         $this->assertDatabaseHas('page_revisions', [
79             'page_id' => $page->id,
80             'type' => 'update_draft'
81         ]);
82
83         $exitCode = \Artisan::call('bookstack:clear-revisions', ['--all' => true]);
84         $this->assertTrue($exitCode === 0, 'Command executed successfully');
85
86         $this->assertDatabaseMissing('page_revisions', [
87             'page_id' => $page->id,
88             'type' => 'update_draft'
89         ]);
90     }
91
92     public function test_regen_permissions_command()
93     {
94         JointPermission::query()->truncate();
95         $page = Page::first();
96
97         $this->assertDatabaseMissing('joint_permissions', ['entity_id' => $page->id]);
98
99         $exitCode = \Artisan::call('bookstack:regenerate-permissions');
100         $this->assertTrue($exitCode === 0, 'Command executed successfully');
101
102         $this->assertDatabaseHas('joint_permissions', ['entity_id' => $page->id]);
103     }
104
105     public function test_add_admin_command()
106     {
107         $exitCode = \Artisan::call('bookstack:create-admin', [
108             '--email' => 'admintest@example.com',
109             '--name' => 'Admin Test',
110             '--password' => 'testing-4',
111         ]);
112         $this->assertTrue($exitCode === 0, 'Command executed successfully');
113
114         $this->assertDatabaseHas('users', [
115             'email' => 'admintest@example.com',
116             'name' => 'Admin Test'
117         ]);
118
119         $this->assertTrue(User::where('email', '=', 'admintest@example.com')->first()->hasSystemRole('admin'), 'User has admin role as expected');
120         $this->assertTrue(\Auth::attempt(['email' => 'admintest@example.com', 'password' => 'testing-4']), 'Password stored as expected');
121     }
122 }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.