]> BookStack Code Mirror - bookstack/blob - tests/HomepageTest.php
LDAP: Added TLS support
[bookstack] / tests / HomepageTest.php
1 <?php namespace Tests;
2
3 use BookStack\Entities\Bookshelf;
4
5 class HomepageTest extends TestCase
6 {
7
8     public function test_default_homepage_visible()
9     {
10         $this->asEditor();
11         $homeVisit = $this->get('/');
12         $homeVisit->assertSee('My Recently Viewed');
13         $homeVisit->assertSee('Recently Updated Pages');
14         $homeVisit->assertSee('Recent Activity');
15         $homeVisit->assertSee('home-default');
16     }
17
18     public function test_custom_homepage()
19     {
20         $this->asEditor();
21         $name = 'My custom homepage';
22         $content = str_repeat('This is the body content of my custom homepage.', 20);
23         $customPage = $this->newPage(['name' => $name, 'html' => $content]);
24         $this->setSettings(['app-homepage' => $customPage->id]);
25         $this->setSettings(['app-homepage-type' => 'page']);
26
27         $homeVisit = $this->get('/');
28         $homeVisit->assertSee($name);
29         $homeVisit->assertSee($content);
30         $homeVisit->assertSee('My Recently Viewed');
31         $homeVisit->assertSee('Recently Updated Pages');
32         $homeVisit->assertSee('Recent Activity');
33     }
34
35     public function test_delete_custom_homepage()
36     {
37         $this->asEditor();
38         $name = 'My custom homepage';
39         $content = str_repeat('This is the body content of my custom homepage.', 20);
40         $customPage = $this->newPage(['name' => $name, 'html' => $content]);
41         $this->setSettings([
42             'app-homepage' => $customPage->id,
43             'app-homepage-type' => 'page'
44         ]);
45
46         $homeVisit = $this->get('/');
47         $homeVisit->assertSee($name);
48         $homeVisit->assertElementNotExists('#home-default');
49
50         $pageDeleteReq = $this->delete($customPage->getUrl());
51         $pageDeleteReq->assertStatus(302);
52         $pageDeleteReq->assertRedirect($customPage->getUrl());
53         $pageDeleteReq->assertSessionHas('error');
54         $pageDeleteReq->assertSessionMissing('success');
55
56         $homeVisit = $this->get('/');
57         $homeVisit->assertSee($name);
58         $homeVisit->assertStatus(200);
59     }
60
61     public function test_custom_homepage_can_be_deleted_once_custom_homepage_no_longer_used()
62     {
63         $this->asEditor();
64         $name = 'My custom homepage';
65         $content = str_repeat('This is the body content of my custom homepage.', 20);
66         $customPage = $this->newPage(['name' => $name, 'html' => $content]);
67         $this->setSettings([
68             'app-homepage' => $customPage->id,
69             'app-homepage-type' => 'default'
70         ]);
71
72         $pageDeleteReq = $this->delete($customPage->getUrl());
73         $pageDeleteReq->assertStatus(302);
74         $pageDeleteReq->assertSessionHas('success');
75         $pageDeleteReq->assertSessionMissing('error');
76     }
77
78     public function test_set_book_homepage()
79     {
80         $editor = $this->getEditor();
81         setting()->putUser($editor, 'books_view_type', 'grid');
82
83         $this->setSettings(['app-homepage-type' => 'books']);
84
85         $this->asEditor();
86         $homeVisit = $this->get('/');
87         $homeVisit->assertSee('Books');
88         $homeVisit->assertSee('grid-card');
89         $homeVisit->assertSee('grid-card-content');
90         $homeVisit->assertSee('grid-card-footer');
91         $homeVisit->assertSee('featured-image-container');
92
93         $this->setSettings(['app-homepage-type' => false]);
94         $this->test_default_homepage_visible();
95     }
96
97     public function test_set_bookshelves_homepage()
98     {
99         $editor = $this->getEditor();
100         setting()->putUser($editor, 'bookshelves_view_type', 'grid');
101
102         $this->setSettings(['app-homepage-type' => 'bookshelves']);
103
104         $this->asEditor();
105         $homeVisit = $this->get('/');
106         $homeVisit->assertSee('Shelves');
107         $homeVisit->assertSee('bookshelf-grid-item grid-card');
108         $homeVisit->assertSee('grid-card-content');
109         $homeVisit->assertSee('grid-card-footer');
110         $homeVisit->assertSee('featured-image-container');
111
112         $this->setSettings(['app-homepage-type' => false]);
113         $this->test_default_homepage_visible();
114     }
115
116     public function test_shelves_list_homepage_adheres_to_book_visibility_permissions()
117     {
118         $editor = $this->getEditor();
119         setting()->putUser($editor, 'bookshelves_view_type', 'list');
120         $this->setSettings(['app-homepage-type' => 'bookshelves']);
121         $this->asEditor();
122
123         $shelf = Bookshelf::query()->first();
124         $book = $shelf->books()->first();
125
126         // Ensure initially visible
127         $homeVisit = $this->get('/');
128         $homeVisit->assertElementContains('.content-wrap', $shelf->name);
129         $homeVisit->assertElementContains('.content-wrap', $book->name);
130
131         // Ensure book no longer visible without view permission
132         $editor->roles()->detach();
133         $this->giveUserPermissions($editor, ['bookshelf-view-all']);
134         $homeVisit = $this->get('/');
135         $homeVisit->assertElementContains('.content-wrap', $shelf->name);
136         $homeVisit->assertElementNotContains('.content-wrap', $book->name);
137
138         // Ensure is visible again with entity-level view permission
139         $this->setEntityRestrictions($book, ['view'], [$editor->roles()->first()]);
140         $homeVisit = $this->get('/');
141         $homeVisit->assertElementContains('.content-wrap', $shelf->name);
142         $homeVisit->assertElementContains('.content-wrap', $book->name);
143     }
144 }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.