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