1 <?php namespace Test\User;
4 use BookStack\Auth\User;
5 use BookStack\Entities\Bookshelf;
6 use Tests\BrowserKitTest;
8 class UserProfileTest extends BrowserKitTest
12 public function setUp(): void
15 $this->user = User::all()->last();
18 public function test_profile_page_shows_name()
21 ->visit('/user/' . $this->user->id)
22 ->see($this->user->name);
25 public function test_profile_page_shows_recent_entities()
27 $content = $this->createEntityChainBelongingToUser($this->user, $this->user);
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);
39 public function test_profile_page_shows_created_content_counts()
41 $newUser = $this->getNewBlankUser();
43 $this->asAdmin()->visit('/user/' . $newUser->id)
45 ->seeInElement('#content-counts', '0 Books')
46 ->seeInElement('#content-counts', '0 Chapters')
47 ->seeInElement('#content-counts', '0 Pages');
49 $this->createEntityChainBelongingToUser($newUser, $newUser);
51 $this->asAdmin()->visit('/user/' . $newUser->id)
53 ->seeInElement('#content-counts', '1 Book')
54 ->seeInElement('#content-counts', '1 Chapter')
55 ->seeInElement('#content-counts', '1 Page');
58 public function test_profile_page_shows_recent_activity()
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);
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);
72 public function test_clicking_user_name_in_activity_leads_to_profile_page()
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);
80 $this->asAdmin()->visit('/')->clickInElement('#recent-activity', $newUser->name)
81 ->seePageIs('/user/' . $newUser->id)
82 ->see($newUser->name);
85 public function test_guest_profile_shows_limited_form()
88 ->visit('/settings/users')
90 ->dontSeeElement('#password');
93 public function test_guest_profile_cannot_be_deleted()
95 $guestUser = User::getDefault();
96 $this->asAdmin()->visit('/settings/users/' . $guestUser->id . '/delete')
97 ->see('Delete User')->see('Guest')
99 ->seePageIs('/settings/users/' . $guestUser->id)
100 ->see('cannot delete the guest user');
103 public function test_books_view_is_list()
105 $editor = $this->getEditor();
106 setting()->putUser($editor, 'books_view_type', 'list');
108 $this->actingAs($editor)
110 ->pageNotHasElement('.featured-image-container')
111 ->pageHasElement('.content-wrap .entity-list-item');
114 public function test_books_view_is_grid()
116 $editor = $this->getEditor();
117 setting()->putUser($editor, 'books_view_type', 'grid');
119 $this->actingAs($editor)
121 ->pageHasElement('.featured-image-container');
124 public function test_shelf_view_type_change()
126 $editor = $this->getEditor();
127 $shelf = Bookshelf::query()->first();
128 setting()->putUser($editor, 'bookshelf_view_type', 'list');
130 $this->actingAs($editor)->visit($shelf->getUrl())
131 ->pageNotHasElement('.featured-image-container')
132 ->pageHasElement('.content-wrap .entity-list-item')
135 $req = $this->patch("/settings/users/{$editor->id}/switch-shelf-view", ['view_type' => 'grid']);
136 $req->assertRedirectedTo($shelf->getUrl());
138 $this->actingAs($editor)->visit($shelf->getUrl())
139 ->pageHasElement('.featured-image-container')
140 ->pageNotHasElement('.content-wrap .entity-list-item')