]> BookStack Code Mirror - bookstack/blob - tests/Settings/SettingsTest.php
Covered app icon setting with testing
[bookstack] / tests / Settings / SettingsTest.php
1 <?php
2
3 namespace Tests\Settings;
4
5 use Illuminate\Support\Facades\Storage;
6 use Tests\TestCase;
7 use Tests\Uploads\UsesImages;
8
9 class SettingsTest extends TestCase
10 {
11     use UsesImages;
12
13     public function test_settings_endpoint_redirects_to_settings_view()
14     {
15         $resp = $this->asAdmin()->get('/settings');
16
17         $resp->assertStatus(302);
18
19         // Manually check path to ensure it's generated as the full path
20         $location = $resp->headers->get('location');
21         $this->assertEquals(url('/settings/features'), $location);
22     }
23
24     public function test_settings_category_links_work_as_expected()
25     {
26         $this->asAdmin();
27         $categories = [
28             'features'      => 'Features & Security',
29             'customization' => 'Customization',
30             'registration'  => 'Registration',
31         ];
32
33         foreach ($categories as $category => $title) {
34             $resp = $this->get("/settings/{$category}");
35             $this->withHtml($resp)->assertElementContains('h1', $title);
36             $this->withHtml($resp)->assertElementExists("form[action$=\"/settings/{$category}\"]");
37         }
38     }
39
40     public function test_not_found_setting_category_throws_404()
41     {
42         $resp = $this->asAdmin()->get('/settings/biscuits');
43
44         $resp->assertStatus(404);
45         $resp->assertSee('Page Not Found');
46     }
47
48     public function test_updating_and_removing_app_icon()
49     {
50         $this->asAdmin();
51         $galleryFile = $this->getTestImage('my-app-icon.png');
52         $expectedPath = public_path('uploads/images/system/' . date('Y-m') . '/my-app-icon.png');
53
54         $this->assertFalse(setting()->get('app-icon'));
55         $this->assertFalse(setting()->get('app-icon-180'));
56         $this->assertFalse(setting()->get('app-icon-128'));
57         $this->assertFalse(setting()->get('app-icon-64'));
58         $this->assertFalse(setting()->get('app-icon-32'));
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         $reset = $this->post('/settings/customization', ['app_icon_reset' => 'true']);
79         $reset->assertRedirect('/settings/customization');
80
81         $resetFileCount = count(glob(dirname($expectedPath) . DIRECTORY_SEPARATOR . '*.png'));
82         $this->assertEquals($prevFileCount, $resetFileCount);
83         $this->assertFalse(setting()->get('app-icon'));
84         $this->assertFalse(setting()->get('app-icon-180'));
85         $this->assertFalse(setting()->get('app-icon-128'));
86         $this->assertFalse(setting()->get('app-icon-64'));
87         $this->assertFalse(setting()->get('app-icon-32'));
88     }
89 }