]> BookStack Code Mirror - bookstack/blob - tests/Settings/SettingsTest.php
Integrated favicon handler with correct files & actions
[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         $this->assertEquals(
56             file_get_contents(public_path('icon.ico')),
57             file_get_contents(public_path('favicon.ico')),
58         );
59
60         $prevFileCount = count(glob(dirname($expectedPath) . DIRECTORY_SEPARATOR . '*.png'));
61
62         $upload = $this->call('POST', '/settings/customization', [], [], ['app_icon' => $galleryFile], []);
63         $upload->assertRedirect('/settings/customization');
64
65         $this->assertTrue(file_exists($expectedPath), 'Uploaded image not found at path: ' . $expectedPath);
66         $this->assertStringContainsString('my-app-icon', setting()->get('app-icon'));
67         $this->assertStringContainsString('my-app-icon', setting()->get('app-icon-180'));
68         $this->assertStringContainsString('my-app-icon', setting()->get('app-icon-128'));
69         $this->assertStringContainsString('my-app-icon', setting()->get('app-icon-64'));
70         $this->assertStringContainsString('my-app-icon', setting()->get('app-icon-32'));
71
72         $newFileCount = count(glob(dirname($expectedPath) . DIRECTORY_SEPARATOR . '*.png'));
73         $this->assertEquals(5, $newFileCount - $prevFileCount);
74
75         $resp = $this->get('/');
76         $this->withHtml($resp)->assertElementCount('link[sizes][href*="my-app-icon"]', 6);
77
78         $this->assertNotEquals(
79             file_get_contents(public_path('icon.ico')),
80             file_get_contents(public_path('favicon.ico')),
81         );
82
83         $reset = $this->post('/settings/customization', ['app_icon_reset' => 'true']);
84         $reset->assertRedirect('/settings/customization');
85
86         $resetFileCount = count(glob(dirname($expectedPath) . DIRECTORY_SEPARATOR . '*.png'));
87         $this->assertEquals($prevFileCount, $resetFileCount);
88         $this->assertFalse(setting()->get('app-icon'));
89         $this->assertFalse(setting()->get('app-icon-180'));
90         $this->assertFalse(setting()->get('app-icon-128'));
91         $this->assertFalse(setting()->get('app-icon-64'));
92         $this->assertFalse(setting()->get('app-icon-32'));
93
94         $this->assertEquals(
95             file_get_contents(public_path('icon.ico')),
96             file_get_contents(public_path('favicon.ico')),
97         );
98     }
99 }