]> BookStack Code Mirror - bookstack/blob - tests/AuditLogTest.php
LDAP: Added TLS support
[bookstack] / tests / AuditLogTest.php
1 <?php namespace Tests;
2
3 use BookStack\Actions\Activity;
4 use BookStack\Actions\ActivityService;
5 use BookStack\Auth\UserRepo;
6 use BookStack\Entities\Managers\TrashCan;
7 use BookStack\Entities\Page;
8 use BookStack\Entities\Repos\PageRepo;
9 use Carbon\Carbon;
10
11 class AuditLogTest extends TestCase
12 {
13
14     public function test_only_accessible_with_right_permissions()
15     {
16         $viewer = $this->getViewer();
17         $this->actingAs($viewer);
18
19         $resp = $this->get('/settings/audit');
20         $this->assertPermissionError($resp);
21
22         $this->giveUserPermissions($viewer, ['settings-manage']);
23         $resp = $this->get('/settings/audit');
24         $this->assertPermissionError($resp);
25
26         $this->giveUserPermissions($viewer, ['users-manage']);
27         $resp = $this->get('/settings/audit');
28         $resp->assertStatus(200);
29         $resp->assertSeeText('Audit Log');
30     }
31
32     public function test_shows_activity()
33     {
34         $admin = $this->getAdmin();
35         $this->actingAs($admin);
36         $page = Page::query()->first();
37         app(ActivityService::class)->add($page, 'page_create', $page->book->id);
38         $activity = Activity::query()->orderBy('id', 'desc')->first();
39
40         $resp = $this->get('settings/audit');
41         $resp->assertSeeText($page->name);
42         $resp->assertSeeText('page_create');
43         $resp->assertSeeText($activity->created_at->toDateTimeString());
44         $resp->assertElementContains('.table-user-item', $admin->name);
45     }
46
47     public function test_shows_name_for_deleted_items()
48     {
49         $this->actingAs( $this->getAdmin());
50         $page = Page::query()->first();
51         $pageName = $page->name;
52         app(ActivityService::class)->add($page, 'page_create', $page->book->id);
53
54         app(PageRepo::class)->destroy($page);
55         app(TrashCan::class)->empty();
56
57         $resp = $this->get('settings/audit');
58         $resp->assertSeeText('Deleted Item');
59         $resp->assertSeeText('Name: ' . $pageName);
60     }
61
62     public function test_shows_activity_for_deleted_users()
63     {
64         $viewer = $this->getViewer();
65         $this->actingAs($viewer);
66         $page = Page::query()->first();
67         app(ActivityService::class)->add($page, 'page_create', $page->book->id);
68
69         $this->actingAs($this->getAdmin());
70         app(UserRepo::class)->destroy($viewer);
71
72         $resp = $this->get('settings/audit');
73         $resp->assertSeeText("[ID: {$viewer->id}] Deleted User");
74     }
75
76     public function test_filters_by_key()
77     {
78         $this->actingAs($this->getAdmin());
79         $page = Page::query()->first();
80         app(ActivityService::class)->add($page, 'page_create', $page->book->id);
81
82         $resp = $this->get('settings/audit');
83         $resp->assertSeeText($page->name);
84
85         $resp = $this->get('settings/audit?event=page_delete');
86         $resp->assertDontSeeText($page->name);
87     }
88
89     public function test_date_filters()
90     {
91         $this->actingAs($this->getAdmin());
92         $page = Page::query()->first();
93         app(ActivityService::class)->add($page, 'page_create', $page->book->id);
94
95         $yesterday = (Carbon::now()->subDay()->format('Y-m-d'));
96         $tomorrow = (Carbon::now()->addDay()->format('Y-m-d'));
97
98         $resp = $this->get('settings/audit?date_from=' . $yesterday);
99         $resp->assertSeeText($page->name);
100
101         $resp = $this->get('settings/audit?date_from=' . $tomorrow);
102         $resp->assertDontSeeText($page->name);
103
104         $resp = $this->get('settings/audit?date_to=' . $tomorrow);
105         $resp->assertSeeText($page->name);
106
107         $resp = $this->get('settings/audit?date_to=' . $yesterday);
108         $resp->assertDontSeeText($page->name);
109     }
110
111 }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.