1 <?php namespace Tests\User;
4 use BookStack\Actions\ActivityType;
5 use BookStack\Auth\User;
6 use BookStack\Entities\Models\Bookshelf;
7 use Tests\BrowserKitTest;
9 class UserProfileTest extends BrowserKitTest
13 public function setUp(): void
16 $this->user = User::all()->last();
19 public function test_profile_page_shows_name()
22 ->visit('/user/' . $this->user->slug)
23 ->see($this->user->name);
26 public function test_profile_page_shows_recent_entities()
28 $content = $this->createEntityChainBelongingToUser($this->user, $this->user);
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);
40 public function test_profile_page_shows_created_content_counts()
42 $newUser = $this->getNewBlankUser();
44 $this->asAdmin()->visit('/user/' . $newUser->slug)
46 ->seeInElement('#content-counts', '0 Books')
47 ->seeInElement('#content-counts', '0 Chapters')
48 ->seeInElement('#content-counts', '0 Pages');
50 $this->createEntityChainBelongingToUser($newUser, $newUser);
52 $this->asAdmin()->visit('/user/' . $newUser->slug)
54 ->seeInElement('#content-counts', '1 Book')
55 ->seeInElement('#content-counts', '1 Chapter')
56 ->seeInElement('#content-counts', '1 Page');
59 public function test_profile_page_shows_recent_activity()
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);
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);
73 public function test_clicking_user_name_in_activity_leads_to_profile_page()
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);
81 $this->asAdmin()->visit('/')->clickInElement('#recent-activity', $newUser->name)
82 ->seePageIs('/user/' . $newUser->slug)
83 ->see($newUser->name);
86 public function test_guest_profile_shows_limited_form()
89 ->visit('/settings/users')
91 ->dontSeeElement('#password');
94 public function test_guest_profile_cannot_be_deleted()
96 $guestUser = User::getDefault();
97 $this->asAdmin()->visit('/settings/users/' . $guestUser->id . '/delete')
98 ->see('Delete User')->see('Guest')
100 ->seePageIs('/settings/users/' . $guestUser->id)
101 ->see('cannot delete the guest user');
104 public function test_books_view_is_list()
106 $editor = $this->getEditor();
107 setting()->putUser($editor, 'books_view_type', 'list');
109 $this->actingAs($editor)
111 ->pageNotHasElement('.featured-image-container')
112 ->pageHasElement('.content-wrap .entity-list-item');
115 public function test_books_view_is_grid()
117 $editor = $this->getEditor();
118 setting()->putUser($editor, 'books_view_type', 'grid');
120 $this->actingAs($editor)
122 ->pageHasElement('.featured-image-container');
125 public function test_shelf_view_type_change()
127 $editor = $this->getEditor();
128 $shelf = Bookshelf::query()->first();
129 setting()->putUser($editor, 'bookshelf_view_type', 'list');
131 $this->actingAs($editor)->visit($shelf->getUrl())
132 ->pageNotHasElement('.featured-image-container')
133 ->pageHasElement('.content-wrap .entity-list-item')
136 $req = $this->patch("/settings/users/{$editor->id}/switch-shelf-view", ['view_type' => 'grid']);
137 $req->assertRedirectedTo($shelf->getUrl());
139 $this->actingAs($editor)->visit($shelf->getUrl())
140 ->pageHasElement('.featured-image-container')
141 ->pageNotHasElement('.content-wrap .entity-list-item')