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