]> BookStack Code Mirror - bookstack/blob - tests/PublicActionTest.php
Update passwords.php
[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\Entities\Book::orderBy('name', 'asc')->first();
10         $this->visit('/books')->seePageIs('/login');
11         $this->visit($book->getUrl())->seePageIs('/login');
12
13         $page = \BookStack\Entities\Page::first();
14         $this->visit($page->getUrl())->seePageIs('/login');
15     }
16
17     public function test_login_link_visible()
18     {
19         $this->setSettings(['app-public' => 'true']);
20         $this->visit('/')->see(url('/login'));
21     }
22
23     public function test_register_link_visible_when_enabled()
24     {
25         $this->setSettings(['app-public' => 'true']);
26
27         $this->visit('/')->see(url('/login'));
28         $this->visit('/')->dontSee(url('/register'));
29
30         $this->setSettings(['app-public' => 'true', 'registration-enabled' => 'true']);
31         $this->visit('/')->see(url('/login'));
32         $this->visit('/')->see(url('/register'));
33     }
34
35     public function test_books_viewable()
36     {
37         $this->setSettings(['app-public' => 'true']);
38         $books = \BookStack\Entities\Book::orderBy('name', 'asc')->take(10)->get();
39         $bookToVisit = $books[1];
40
41         // Check books index page is showing
42         $this->visit('/books')
43             ->seeStatusCode(200)
44             ->see($books[0]->name)
45             // Check individual book page is showing and it's child contents are visible.
46             ->click($bookToVisit->name)
47             ->seePageIs($bookToVisit->getUrl())
48             ->see($bookToVisit->name)
49             ->see($bookToVisit->chapters()->first()->name);
50     }
51
52     public function test_chapters_viewable()
53     {
54         $this->setSettings(['app-public' => 'true']);
55         $chapterToVisit = \BookStack\Entities\Chapter::first();
56         $pageToVisit = $chapterToVisit->pages()->first();
57
58         // Check chapters index page is showing
59         $this->visit($chapterToVisit->getUrl())
60             ->seeStatusCode(200)
61             ->see($chapterToVisit->name)
62             // Check individual chapter page is showing and it's child contents are visible.
63             ->see($pageToVisit->name)
64             ->click($pageToVisit->name)
65             ->see($chapterToVisit->book->name)
66             ->see($chapterToVisit->name)
67             ->seePageIs($pageToVisit->getUrl());
68     }
69
70     public function test_public_page_creation()
71     {
72         $this->setSettings(['app-public' => 'true']);
73         $publicRole = \BookStack\Auth\Role::getSystemRole('public');
74         // Grant all permissions to public
75         $publicRole->permissions()->detach();
76         foreach (\BookStack\Auth\Permissions\RolePermission::all() as $perm) {
77             $publicRole->attachPermission($perm);
78         }
79         $this->app[\BookStack\Auth\Permissions\PermissionService::class]->buildJointPermissionForRole($publicRole);
80
81         $chapter = \BookStack\Entities\Chapter::first();
82         $this->visit($chapter->book->getUrl());
83         $this->visit($chapter->getUrl())
84             ->click('New Page')
85             ->see('New Page')
86             ->seePageIs($chapter->getUrl('/create-page'));
87
88         $this->submitForm('Continue', [
89             'name' => 'My guest page'
90         ])->seePageIs($chapter->book->getUrl('/page/my-guest-page/edit'));
91
92         $user = \BookStack\Auth\User::getDefault();
93         $this->seeInDatabase('pages', [
94             'name' => 'My guest page',
95             'chapter_id' => $chapter->id,
96             'created_by' => $user->id,
97             'updated_by' => $user->id
98         ]);
99     }
100
101     public function test_content_not_listed_on_404_for_public_users()
102     {
103         $page = \BookStack\Entities\Page::first();
104         $this->asAdmin()->visit($page->getUrl());
105         \Auth::logout();
106         view()->share('pageTitle', '');
107         $this->forceVisit('/cats/dogs/hippos');
108         $this->dontSee($page->name);
109     }
110
111     public function test_robots_effected_by_public_status()
112     {
113         $this->visit('/robots.txt');
114         $this->seeText("User-agent: *\nDisallow: /");
115
116         $this->setSettings(['app-public' => 'true']);
117         $this->visit('/robots.txt');
118
119         $this->seeText("User-agent: *\nDisallow:");
120         $this->dontSeeText("Disallow: /");
121     }
122
123     public function test_robots_effected_by_setting()
124     {
125         $this->visit('/robots.txt');
126         $this->seeText("User-agent: *\nDisallow: /");
127
128         config()->set('app.allow_robots', true);
129         $this->visit('/robots.txt');
130
131         $this->seeText("User-agent: *\nDisallow:");
132         $this->dontSeeText("Disallow: /");
133
134         // Check config overrides app-public setting
135         config()->set('app.allow_robots', false);
136         $this->setSettings(['app-public' => 'true']);
137         $this->visit('/robots.txt');
138
139         $this->seeText("User-agent: *\nDisallow: /");
140     }
141
142 }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.