forked from phpbb-extensions/webpushnotifications
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller_manifest_test.php
More file actions
175 lines (157 loc) · 3.97 KB
/
controller_manifest_test.php
File metadata and controls
175 lines (157 loc) · 3.97 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
/**
*
* phpBB Browser Push Notifications. An extension for the phpBB Forum Software package.
*
* @copyright (c) 2025, phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/
namespace phpbb\webpushnotifications\tests\controller;
use Symfony\Component\HttpFoundation\JsonResponse;
class controller_manifest_test extends \phpbb_test_case
{
protected $config;
protected $user;
protected $manifest;
protected function setUp(): void
{
global $config, $user, $phpbb_root_path, $phpEx;
parent::setUp();
$config = $this->config = new \phpbb\config\config([
'force_server_vars' => false,
'script_path' => '',
'sitename' => '',
'pwa_short_name' => '',
'pwa_icon_small' => '',
'pwa_icon_large' => '',
]);
$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
$language = new \phpbb\language\language($lang_loader);
$user = $this->user = new \phpbb\user($language, '\phpbb\datetime');
$this->manifest = new \phpbb\webpushnotifications\controller\manifest($this->config, $this->user);
}
public function manifest_data()
{
return [
'using board url root path' => [
[
'force_server_vars' => false,
'script_path' => '',
'sitename' => 'yourdomain.com',
'pwa_short_name' => 'yourdomain',
],
[
'name' => 'yourdomain.com',
'short_name' => 'yourdomain',
'display' => 'standalone',
'orientation' => 'portrait',
'start_url' => '/',
'scope' => '/',
],
],
'using script path' => [
[
'force_server_vars' => true,
'script_path' => '/foo/',
'sitename' => 'yourdomain.com',
'pwa_short_name' => 'yourdomain',
],
[
'name' => 'yourdomain.com',
'short_name' => 'yourdomain',
'display' => 'standalone',
'orientation' => 'portrait',
'start_url' => '/foo/',
'scope' => '/foo/',
],
],
'with shortname' => [
[
'sitename' => 'testdomain.com',
'pwa_short_name' => 'testdomain',
],
[
'name' => 'testdomain.com',
'short_name' => 'testdomain',
'display' => 'standalone',
'orientation' => 'portrait',
'start_url' => '/',
'scope' => '/',
],
],
'without shortname' => [
[
'sitename' => 'testdomain.com',
'pwa_short_name' => '',
],
[
'name' => 'testdomain.com',
'short_name' => 'testdomain.c',
'display' => 'standalone',
'orientation' => 'portrait',
'start_url' => '/',
'scope' => '/',
],
],
'with icons' => [
[
'sitename' => '',
'pwa_short_name' => '',
'pwa_icon_small' => 'foo_sm.png',
'pwa_icon_large' => 'foo_lg.png',
],
[
'name' => '',
'short_name' => '',
'display' => 'standalone',
'orientation' => 'portrait',
'start_url' => '/',
'scope' => '/',
'icons' => [
[
'src' => 'http://images/site_icons/foo_sm.png',
'sizes' => '192x192',
'type' => 'image/png',
],
[
'src' => 'http://images/site_icons/foo_lg.png',
'sizes' => '512x512',
'type' => 'image/png',
],
],
],
],
];
}
/**
* @dataProvider manifest_data
*/
public function test_manifest($configs, $expected)
{
foreach ($configs as $key => $value)
{
$this->config->set($key, $value);
}
$response = $this->manifest->handle();
$this->assertInstanceOf(JsonResponse::class, $response);
$this->assertEquals($expected, json_decode($response->getContent(), true));
}
public function manifest_with_bot_data()
{
return [
'is a bot' => [true, 'yes'],
'not a bot' => [false, null],
];
}
/**
* @dataProvider manifest_with_bot_data
*/
public function test_manifest_with_bot($is_bot, $expected)
{
$this->user->data['is_bot'] = $is_bot;
$response = $this->manifest->handle();
$this->assertInstanceOf(JsonResponse::class, $response);
$this->assertEquals($expected, $response->headers->get('X-PHPBB-IS-BOT'));
}
}