]> BookStack Code Mirror - bookstack/blob - tests/PublicActionTest.php
Fix ajax tag suggestion for subdir installs
[bookstack] / tests / PublicActionTest.php
1 <?php namespace Tests;
2
3 class PublicActionTest extends BrowserKitTest
4 {
5
6     public function test_app_not_public()
7     {
8         $this->setSettings(['app-public' => 'false']);
9         $book = \BookStack\Book::orderBy('name', 'asc')->first();
10         $this->visit('/books')->seePageIs('/login');
11         $this->visit($book->getUrl())->seePageIs('/login');
12
13         $page = \BookStack\Page::first();
14         $this->visit($page->getUrl())->seePageIs('/login');
15     }
16
17     public function test_books_viewable()
18     {
19         $this->setSettings(['app-public' => 'true']);
20         $books = \BookStack\Book::orderBy('name', 'asc')->take(10)->get();
21         $bookToVisit = $books[1];
22
23         // Check books index page is showing
24         $this->visit('/books')
25             ->seeStatusCode(200)
26             ->see($books[0]->name)
27             // Check individual book page is showing and it's child contents are visible.
28             ->click($bookToVisit->name)
29             ->seePageIs($bookToVisit->getUrl())
30             ->see($bookToVisit->name)
31             ->see($bookToVisit->chapters()->first()->name);
32     }
33
34     public function test_chapters_viewable()
35     {
36         $this->setSettings(['app-public' => 'true']);
37         $chapterToVisit = \BookStack\Chapter::first();
38         $pageToVisit = $chapterToVisit->pages()->first();
39
40         // Check chapters index page is showing
41         $this->visit($chapterToVisit->getUrl())
42             ->seeStatusCode(200)
43             ->see($chapterToVisit->name)
44             // Check individual chapter page is showing and it's child contents are visible.
45             ->see($pageToVisit->name)
46             ->click($pageToVisit->name)
47             ->see($chapterToVisit->book->name)
48             ->see($chapterToVisit->name)
49             ->seePageIs($pageToVisit->getUrl());
50     }
51
52     public function test_public_page_creation()
53     {
54         $this->setSettings(['app-public' => 'true']);
55         $publicRole = \BookStack\Role::getSystemRole('public');
56         // Grant all permissions to public
57         $publicRole->permissions()->detach();
58         foreach (\BookStack\RolePermission::all() as $perm) {
59             $publicRole->attachPermission($perm);
60         }
61         $this->app[\BookStack\Services\PermissionService::class]->buildJointPermissionForRole($publicRole);
62
63         $chapter = \BookStack\Chapter::first();
64         $this->visit($chapter->book->getUrl());
65         $this->visit($chapter->getUrl())
66             ->click('New Page')
67             ->see('New Page')
68             ->seePageIs($chapter->getUrl('/create-page'));
69
70         $this->submitForm('Continue', [
71             'name' => 'My guest page'
72         ])->seePageIs($chapter->book->getUrl('/page/my-guest-page/edit'));
73
74         $user = \BookStack\User::getDefault();
75         $this->seeInDatabase('pages', [
76             'name' => 'My guest page',
77             'chapter_id' => $chapter->id,
78             'created_by' => $user->id,
79             'updated_by' => $user->id
80         ]);
81     }
82
83     public function test_content_not_listed_on_404_for_public_users()
84     {
85         $page = \BookStack\Page::first();
86         $this->asAdmin()->visit($page->getUrl());
87         \Auth::logout();
88         view()->share('pageTitle', '');
89         $this->forceVisit('/cats/dogs/hippos');
90         $this->dontSee($page->name);
91     }
92
93 }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.