]> BookStack Code Mirror - bookstack/blob - tests/User/UserProfileTest.php
Updated styles to use logical properties/values
[bookstack] / tests / User / UserProfileTest.php
1 <?php namespace Test\User;
2
3 use Tests\BrowserKitTest;
4
5 class UserProfileTest extends BrowserKitTest
6 {
7     protected $user;
8
9     public function setUp(): void
10     {
11         parent::setUp();
12         $this->user = \BookStack\Auth\User::all()->last();
13     }
14
15     public function test_profile_page_shows_name()
16     {
17         $this->asAdmin()
18             ->visit('/user/' . $this->user->id)
19             ->see($this->user->name);
20     }
21
22     public function test_profile_page_shows_recent_entities()
23     {
24         $content = $this->createEntityChainBelongingToUser($this->user, $this->user);
25
26         $this->asAdmin()
27             ->visit('/user/' . $this->user->id)
28             // Check the recently created page is shown
29             ->see($content['page']->name)
30             // Check the recently created chapter is shown
31             ->see($content['chapter']->name)
32             // Check the recently created book is shown
33             ->see($content['book']->name);
34     }
35
36     public function test_profile_page_shows_created_content_counts()
37     {
38         $newUser = $this->getNewBlankUser();
39
40         $this->asAdmin()->visit('/user/' . $newUser->id)
41             ->see($newUser->name)
42             ->seeInElement('#content-counts', '0 Books')
43             ->seeInElement('#content-counts', '0 Chapters')
44             ->seeInElement('#content-counts', '0 Pages');
45
46         $this->createEntityChainBelongingToUser($newUser, $newUser);
47
48         $this->asAdmin()->visit('/user/' . $newUser->id)
49             ->see($newUser->name)
50             ->seeInElement('#content-counts', '1 Book')
51             ->seeInElement('#content-counts', '1 Chapter')
52             ->seeInElement('#content-counts', '1 Page');
53     }
54
55     public function test_profile_page_shows_recent_activity()
56     {
57         $newUser = $this->getNewBlankUser();
58         $this->actingAs($newUser);
59         $entities = $this->createEntityChainBelongingToUser($newUser, $newUser);
60         \Activity::add($entities['book'], 'book_update', $entities['book']->id);
61         \Activity::add($entities['page'], 'page_create', $entities['book']->id);
62
63         $this->asAdmin()->visit('/user/' . $newUser->id)
64             ->seeInElement('#recent-user-activity', 'updated book')
65             ->seeInElement('#recent-user-activity', 'created page')
66             ->seeInElement('#recent-user-activity', $entities['page']->name);
67     }
68
69     public function test_clicking_user_name_in_activity_leads_to_profile_page()
70     {
71         $newUser = $this->getNewBlankUser();
72         $this->actingAs($newUser);
73         $entities = $this->createEntityChainBelongingToUser($newUser, $newUser);
74         \Activity::add($entities['book'], 'book_update', $entities['book']->id);
75         \Activity::add($entities['page'], 'page_create', $entities['book']->id);
76
77         $this->asAdmin()->visit('/')->clickInElement('#recent-activity', $newUser->name)
78             ->seePageIs('/user/' . $newUser->id)
79             ->see($newUser->name);
80     }
81
82     public function test_guest_profile_shows_limited_form()
83     {
84         $this->asAdmin()
85             ->visit('/settings/users')
86             ->click('Guest')
87             ->dontSeeElement('#password');
88     }
89
90     public function test_guest_profile_cannot_be_deleted()
91     {
92         $guestUser = \BookStack\Auth\User::getDefault();
93         $this->asAdmin()->visit('/settings/users/' . $guestUser->id . '/delete')
94             ->see('Delete User')->see('Guest')
95             ->press('Confirm')
96             ->seePageIs('/settings/users/' . $guestUser->id)
97             ->see('cannot delete the guest user');
98     }
99
100     public function test_books_view_is_list()
101     {
102         $editor = $this->getEditor();
103         setting()->putUser($editor, 'books_view_type', 'list');
104
105         $this->actingAs($editor)
106             ->visit('/books')
107             ->pageNotHasElement('.featured-image-container')
108             ->pageHasElement('.content-wrap .entity-list-item');
109     }
110
111     public function test_books_view_is_grid()
112     {
113         $editor = $this->getEditor();
114         setting()->putUser($editor, 'books_view_type', 'grid');
115
116         $this->actingAs($editor)
117             ->visit('/books')
118             ->pageHasElement('.featured-image-container');
119     }
120
121 }