3 use BookStack\Entities\Bookshelf;
5 class HomepageTest extends TestCase
8 public function test_default_homepage_visible()
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');
18 public function test_custom_homepage()
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']);
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');
35 public function test_delete_custom_homepage()
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]);
42 'app-homepage' => $customPage->id,
43 'app-homepage-type' => 'page'
46 $homeVisit = $this->get('/');
47 $homeVisit->assertSee($name);
48 $homeVisit->assertElementNotExists('#home-default');
50 $pageDeleteReq = $this->delete($customPage->getUrl());
51 $pageDeleteReq->assertStatus(302);
52 $pageDeleteReq->assertRedirect($customPage->getUrl());
53 $pageDeleteReq->assertSessionHas('error');
54 $pageDeleteReq->assertSessionMissing('success');
56 $homeVisit = $this->get('/');
57 $homeVisit->assertSee($name);
58 $homeVisit->assertStatus(200);
61 public function test_custom_homepage_can_be_deleted_once_custom_homepage_no_longer_used()
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]);
68 'app-homepage' => $customPage->id,
69 'app-homepage-type' => 'default'
72 $pageDeleteReq = $this->delete($customPage->getUrl());
73 $pageDeleteReq->assertStatus(302);
74 $pageDeleteReq->assertSessionHas('success');
75 $pageDeleteReq->assertSessionMissing('error');
78 public function test_set_book_homepage()
80 $editor = $this->getEditor();
81 setting()->putUser($editor, 'books_view_type', 'grid');
83 $this->setSettings(['app-homepage-type' => 'books']);
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');
93 $this->setSettings(['app-homepage-type' => false]);
94 $this->test_default_homepage_visible();
97 public function test_set_bookshelves_homepage()
99 $editor = $this->getEditor();
100 setting()->putUser($editor, 'bookshelves_view_type', 'grid');
102 $this->setSettings(['app-homepage-type' => 'bookshelves']);
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');
112 $this->setSettings(['app-homepage-type' => false]);
113 $this->test_default_homepage_visible();
116 public function test_shelves_list_homepage_adheres_to_book_visibility_permissions()
118 $editor = $this->getEditor();
119 setting()->putUser($editor, 'bookshelves_view_type', 'list');
120 $this->setSettings(['app-homepage-type' => 'bookshelves']);
123 $shelf = Bookshelf::query()->first();
124 $book = $shelf->books()->first();
126 // Ensure initially visible
127 $homeVisit = $this->get('/');
128 $homeVisit->assertElementContains('.content-wrap', $shelf->name);
129 $homeVisit->assertElementContains('.content-wrap', $book->name);
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);
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);