]> BookStack Code Mirror - bookstack/blob - tests/AuthTest.php
343823687a5f8735725667b50b4c44b4e6f6d711
[bookstack] / tests / AuthTest.php
1 <?php
2
3 class AuthTest extends TestCase
4 {
5
6     public function testAuthWorking()
7     {
8         $this->visit('/')
9             ->seePageIs('/login');
10     }
11
12     public function testLogin()
13     {
14         $this->visit('/')
15             ->seePageIs('/login')
16             ->type('[email protected]', '#email')
17             ->type('password', '#password')
18             ->press('Sign In')
19             ->seePageIs('/')
20             ->see('BookStack');
21     }
22
23     public function testPublicViewing()
24     {
25         $settings = app('BookStack\Services\SettingService');
26         $settings->put('app-public', 'true');
27         $this->visit('/')
28             ->seePageIs('/')
29             ->see('Sign In');
30     }
31
32     public function testRegistrationShowing()
33     {
34         // Ensure registration form is showing
35         $this->setSettings(['registration-enabled' => 'true']);
36         $this->visit('/login')
37             ->see('Sign up')
38             ->click('Sign up')
39             ->seePageIs('/register');
40     }
41
42     public function testNormalRegistration()
43     {
44         $this->setSettings(['registration-enabled' => 'true']);
45         $user = factory(\BookStack\User::class)->make();
46
47         $this->visit('/register')
48             ->see('Sign Up')
49             ->type($user->name, '#name')
50             ->type($user->email, '#email')
51             ->type($user->password, '#password')
52             ->press('Create Account')
53             ->seePageIs('/')
54             ->see($user->name);
55     }
56
57     private function setSettings($settingsArray)
58     {
59         $settings = app('BookStack\Services\SettingService');
60         foreach($settingsArray as $key => $value) {
61             $settings->put($key, $value);
62         }
63     }
64
65     public function testLogout()
66     {
67         $this->asAdmin()
68             ->visit('/')
69             ->seePageIs('/')
70             ->visit('/logout')
71             ->visit('/')
72             ->seePageIs('/login');
73     }
74 }