]> BookStack Code Mirror - bookstack/blob - tests/PwaManifestTest.php
PWA Manifest: Tweaks during review of PR #4430
[bookstack] / tests / PwaManifestTest.php
1 <?php
2
3 namespace Tests;
4
5 class PwaManifestTest extends TestCase
6 {
7     public function test_manifest_access_and_format()
8     {
9         $this->setSettings(['app-color' => '#00ACED']);
10
11         $resp = $this->get('/manifest.json');
12         $resp->assertOk();
13
14         $resp->assertJson([
15             'name' => setting('app-name'),
16             'launch_handler' => [
17                 'client_mode' => 'focus-existing'
18             ],
19             'theme_color' => '#00ACED',
20         ]);
21     }
22
23     public function test_pwa_meta_tags_in_head()
24     {
25         $html = $this->asViewer()->withHtml($this->get('/'));
26
27         // crossorigin attribute is required to send cookies with the manifest,
28         // so it can react correctly to user preferences (dark/light mode).
29         $html->assertElementExists('head link[rel="manifest"][href$="manifest.json"][crossorigin="use-credentials"]');
30         $html->assertElementExists('head meta[name="mobile-web-app-capable"][content="yes"]');
31     }
32
33     public function test_manifest_uses_configured_icons_if_existing()
34     {
35         $resp = $this->get('/manifest.json');
36         $resp->assertJson([
37             'icons' => [[
38                 "src" => 'http://localhost/icon-32.png',
39                 "sizes" => "32x32",
40                 "type" => "image/png"
41             ]]
42         ]);
43
44         $galleryFile = $this->files->uploadedImage('my-app-icon.png');
45         $this->asAdmin()->call('POST', '/settings/customization', [], [], ['app_icon' => $galleryFile], []);
46
47         $customIconUrl = setting()->get('app-icon-32');
48         $this->assertStringContainsString('my-app-icon', $customIconUrl);
49
50         $resp = $this->get('/manifest.json');
51         $resp->assertJson([
52             'icons' => [[
53                 "src" => $customIconUrl,
54                 "sizes" => "32x32",
55                 "type" => "image/png"
56             ]]
57         ]);
58     }
59
60     public function test_manifest_changes_to_user_preferences()
61     {
62         $lightUser = $this->users->viewer();
63         $darkUser = $this->users->editor();
64         setting()->putUser($darkUser, 'dark-mode-enabled', 'true');
65
66         $resp = $this->actingAs($lightUser)->get('/manifest.json');
67         $resp->assertJson(['background_color' => '#F2F2F2']);
68
69         $resp = $this->actingAs($darkUser)->get('/manifest.json');
70         $resp->assertJson(['background_color' => '#111111']);
71     }
72 }