forked from BookStackApp/BookStack
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSettingsTest.php
More file actions
117 lines (93 loc) · 4.51 KB
/
SettingsTest.php
File metadata and controls
117 lines (93 loc) · 4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
namespace Tests\Settings;
use Tests\TestCase;
class SettingsTest extends TestCase
{
public function test_admin_can_see_settings()
{
$this->asAdmin()->get('/settings/features')->assertSee('Settings');
}
public function test_settings_endpoint_redirects_to_settings_view()
{
$resp = $this->asAdmin()->get('/settings');
$resp->assertStatus(302);
// Manually check path to ensure it's generated as the full path
$location = $resp->headers->get('location');
$this->assertEquals(url('/settings/features'), $location);
}
public function test_settings_category_links_work_as_expected()
{
$this->asAdmin();
$categories = [
'features' => 'Features & Security',
'customization' => 'Customization',
'registration' => 'Registration',
];
foreach ($categories as $category => $title) {
$resp = $this->get("/settings/{$category}");
$this->withHtml($resp)->assertElementContains('h1', $title);
$this->withHtml($resp)->assertElementExists("form[action$=\"/settings/{$category}\"]");
}
}
public function test_not_found_setting_category_throws_404()
{
$resp = $this->asAdmin()->get('/settings/biscuits');
$resp->assertStatus(404);
$resp->assertSee('Page Not Found');
}
public function test_updating_and_removing_app_icon()
{
$this->asAdmin();
$galleryFile = $this->files->uploadedImage('my-app-icon.png');
$expectedPath = public_path('uploads/images/system/' . date('Y-m') . '/my-app-icon.png');
$this->assertFalse(setting()->get('app-icon'));
$this->assertFalse(setting()->get('app-icon-180'));
$this->assertFalse(setting()->get('app-icon-128'));
$this->assertFalse(setting()->get('app-icon-64'));
$this->assertFalse(setting()->get('app-icon-32'));
$this->assertEquals(
file_get_contents(public_path('icon.ico')),
file_get_contents(public_path('favicon.ico')),
);
$prevFileCount = count(glob(dirname($expectedPath) . DIRECTORY_SEPARATOR . '*.png'));
$upload = $this->call('POST', '/settings/customization', [], [], ['app_icon' => $galleryFile], []);
$upload->assertRedirect('/settings/customization');
$this->assertTrue(file_exists($expectedPath), 'Uploaded image not found at path: ' . $expectedPath);
$this->assertStringContainsString('my-app-icon', setting()->get('app-icon'));
$this->assertStringContainsString('my-app-icon', setting()->get('app-icon-180'));
$this->assertStringContainsString('my-app-icon', setting()->get('app-icon-128'));
$this->assertStringContainsString('my-app-icon', setting()->get('app-icon-64'));
$this->assertStringContainsString('my-app-icon', setting()->get('app-icon-32'));
$newFileCount = count(glob(dirname($expectedPath) . DIRECTORY_SEPARATOR . '*.png'));
$this->assertEquals(5, $newFileCount - $prevFileCount);
$resp = $this->get('/');
$this->withHtml($resp)->assertElementCount('link[sizes][href*="my-app-icon"]', 6);
$this->assertNotEquals(
file_get_contents(public_path('icon.ico')),
file_get_contents(public_path('favicon.ico')),
);
$reset = $this->post('/settings/customization', ['app_icon_reset' => 'true']);
$reset->assertRedirect('/settings/customization');
$resetFileCount = count(glob(dirname($expectedPath) . DIRECTORY_SEPARATOR . '*.png'));
$this->assertEquals($prevFileCount, $resetFileCount);
$this->assertFalse(setting()->get('app-icon'));
$this->assertFalse(setting()->get('app-icon-180'));
$this->assertFalse(setting()->get('app-icon-128'));
$this->assertFalse(setting()->get('app-icon-64'));
$this->assertFalse(setting()->get('app-icon-32'));
$this->assertEquals(
file_get_contents(public_path('icon.ico')),
file_get_contents(public_path('favicon.ico')),
);
}
public function test_both_light_and_dark_colors_are_used_in_the_base_view()
{
// To allow for dynamic color changes on the front-end where desired.
$this->setSettings(['page-color' => 'superlightblue', 'page-color-dark' => 'superdarkblue']);
$resp = $this->get('/login');
$resp->assertSee(':root {');
$resp->assertSee('superlightblue');
$resp->assertSee(':root.dark-mode {');
$resp->assertSee('superdarkblue');
}
}