1 <?php namespace Test\User;
3 use Tests\BrowserKitTest;
5 class UserProfileTest extends BrowserKitTest
9 public function setUp(): void
12 $this->user = \BookStack\Auth\User::all()->last();
15 public function test_profile_page_shows_name()
18 ->visit('/user/' . $this->user->id)
19 ->see($this->user->name);
22 public function test_profile_page_shows_recent_entities()
24 $content = $this->createEntityChainBelongingToUser($this->user, $this->user);
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);
36 public function test_profile_page_shows_created_content_counts()
38 $newUser = $this->getNewBlankUser();
40 $this->asAdmin()->visit('/user/' . $newUser->id)
42 ->seeInElement('#content-counts', '0 Books')
43 ->seeInElement('#content-counts', '0 Chapters')
44 ->seeInElement('#content-counts', '0 Pages');
46 $this->createEntityChainBelongingToUser($newUser, $newUser);
48 $this->asAdmin()->visit('/user/' . $newUser->id)
50 ->seeInElement('#content-counts', '1 Book')
51 ->seeInElement('#content-counts', '1 Chapter')
52 ->seeInElement('#content-counts', '1 Page');
55 public function test_profile_page_shows_recent_activity()
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);
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);
69 public function test_clicking_user_name_in_activity_leads_to_profile_page()
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);
77 $this->asAdmin()->visit('/')->clickInElement('#recent-activity', $newUser->name)
78 ->seePageIs('/user/' . $newUser->id)
79 ->see($newUser->name);
82 public function test_guest_profile_shows_limited_form()
85 ->visit('/settings/users')
87 ->dontSeeElement('#password');
90 public function test_guest_profile_cannot_be_deleted()
92 $guestUser = \BookStack\Auth\User::getDefault();
93 $this->asAdmin()->visit('/settings/users/' . $guestUser->id . '/delete')
94 ->see('Delete User')->see('Guest')
96 ->seePageIs('/settings/users/' . $guestUser->id)
97 ->see('cannot delete the guest user');
100 public function test_books_view_is_list()
102 $editor = $this->getEditor();
103 setting()->putUser($editor, 'books_view_type', 'list');
105 $this->actingAs($editor)
107 ->pageNotHasElement('.featured-image-container')
108 ->pageHasElement('.content-wrap .entity-list-item');
111 public function test_books_view_is_grid()
113 $editor = $this->getEditor();
114 setting()->putUser($editor, 'books_view_type', 'grid');
116 $this->actingAs($editor)
118 ->pageHasElement('.featured-image-container');