]> BookStack Code Mirror - bookstack/blob - tests/Meta/PwaManifestTest.php
Opensearch: Fixed XML declaration when php short tags enabled
[bookstack] / tests / Meta / PwaManifestTest.php
1 <?php
2
3 namespace Tests\Meta;
4
5 use Tests\TestCase;
6
7 class PwaManifestTest extends TestCase
8 {
9     public function test_manifest_access_and_format()
10     {
11         $this->setSettings(['app-color' => '#00ACED']);
12
13         $resp = $this->get('/manifest.json');
14         $resp->assertOk();
15
16         $resp->assertJson([
17             'name' => setting('app-name'),
18             'launch_handler' => [
19                 'client_mode' => 'focus-existing'
20             ],
21             'theme_color' => '#00ACED',
22         ]);
23     }
24
25     public function test_pwa_meta_tags_in_head()
26     {
27         $html = $this->asViewer()->withHtml($this->get('/'));
28
29         $html->assertElementExists('head link[rel="manifest"][href$="manifest.json"]');
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         $this->beforeApplicationDestroyed(fn() => $this->files->resetAppFavicon());
36
37         $resp = $this->get('/manifest.json');
38         $resp->assertJson([
39             'icons' => [[
40                 "src" => 'http://localhost/icon-32.png',
41                 "sizes" => "32x32",
42                 "type" => "image/png"
43             ]]
44         ]);
45
46         $galleryFile = $this->files->uploadedImage('my-app-icon.png');
47         $this->asAdmin()->call('POST', '/settings/customization', [], [], ['app_icon' => $galleryFile], []);
48
49         $customIconUrl = setting()->get('app-icon-32');
50         $this->assertStringContainsString('my-app-icon', $customIconUrl);
51
52         $resp = $this->get('/manifest.json');
53         $resp->assertJson([
54             'icons' => [[
55                 "src" => $customIconUrl,
56                 "sizes" => "32x32",
57                 "type" => "image/png"
58             ]]
59         ]);
60     }
61
62     public function test_manifest_changes_to_user_preferences()
63     {
64         $lightUser = $this->users->viewer();
65         $darkUser = $this->users->editor();
66         setting()->putUser($darkUser, 'dark-mode-enabled', 'true');
67
68         $resp = $this->actingAs($lightUser)->get('/manifest.json');
69         $resp->assertJson(['background_color' => '#F2F2F2']);
70
71         $resp = $this->actingAs($darkUser)->get('/manifest.json');
72         $resp->assertJson(['background_color' => '#111111']);
73     }
74 }