@@ -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