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_profile_has_search_links_in_created_entity_lists()
90 $user = $this->getEditor();
91 $resp = $this->actingAs($this->getAdmin())->visit('/user/' . $user->slug);
94 '/search?term=%7Bcreated_by%3A' . $user->slug . '%7D+%7Btype%3Apage%7D',
95 '/search?term=%7Bcreated_by%3A' . $user->slug . '%7D+%7Btype%3Achapter%7D',
96 '/search?term=%7Bcreated_by%3A' . $user->slug . '%7D+%7Btype%3Abook%7D',
97 '/search?term=%7Bcreated_by%3A' . $user->slug . '%7D+%7Btype%3Abookshelf%7D',
100 foreach ($expectedLinks as $link) {
101 $resp->seeInElement('[href$="' . $link . '"]', 'View All');
105 public function test_guest_profile_shows_limited_form()
108 ->visit('/settings/users')
110 ->dontSeeElement('#password');
113 public function test_guest_profile_cannot_be_deleted()
115 $guestUser = User::getDefault();
116 $this->asAdmin()->visit('/settings/users/' . $guestUser->id . '/delete')
117 ->see('Delete User')->see('Guest')
119 ->seePageIs('/settings/users/' . $guestUser->id)
120 ->see('cannot delete the guest user');
123 public function test_books_view_is_list()
125 $editor = $this->getEditor();
126 setting()->putUser($editor, 'books_view_type', 'list');
128 $this->actingAs($editor)
130 ->pageNotHasElement('.featured-image-container')
131 ->pageHasElement('.content-wrap .entity-list-item');
134 public function test_books_view_is_grid()
136 $editor = $this->getEditor();
137 setting()->putUser($editor, 'books_view_type', 'grid');
139 $this->actingAs($editor)
141 ->pageHasElement('.featured-image-container');
144 public function test_shelf_view_type_change()
146 $editor = $this->getEditor();
147 $shelf = Bookshelf::query()->first();
148 setting()->putUser($editor, 'bookshelf_view_type', 'list');
150 $this->actingAs($editor)->visit($shelf->getUrl())
151 ->pageNotHasElement('.featured-image-container')
152 ->pageHasElement('.content-wrap .entity-list-item')
155 $req = $this->patch("/settings/users/{$editor->id}/switch-shelf-view", ['view_type' => 'grid']);
156 $req->assertRedirectedTo($shelf->getUrl());
158 $this->actingAs($editor)->visit($shelf->getUrl())
159 ->pageHasElement('.featured-image-container')
160 ->pageNotHasElement('.content-wrap .entity-list-item')