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