forked from phpbb-extensions/webpushnotifications
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctional_test.php
More file actions
175 lines (138 loc) · 6.95 KB
/
functional_test.php
File metadata and controls
175 lines (138 loc) · 6.95 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) 2023, phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/
namespace phpbb\webpushnotifications\tests\functional;
/**
* @group functional
*/
class functional_test extends \phpbb_functional_test_case
{
protected static function setup_extensions()
{
return array('phpbb/webpushnotifications');
}
public function test_extension_enabled()
{
$this->login();
$this->admin_login();
$crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&sid=' . $this->sid);
$this->assertStringContainsString('phpBB Browser Push Notifications', $crawler->filter('.ext_enabled')->eq(0)->text());
$this->assertContainsLang('EXTENSION_DISABLE', $crawler->filter('.ext_enabled')->eq(0)->text());
}
public function test_acp_module()
{
$this->login();
$this->admin_login();
$this->add_lang_ext('phpbb/webpushnotifications', ['info_acp_webpushnotifications', 'webpushnotifications_module_acp']);
$crawler = self::request('GET', 'adm/index.php?i=-phpbb-webpushnotifications-acp-wpn_acp_module&mode=webpush&sid=' . $this->sid);
$this->assertContainsLang('ACP_WEBPUSH_EXT_SETTINGS', $crawler->filter('div.main > h1')->text());
$this->assertContainsLang('ACP_WEBPUSH_SETTINGS_EXPLAIN', $crawler->filter('div.main > p')->html());
$this->assertContainsLang('WEBPUSH_GENERATE_VAPID_KEYS', $crawler->filter('input[type="button"]')->attr('value'));
$form_data = [
'config[wpn_webpush_enable]' => 1,
'config[wpn_webpush_vapid_public]' => 'BDnYSJHVZBxq834LqDGr893IfazEez7q-jYH2QBNlT0ji2C9UwGosiqz8Dp_ZN23lqAngBZyRjXVWF4ZLA8X2zI',
'config[wpn_webpush_vapid_private]' => 'IE5OYlmfWsMbBU1lzvr0bxrxVAXIteSkAnwGlZIhmRk',
];
$form = $crawler->selectButton('submit')->form($form_data);
$crawler = self::submit($form);
$this->assertStringContainsString($this->lang('CONFIG_UPDATED'), $crawler->filter('.successbox')->text());
$crawler = self::request('GET', 'adm/index.php?i=-phpbb-webpushnotifications-acp-wpn_acp_module&mode=webpush&sid=' . $this->sid);
foreach ($form_data as $config_name => $config_value)
{
$config_value = ($config_name === 'config[wpn_webpush_vapid_private]') ? \phpbb\webpushnotifications\acp\wpn_acp_module::MASKED_PRIVATE_KEY : $config_value;
$this->assertEquals($config_value, $crawler->filter('input[name="' . $config_name . '"]')->attr('value'));
}
}
public function test_ucp_module()
{
$this->login();
$this->admin_login();
$this->add_lang_ext('phpbb/webpushnotifications', 'webpushnotifications_module_ucp');
$crawler = self::request('GET', 'ucp.php?i=ucp_notifications&mode=notification_options');
$this->assertContainsLang('NOTIFY_WEBPUSH_NOTIFICATIONS', $crawler->filter('label[for="subscribe_webpush"]')->text());
$this->assertContainsLang('NOTIFICATION_METHOD_PHPBB_WPN_WEBPUSH', $crawler->filter('th.mark')->eq(2)->text());
// Assert checkbox is unchecked by default
$wp_list = $crawler->filter('.table1');
$this->assert_checkbox_is_unchecked($wp_list, 'notification.type.quote_notification.method.phpbb.wpn.webpush');
$this->assert_checkbox_is_unchecked($wp_list, 'notification.type.pm_notification.method.phpbb.wpn.webpush');
$this->set_acp_option('wpn_webpush_method_enabled', 1);
$crawler = self::request('GET', 'ucp.php?i=ucp_notifications&mode=notification_options');
// Assert checkbox is checked
$wp_list = $crawler->filter('.table1');
$this->assert_checkbox_is_checked($wp_list, 'notification.type.quote_notification.method.phpbb.wpn.webpush');
$this->assert_checkbox_is_checked($wp_list, 'notification.type.pm_notification.method.phpbb.wpn.webpush');
}
public function test_dropdown_subscribe_button()
{
$this->login();
$this->admin_login();
$this->add_lang_ext('phpbb/webpushnotifications', 'webpushnotifications_module_ucp');
// Assert subscribe dropdown is not present by default
$crawler = self::request('GET', 'index.php');
$this->assertCount(0, $crawler->filter('.wpn-notification-dropdown-footer'));
$this->set_acp_option('wpn_webpush_dropdown_subscribe', 1);
// Assert subscribe dropdown is present
$crawler = self::request('GET', 'index.php');
$this->assertCount(1, $crawler->filter('.wpn-notification-dropdown-footer'));
$this->assertContainsLang('NOTIFY_WEBPUSH_SUBSCRIBE', $crawler->filter('.wpn-notification-dropdown-footer #subscribe_webpush')->html());
$this->assertContainsLang('NOTIFY_WEBPUSH_UNSUBSCRIBE', $crawler->filter('.wpn-notification-dropdown-footer #unsubscribe_webpush')->html());
// Assert subscribe button is not displayed in UCP when dropdown subscribe is present
$crawler = self::request('GET', 'ucp.php?i=ucp_notifications&mode=notification_options');
$this->assertCount(0, $crawler->filter('.wpn-notification-dropdown-footer'));
}
public function test_manifest()
{
$expected = [
'name' => 'yourdomain.com',
'short_name' => 'yourdomain',
'display' => 'standalone',
'orientation' => 'portrait',
'start_url' => '/',
'scope' => '/',
];
$this->login();
$this->admin_login();
$crawler = self::request('GET', 'adm/index.php?i=acp_board&mode=settings&sid=' . $this->sid);
$form_data = [
'config[pwa_short_name]' => $expected['short_name'],
];
$form = $crawler->selectButton('submit')->form($form_data);
$crawler = self::submit($form);
$this->assertStringContainsString($this->lang('CONFIG_UPDATED'), $crawler->filter('.successbox')->text());
self::request('GET', 'app.php/manifest', [], false);
$this->assertEquals(json_encode($expected), self::get_content());
}
public function test_popup_prompt()
{
$this->login();
$this->admin_login();
$this->add_lang_ext('phpbb/webpushnotifications', 'webpushnotifications_module_ucp');
// Assert popup is not present by default
$crawler = self::request('GET', 'index.php');
$this->assertCount(0, $crawler->filter('#wpn_popup_prompt'));
$this->set_acp_option('wpn_webpush_popup_prompt', 1);
// Assert popup is present when enabled
$crawler = self::request('GET', 'index.php');
$this->assertCount(1, $crawler->filter('#wpn_popup_prompt'));
$this->assertContainsLang('NOTIFY_WEBPUSH_POPUP_TITLE', $crawler->filter('.wpn-popup-title')->text());
$this->assertContainsLang('NOTIFY_WEBPUSH_POPUP_MESSAGE', $crawler->filter('.wpn-popup-message')->text());
$this->assertContainsLang('NOTIFY_WEBPUSH_POPUP_ALLOW', $crawler->filter('#wpn_popup_allow')->text());
$this->assertContainsLang('NOTIFY_WEBPUSH_POPUP_DENY', $crawler->filter('#wpn_popup_deny')->text());
}
protected function set_acp_option($option, $value)
{
$crawler = self::request('GET', 'adm/index.php?i=-phpbb-webpushnotifications-acp-wpn_acp_module&mode=webpush&sid=' . $this->sid);
$form = $crawler->selectButton('Submit')->form();
$values = $form->getValues();
$values["config[{$option}]"] = $value;
$form->setValues($values);
$crawler = self::submit($form);
$this->assertEquals(1, $crawler->filter('.successbox')->count());
}
}