]> BookStack Code Mirror - bookstack/blob - tests/HomepageTest.php
Update maintenance.php
[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(['app-homepage' => $customPage->id]);
42
43         $homeVisit = $this->get('/');
44         $homeVisit->assertSee($name);
45
46         $pageDeleteReq = $this->delete($customPage->getUrl());
47         $pageDeleteReq->assertStatus(302);
48         $pageDeleteReq->assertRedirect($customPage->getUrl());
49         $pageDeleteReq->assertSessionHas('error');
50         $pageDeleteReq->assertSessionMissing('success');
51
52         $homeVisit = $this->get('/');
53         $homeVisit->assertSee($name);
54         $homeVisit->assertStatus(200);
55     }
56
57     public function test_set_book_homepage()
58     {
59         $editor = $this->getEditor();
60         setting()->putUser($editor, 'books_view_type', 'grid');
61
62         $this->setSettings(['app-homepage-type' => 'books']);
63
64         $this->asEditor();
65         $homeVisit = $this->get('/');
66         $homeVisit->assertSee('Books');
67         $homeVisit->assertSee('grid-card');
68         $homeVisit->assertSee('grid-card-content');
69         $homeVisit->assertSee('grid-card-footer');
70         $homeVisit->assertSee('featured-image-container');
71
72         $this->setSettings(['app-homepage-type' => false]);
73         $this->test_default_homepage_visible();
74     }
75
76     public function test_set_bookshelves_homepage()
77     {
78         $editor = $this->getEditor();
79         setting()->putUser($editor, 'bookshelves_view_type', 'grid');
80
81         $this->setSettings(['app-homepage-type' => 'bookshelves']);
82
83         $this->asEditor();
84         $homeVisit = $this->get('/');
85         $homeVisit->assertSee('Shelves');
86         $homeVisit->assertSee('bookshelf-grid-item grid-card');
87         $homeVisit->assertSee('grid-card-content');
88         $homeVisit->assertSee('grid-card-footer');
89         $homeVisit->assertSee('featured-image-container');
90
91         $this->setSettings(['app-homepage-type' => false]);
92         $this->test_default_homepage_visible();
93     }
94
95     public function test_shelves_list_homepage_adheres_to_book_visibility_permissions()
96     {
97         $editor = $this->getEditor();
98         setting()->putUser($editor, 'bookshelves_view_type', 'list');
99         $this->setSettings(['app-homepage-type' => 'bookshelves']);
100         $this->asEditor();
101
102         $shelf = Bookshelf::query()->first();
103         $book = $shelf->books()->first();
104
105         // Ensure initially visible
106         $homeVisit = $this->get('/');
107         $homeVisit->assertElementContains('.content-wrap', $shelf->name);
108         $homeVisit->assertElementContains('.content-wrap', $book->name);
109
110         // Ensure book no longer visible without view permission
111         $editor->roles()->detach();
112         $this->giveUserPermissions($editor, ['bookshelf-view-all']);
113         $homeVisit = $this->get('/');
114         $homeVisit->assertElementContains('.content-wrap', $shelf->name);
115         $homeVisit->assertElementNotContains('.content-wrap', $book->name);
116
117         // Ensure is visible again with entity-level view permission
118         $this->setEntityRestrictions($book, ['view'], [$editor->roles()->first()]);
119         $homeVisit = $this->get('/');
120         $homeVisit->assertElementContains('.content-wrap', $shelf->name);
121         $homeVisit->assertElementContains('.content-wrap', $book->name);
122     }
123 }