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