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