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]);
41 $this->setSettings(['app-homepage' => $customPage->id]);
43 $homeVisit = $this->get('/');
44 $homeVisit->assertSee($name);
46 $pageDeleteReq = $this->delete($customPage->getUrl());
47 $pageDeleteReq->assertStatus(302);
48 $pageDeleteReq->assertRedirect($customPage->getUrl());
49 $pageDeleteReq->assertSessionHas('error');
50 $pageDeleteReq->assertSessionMissing('success');
52 $homeVisit = $this->get('/');
53 $homeVisit->assertSee($name);
54 $homeVisit->assertStatus(200);
57 public function test_set_book_homepage()
59 $editor = $this->getEditor();
60 setting()->putUser($editor, 'books_view_type', 'grid');
62 $this->setSettings(['app-homepage-type' => 'books']);
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');
72 $this->setSettings(['app-homepage-type' => false]);
73 $this->test_default_homepage_visible();
76 public function test_set_bookshelves_homepage()
78 $editor = $this->getEditor();
79 setting()->putUser($editor, 'bookshelves_view_type', 'grid');
81 $this->setSettings(['app-homepage-type' => 'bookshelves']);
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');
91 $this->setSettings(['app-homepage-type' => false]);
92 $this->test_default_homepage_visible();
95 public function test_shelves_list_homepage_adheres_to_book_visibility_permissions()
97 $editor = $this->getEditor();
98 setting()->putUser($editor, 'bookshelves_view_type', 'list');
99 $this->setSettings(['app-homepage-type' => 'bookshelves']);
102 $shelf = Bookshelf::query()->first();
103 $book = $shelf->books()->first();
105 // Ensure initially visible
106 $homeVisit = $this->get('/');
107 $homeVisit->assertElementContains('.content-wrap', $shelf->name);
108 $homeVisit->assertElementContains('.content-wrap', $book->name);
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);
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);