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