Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 69 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| phpbb_functional_notification_webpush_test | |
0.00% |
0 / 69 |
|
0.00% |
0 / 4 |
42 | |
0.00% |
0 / 1 |
| test_acp_module | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
12 | |||
| test_ucp_module | |
0.00% |
0 / 30 |
|
0.00% |
0 / 1 |
2 | |||
| test_dropdown_subscribe_button | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
2 | |||
| set_acp_option | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * |
| 4 | * This file is part of the phpBB Forum Software package. |
| 5 | * |
| 6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
| 7 | * @license GNU General Public License, version 2 (GPL-2.0) |
| 8 | * |
| 9 | * For full copyright and license information, please see |
| 10 | * the docs/CREDITS.txt file. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | /** |
| 15 | * @group functional |
| 16 | */ |
| 17 | class phpbb_functional_notification_webpush_test extends phpbb_functional_test_case |
| 18 | { |
| 19 | public function test_acp_module() |
| 20 | { |
| 21 | $this->login(); |
| 22 | $this->admin_login(); |
| 23 | |
| 24 | $this->add_lang(['acp/board', 'acp/common']); |
| 25 | |
| 26 | $crawler = self::request('GET', 'adm/index.php?i=acp_board&mode=webpush&sid=' . $this->sid); |
| 27 | |
| 28 | $this->assertContainsLang('ACP_WEBPUSH_SETTINGS', $crawler->filter('div.main > h1')->text()); |
| 29 | $this->assertContainsLang('ACP_WEBPUSH_SETTINGS_EXPLAIN', $crawler->filter('div.main > p')->text()); |
| 30 | $this->assertContainsLang('WEBPUSH_GENERATE_VAPID_KEYS', $crawler->filter('input[type="button"]')->attr('value')); |
| 31 | |
| 32 | $form_data = [ |
| 33 | 'config[webpush_enable]' => 1, |
| 34 | 'config[webpush_vapid_public]' => 'BDnYSJHVZBxq834LqDGr893IfazEez7q-jYH2QBNlT0ji2C9UwGosiqz8Dp_ZN23lqAngBZyRjXVWF4ZLA8X2zI', |
| 35 | 'config[webpush_vapid_private]' => 'IE5OYlmfWsMbBU1lzvr0bxrxVAXIteSkAnwGlZIhmRk', |
| 36 | 'config[webpush_method_default_enable]' => 1, |
| 37 | 'config[webpush_dropdown_subscribe]' => 1, |
| 38 | ]; |
| 39 | $form = $crawler->selectButton('submit')->form($form_data); |
| 40 | $crawler = self::submit($form); |
| 41 | $this->assertStringContainsString($this->lang('CONFIG_UPDATED'), $crawler->filter('.successbox')->text()); |
| 42 | |
| 43 | $crawler = self::request('GET', 'adm/index.php?i=acp_board&mode=webpush&sid=' . $this->sid); |
| 44 | |
| 45 | foreach ($form_data as $config_name => $config_value) |
| 46 | { |
| 47 | $config_value = ($config_name === 'config[webpush_vapid_private]') ? '********' : $config_value; |
| 48 | $this->assertEquals($config_value, $crawler->filter('input[name="' . $config_name . '"]')->attr('value')); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | public function test_ucp_module() |
| 53 | { |
| 54 | $this->login(); |
| 55 | $this->admin_login(); |
| 56 | |
| 57 | $this->add_lang('ucp'); |
| 58 | |
| 59 | $crawler = self::request('GET', 'ucp.php?i=ucp_notifications&mode=notification_options'); |
| 60 | |
| 61 | $this->assertContainsLang('NOTIFY_WEBPUSH_ENABLE', $crawler->filter('label[for="subscribe_webpush"]')->text()); |
| 62 | $this->assertContainsLang('NOTIFICATION_METHOD_WEBPUSH', $crawler->filter('th.mark')->eq(2)->text()); |
| 63 | |
| 64 | // Assert checkbox is checked |
| 65 | $wp_list = $crawler->filter('.table1'); |
| 66 | $this->assert_checkbox_is_checked($wp_list, 'notification.type.bookmark_notification.method.webpush'); |
| 67 | $this->assert_checkbox_is_checked($wp_list, 'notification.type.mention_notification.method.webpush'); |
| 68 | $this->assert_checkbox_is_checked($wp_list, 'notification.type.post_notification.method.webpush'); |
| 69 | $this->assert_checkbox_is_checked($wp_list, 'notification.type.quote_notification.method.webpush'); |
| 70 | $this->assert_checkbox_is_checked($wp_list, 'notification.type.topic_notification.method.webpush'); |
| 71 | $this->assert_checkbox_is_checked($wp_list, 'notification.type.forum_notification.method.webpush'); |
| 72 | $this->assert_checkbox_is_checked($wp_list, 'notification.type.group_request_notification.method.webpush'); |
| 73 | $this->assert_checkbox_is_checked($wp_list, 'notification.type.pm_notification.method.webpush'); |
| 74 | $this->assert_checkbox_is_checked($wp_list, 'notification.type.report_pm_closed_notification.method.webpush'); |
| 75 | $this->assert_checkbox_is_checked($wp_list, 'notification.type.report_post_closed_notification.method.webpush'); |
| 76 | |
| 77 | $this->set_acp_option('webpush_method_default_enable', 0); |
| 78 | |
| 79 | $crawler = self::request('GET', 'ucp.php?i=ucp_notifications&mode=notification_options'); |
| 80 | |
| 81 | // Assert checkbox is unchecked |
| 82 | $wp_list = $crawler->filter('.table1'); |
| 83 | $this->assert_checkbox_is_unchecked($wp_list, 'notification.type.bookmark_notification.method.webpush'); |
| 84 | $this->assert_checkbox_is_unchecked($wp_list, 'notification.type.mention_notification.method.webpush'); |
| 85 | $this->assert_checkbox_is_unchecked($wp_list, 'notification.type.post_notification.method.webpush'); |
| 86 | $this->assert_checkbox_is_unchecked($wp_list, 'notification.type.quote_notification.method.webpush'); |
| 87 | $this->assert_checkbox_is_unchecked($wp_list, 'notification.type.topic_notification.method.webpush'); |
| 88 | $this->assert_checkbox_is_unchecked($wp_list, 'notification.type.forum_notification.method.webpush'); |
| 89 | $this->assert_checkbox_is_unchecked($wp_list, 'notification.type.group_request_notification.method.webpush'); |
| 90 | $this->assert_checkbox_is_unchecked($wp_list, 'notification.type.pm_notification.method.webpush'); |
| 91 | $this->assert_checkbox_is_unchecked($wp_list, 'notification.type.report_pm_closed_notification.method.webpush'); |
| 92 | $this->assert_checkbox_is_unchecked($wp_list, 'notification.type.report_post_closed_notification.method.webpush'); |
| 93 | } |
| 94 | |
| 95 | public function test_dropdown_subscribe_button() |
| 96 | { |
| 97 | $this->login(); |
| 98 | $this->admin_login(); |
| 99 | |
| 100 | // Assert subscribe dropdown is present |
| 101 | $crawler = self::request('GET', 'index.php'); |
| 102 | $this->assertCount(1, $crawler->filter('.webpush-subscribe')); |
| 103 | $this->assertContainsLang('NOTIFY_WEB_PUSH_SUBSCRIBE', $crawler->filter('.webpush-subscribe #subscribe_webpush')->text()); |
| 104 | $this->assertContainsLang('NOTIFY_WEB_PUSH_SUBSCRIBED', $crawler->filter('.webpush-subscribe #unsubscribe_webpush')->text()); |
| 105 | |
| 106 | // Assert subscribe button is not displayed in UCP when dropdown subscribe is present |
| 107 | $crawler = self::request('GET', 'ucp.php?i=ucp_notifications&mode=notification_options'); |
| 108 | $this->assertCount(0, $crawler->filter('.webpush-subscribe')); |
| 109 | |
| 110 | $this->set_acp_option('webpush_dropdown_subscribe', 0); |
| 111 | |
| 112 | // Assert subscribe dropdown is not present by default |
| 113 | $crawler = self::request('GET', 'index.php'); |
| 114 | $this->assertCount(0, $crawler->filter('.webpush-subscribe')); |
| 115 | } |
| 116 | |
| 117 | protected function set_acp_option($option, $value) |
| 118 | { |
| 119 | $crawler = self::request('GET', 'adm/index.php?i=acp_board&mode=webpush&sid=' . $this->sid); |
| 120 | $form = $crawler->selectButton('Submit')->form(); |
| 121 | $values = $form->getValues(); |
| 122 | $values["config[{$option}]"] = $value; |
| 123 | $form->setValues($values); |
| 124 | $crawler = self::submit($form); |
| 125 | $this->assertEquals(1, $crawler->filter('.successbox')->count()); |
| 126 | } |
| 127 | } |