6 use BookStack\Actions\ActivityType;
7 use BookStack\Auth\User;
8 use BookStack\Entities\Models\Bookshelf;
9 use Tests\BrowserKitTest;
11 class UserProfileTest extends BrowserKitTest
15 public function setUp(): void
18 $this->user = User::all()->last();
21 public function test_profile_page_shows_name()
24 ->visit('/user/' . $this->user->slug)
25 ->see($this->user->name);
28 public function test_profile_page_shows_recent_entities()
30 $content = $this->createEntityChainBelongingToUser($this->user, $this->user);
33 ->visit('/user/' . $this->user->slug)
34 // Check the recently created page is shown
35 ->see($content['page']->name)
36 // Check the recently created chapter is shown
37 ->see($content['chapter']->name)
38 // Check the recently created book is shown
39 ->see($content['book']->name);
42 public function test_profile_page_shows_created_content_counts()
44 $newUser = $this->getNewBlankUser();
46 $this->asAdmin()->visit('/user/' . $newUser->slug)
48 ->seeInElement('#content-counts', '0 Books')
49 ->seeInElement('#content-counts', '0 Chapters')
50 ->seeInElement('#content-counts', '0 Pages');
52 $this->createEntityChainBelongingToUser($newUser, $newUser);
54 $this->asAdmin()->visit('/user/' . $newUser->slug)
56 ->seeInElement('#content-counts', '1 Book')
57 ->seeInElement('#content-counts', '1 Chapter')
58 ->seeInElement('#content-counts', '1 Page');
61 public function test_profile_page_shows_recent_activity()
63 $newUser = $this->getNewBlankUser();
64 $this->actingAs($newUser);
65 $entities = $this->createEntityChainBelongingToUser($newUser, $newUser);
66 Activity::addForEntity($entities['book'], ActivityType::BOOK_UPDATE);
67 Activity::addForEntity($entities['page'], ActivityType::PAGE_CREATE);
69 $this->asAdmin()->visit('/user/' . $newUser->slug)
70 ->seeInElement('#recent-user-activity', 'updated book')
71 ->seeInElement('#recent-user-activity', 'created page')
72 ->seeInElement('#recent-user-activity', $entities['page']->name);
75 public function test_clicking_user_name_in_activity_leads_to_profile_page()
77 $newUser = $this->getNewBlankUser();
78 $this->actingAs($newUser);
79 $entities = $this->createEntityChainBelongingToUser($newUser, $newUser);
80 Activity::addForEntity($entities['book'], ActivityType::BOOK_UPDATE);
81 Activity::addForEntity($entities['page'], ActivityType::PAGE_CREATE);
83 $this->asAdmin()->visit('/')->clickInElement('#recent-activity', $newUser->name)
84 ->seePageIs('/user/' . $newUser->slug)
85 ->see($newUser->name);
88 public function test_guest_profile_shows_limited_form()
91 ->visit('/settings/users')
93 ->dontSeeElement('#password');
96 public function test_guest_profile_cannot_be_deleted()
98 $guestUser = User::getDefault();
99 $this->asAdmin()->visit('/settings/users/' . $guestUser->id . '/delete')
100 ->see('Delete User')->see('Guest')
102 ->seePageIs('/settings/users/' . $guestUser->id)
103 ->see('cannot delete the guest user');
106 public function test_books_view_is_list()
108 $editor = $this->getEditor();
109 setting()->putUser($editor, 'books_view_type', 'list');
111 $this->actingAs($editor)
113 ->pageNotHasElement('.featured-image-container')
114 ->pageHasElement('.content-wrap .entity-list-item');
117 public function test_books_view_is_grid()
119 $editor = $this->getEditor();
120 setting()->putUser($editor, 'books_view_type', 'grid');
122 $this->actingAs($editor)
124 ->pageHasElement('.featured-image-container');
127 public function test_shelf_view_type_change()
129 $editor = $this->getEditor();
130 $shelf = Bookshelf::query()->first();
131 setting()->putUser($editor, 'bookshelf_view_type', 'list');
133 $this->actingAs($editor)->visit($shelf->getUrl())
134 ->pageNotHasElement('.featured-image-container')
135 ->pageHasElement('.content-wrap .entity-list-item')
138 $req = $this->patch("/settings/users/{$editor->id}/switch-shelf-view", ['view_type' => 'grid']);
139 $req->assertRedirectedTo($shelf->getUrl());
141 $this->actingAs($editor)->visit($shelf->getUrl())
142 ->pageHasElement('.featured-image-container')
143 ->pageNotHasElement('.content-wrap .entity-list-item')