]> BookStack Code Mirror - bookstack/blob - tests/Settings/SettingsTest.php
Extracted test file handling to its own class
[bookstack] / tests / Settings / SettingsTest.php
1 <?php
2
3 namespace Tests\Settings;
4
5 use Tests\TestCase;
6
7 class SettingsTest extends TestCase
8 {
9     public function test_settings_endpoint_redirects_to_settings_view()
10     {
11         $resp = $this->asAdmin()->get('/settings');
12
13         $resp->assertStatus(302);
14
15         // Manually check path to ensure it's generated as the full path
16         $location = $resp->headers->get('location');
17         $this->assertEquals(url('/settings/features'), $location);
18     }
19
20     public function test_settings_category_links_work_as_expected()
21     {
22         $this->asAdmin();
23         $categories = [
24             'features'      => 'Features & Security',
25             'customization' => 'Customization',
26             'registration'  => 'Registration',
27         ];
28
29         foreach ($categories as $category => $title) {
30             $resp = $this->get("/settings/{$category}");
31             $this->withHtml($resp)->assertElementContains('h1', $title);
32             $this->withHtml($resp)->assertElementExists("form[action$=\"/settings/{$category}\"]");
33         }
34     }
35
36     public function test_not_found_setting_category_throws_404()
37     {
38         $resp = $this->asAdmin()->get('/settings/biscuits');
39
40         $resp->assertStatus(404);
41         $resp->assertSee('Page Not Found');
42     }
43
44     public function test_updating_and_removing_app_icon()
45     {
46         $this->asAdmin();
47         $galleryFile = $this->files->uploadedImage('my-app-icon.png');
48         $expectedPath = public_path('uploads/images/system/' . date('Y-m') . '/my-app-icon.png');
49
50         $this->assertFalse(setting()->get('app-icon'));
51         $this->assertFalse(setting()->get('app-icon-180'));
52         $this->assertFalse(setting()->get('app-icon-128'));
53         $this->assertFalse(setting()->get('app-icon-64'));
54         $this->assertFalse(setting()->get('app-icon-32'));
55
56         $prevFileCount = count(glob(dirname($expectedPath) . DIRECTORY_SEPARATOR . '*.png'));
57
58         $upload = $this->call('POST', '/settings/customization', [], [], ['app_icon' => $galleryFile], []);
59         $upload->assertRedirect('/settings/customization');
60
61         $this->assertTrue(file_exists($expectedPath), 'Uploaded image not found at path: ' . $expectedPath);
62         $this->assertStringContainsString('my-app-icon', setting()->get('app-icon'));
63         $this->assertStringContainsString('my-app-icon', setting()->get('app-icon-180'));
64         $this->assertStringContainsString('my-app-icon', setting()->get('app-icon-128'));
65         $this->assertStringContainsString('my-app-icon', setting()->get('app-icon-64'));
66         $this->assertStringContainsString('my-app-icon', setting()->get('app-icon-32'));
67
68         $newFileCount = count(glob(dirname($expectedPath) . DIRECTORY_SEPARATOR . '*.png'));
69         $this->assertEquals(5, $newFileCount - $prevFileCount);
70
71         $resp = $this->get('/');
72         $this->withHtml($resp)->assertElementCount('link[sizes][href*="my-app-icon"]', 6);
73
74         $reset = $this->post('/settings/customization', ['app_icon_reset' => 'true']);
75         $reset->assertRedirect('/settings/customization');
76
77         $resetFileCount = count(glob(dirname($expectedPath) . DIRECTORY_SEPARATOR . '*.png'));
78         $this->assertEquals($prevFileCount, $resetFileCount);
79         $this->assertFalse(setting()->get('app-icon'));
80         $this->assertFalse(setting()->get('app-icon-180'));
81         $this->assertFalse(setting()->get('app-icon-128'));
82         $this->assertFalse(setting()->get('app-icon-64'));
83         $this->assertFalse(setting()->get('app-icon-32'));
84     }
85 }