Skip to content

Commit 3412064

Browse files
committed
Fix and add tests
Signed-off-by: Matt Friedman <maf675@gmail.com>
1 parent cad0c69 commit 3412064

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

tests/event/listener_test.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ public function get_ucp_template_data_data()
205205
*/
206206
public function test_get_ucp_template_data($user_id, $method_data, $subscriptions, $expected)
207207
{
208+
$this->config['wpn_webpush_dropdown_subscribe'] = true;
208209
$this->user->data['user_id'] = $user_id;
209210
$this->template->expects($expected ? self::once() : self::never())
210211
->method('assign_vars')

tests/functional/functional_test.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,27 +65,62 @@ public function test_acp_module()
6565
public function test_ucp_module()
6666
{
6767
$this->login();
68+
$this->admin_login();
6869

6970
$this->add_lang_ext('phpbb/webpushnotifications', 'webpushnotifications_module_ucp');
7071

7172
$crawler = self::request('GET', 'ucp.php?i=ucp_notifications&mode=notification_options');
7273

7374
$this->assertContainsLang('NOTIFY_WEBPUSH_ENABLE', $crawler->filter('label[for="subscribe_webpush"]')->text());
7475
$this->assertContainsLang('NOTIFICATION_METHOD_PHPBB_WPN_WEBPUSH', $crawler->filter('th.mark')->eq(2)->text());
76+
77+
// Assert checkbox is unchecked by default
78+
$wp_list = $crawler->filter('.table1');
79+
$this->assert_checkbox_is_unchecked($wp_list, 'notification.type.quote_notification.method.phpbb.wpn.webpush');
80+
$this->assert_checkbox_is_unchecked($wp_list, 'notification.type.pm_notification.method.phpbb.wpn.webpush');
81+
82+
$this->set_acp_option('wpn_webpush_method_enabled', 1);
83+
84+
$crawler = self::request('GET', 'ucp.php?i=ucp_notifications&mode=notification_options');
85+
86+
// Assert checkbox is checked
87+
$wp_list = $crawler->filter('.table1');
88+
$this->assert_checkbox_is_checked($wp_list, 'notification.type.quote_notification.method.phpbb.wpn.webpush');
89+
$this->assert_checkbox_is_checked($wp_list, 'notification.type.pm_notification.method.phpbb.wpn.webpush');
7590
}
7691

7792
public function test_dropdown_subscribe_button()
7893
{
7994
$this->login();
95+
$this->admin_login();
8096

8197
$this->add_lang_ext('phpbb/webpushnotifications', 'webpushnotifications_module_ucp');
8298

99+
// Assert subscribe dropdown is not present by default
100+
$crawler = self::request('GET', 'index.php');
101+
$this->assertCount(0, $crawler->filter('.wpn-notification-dropdown-footer'));
102+
103+
$this->set_acp_option('wpn_webpush_dropdown_subscribe', 1);
104+
105+
// Assert subscribe dropdown is present
83106
$crawler = self::request('GET', 'index.php');
84107
$this->assertCount(1, $crawler->filter('.wpn-notification-dropdown-footer'));
85108
$this->assertContainsLang('NOTIFY_WEBPUSH_SUBSCRIBE', $crawler->filter('.wpn-notification-dropdown-footer #subscribe_webpush')->text());
86109
$this->assertContainsLang('NOTIFY_WEBPUSH_SUBSCRIBED', $crawler->filter('.wpn-notification-dropdown-footer #unsubscribe_webpush')->text());
87110

111+
// Assert subscribe button is not displayed in UCP when dropdown subscribe is present
88112
$crawler = self::request('GET', 'ucp.php?i=ucp_notifications&mode=notification_options');
89113
$this->assertCount(0, $crawler->filter('.wpn-notification-dropdown-footer'));
90114
}
115+
116+
protected function set_acp_option($option, $value)
117+
{
118+
$crawler = self::request('GET', 'adm/index.php?i=-phpbb-webpushnotifications-acp-wpn_acp_module&mode=webpush&sid=' . $this->sid);
119+
$form = $crawler->selectButton('Submit')->form();
120+
$values = $form->getValues();
121+
$values["config[{$option}]"] = $value;
122+
$form->setValues($values);
123+
$crawler = self::submit($form);
124+
$this->assertEquals(1, $crawler->filter('.successbox')->count());
125+
}
91126
}

0 commit comments

Comments
 (0)