]> BookStack Code Mirror - bookstack/blob - tests/UserProfileTest.php
Fix pt_BR translations
[bookstack] / tests / UserProfileTest.php
1 <?php namespace Tests;
2
3 class UserProfileTest extends BrowserKitTest
4 {
5     protected $user;
6
7     public function setUp()
8     {
9         parent::setUp();
10         $this->user = \BookStack\Auth\User::all()->last();
11     }
12
13     public function test_profile_page_shows_name()
14     {
15         $this->asAdmin()
16             ->visit('/user/' . $this->user->id)
17             ->see($this->user->name);
18     }
19
20     public function test_profile_page_shows_recent_entities()
21     {
22         $content = $this->createEntityChainBelongingToUser($this->user, $this->user);
23
24         $this->asAdmin()
25             ->visit('/user/' . $this->user->id)
26             // Check the recently created page is shown
27             ->see($content['page']->name)
28             // Check the recently created chapter is shown
29             ->see($content['chapter']->name)
30             // Check the recently created book is shown
31             ->see($content['book']->name);
32     }
33
34     public function test_profile_page_shows_created_content_counts()
35     {
36         $newUser = $this->getNewBlankUser();
37
38         $this->asAdmin()->visit('/user/' . $newUser->id)
39             ->see($newUser->name)
40             ->seeInElement('#content-counts', '0 Books')
41             ->seeInElement('#content-counts', '0 Chapters')
42             ->seeInElement('#content-counts', '0 Pages');
43
44         $this->createEntityChainBelongingToUser($newUser, $newUser);
45
46         $this->asAdmin()->visit('/user/' . $newUser->id)
47             ->see($newUser->name)
48             ->seeInElement('#content-counts', '1 Book')
49             ->seeInElement('#content-counts', '1 Chapter')
50             ->seeInElement('#content-counts', '1 Page');
51     }
52
53     public function test_profile_page_shows_recent_activity()
54     {
55         $newUser = $this->getNewBlankUser();
56         $this->actingAs($newUser);
57         $entities = $this->createEntityChainBelongingToUser($newUser, $newUser);
58         \Activity::add($entities['book'], 'book_update', $entities['book']->id);
59         \Activity::add($entities['page'], 'page_create', $entities['book']->id);
60
61         $this->asAdmin()->visit('/user/' . $newUser->id)
62             ->seeInElement('#recent-user-activity', 'updated book')
63             ->seeInElement('#recent-user-activity', 'created page')
64             ->seeInElement('#recent-user-activity', $entities['page']->name);
65     }
66
67     public function test_clicking_user_name_in_activity_leads_to_profile_page()
68     {
69         $newUser = $this->getNewBlankUser();
70         $this->actingAs($newUser);
71         $entities = $this->createEntityChainBelongingToUser($newUser, $newUser);
72         \Activity::add($entities['book'], 'book_update', $entities['book']->id);
73         \Activity::add($entities['page'], 'page_create', $entities['book']->id);
74
75         $this->asAdmin()->visit('/')->clickInElement('#recent-activity', $newUser->name)
76             ->seePageIs('/user/' . $newUser->id)
77             ->see($newUser->name);
78     }
79
80     public function test_guest_profile_shows_limited_form()
81     {
82         $this->asAdmin()
83             ->visit('/settings/users')
84             ->click('Guest')
85             ->dontSeeElement('#password');
86     }
87
88     public function test_guest_profile_cannot_be_deleted()
89     {
90         $guestUser = \BookStack\Auth\User::getDefault();
91         $this->asAdmin()->visit('/settings/users/' . $guestUser->id . '/delete')
92             ->see('Delete User')->see('Guest')
93             ->press('Confirm')
94             ->seePageIs('/settings/users/' . $guestUser->id)
95             ->see('cannot delete the guest user');
96     }
97
98     public function test_books_view_is_list()
99     {
100         $editor = $this->getEditor();
101         setting()->putUser($editor, 'books_view_type', 'list');
102
103         $this->actingAs($editor)
104             ->visit('/books')
105             ->pageNotHasElement('.featured-image-container')
106             ->pageHasElement('.content-wrap .entity-list-item');
107     }
108
109     public function test_books_view_is_grid()
110     {
111         $editor = $this->getEditor();
112         setting()->putUser($editor, 'books_view_type', 'grid');
113
114         $this->actingAs($editor)
115             ->visit('/books')
116             ->pageHasElement('.featured-image-container');
117     }
118
119 }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.