From 39240b94d0b20b7a7f8d026997908fac5780699b Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Mon, 8 Jan 2024 22:56:54 -0800 Subject: [PATCH] Add more data to test Signed-off-by: Matt Friedman --- tests/event/fixtures/webpush.xml | 18 +++++++++++++- tests/event/listener_test.php | 41 +++++++++++++++++++++++++++----- 2 files changed, 52 insertions(+), 7 deletions(-) diff --git a/tests/event/fixtures/webpush.xml b/tests/event/fixtures/webpush.xml index 037b8b6..c6fd1c2 100644 --- a/tests/event/fixtures/webpush.xml +++ b/tests/event/fixtures/webpush.xml @@ -12,7 +12,23 @@ 1 2 - https://web.push.test.localhost/foo + https://web.push.test.localhost/foo2 + + + 0 + + + 2 + 3 + https://web.push.test.localhost/foo3 + + + 1 + + + 3 + 4 + https://web.push.test.localhost/foo4 0 diff --git a/tests/event/listener_test.php b/tests/event/listener_test.php index 2ccbe0f..2f0c470 100644 --- a/tests/event/listener_test.php +++ b/tests/event/listener_test.php @@ -60,8 +60,8 @@ protected function setUp(): void $request = new \phpbb\request\request(); $request->enable_super_globals(); $user = new \phpbb\user($this->language, '\phpbb\datetime'); - $user->data['user_id'] = 2; - $user->data['user_form_salt'] = ''; + $this->user = $user; + $this->user->data['user_form_salt'] = ''; $user_loader = new \phpbb\user_loader($db, $phpbb_root_path, $phpEx, 'phpbb_users'); $this->controller_helper = $this->getMockBuilder('\phpbb\controller\helper') @@ -77,12 +77,12 @@ protected function setUp(): void $this->form_helper = new \phpbb\webpushnotifications\form\form_helper( $this->config, $request, - $user + $this->user ); $phpbb_container = $this->container = new ContainerBuilder(); $phpbb_container->set('user_loader', $user_loader); - $phpbb_container->set('user', $user); + $phpbb_container->set('user', $this->user); $phpbb_container->set('config', $this->config); $phpbb_container->set('dbal.conn', $db); $phpbb_container->set('log', new \phpbb\log\dummy()); @@ -163,15 +163,43 @@ public function get_ucp_template_data_data() { return [ [ + 2, 'method_data' => [ 'id' => 'notification.method.phpbb.wpn.webpush', ], + [['endpoint' => 'https://web.push.test.localhost/foo2', 'expirationTime' => 0]], true, ], [ + 2, 'method_data' => [ 'id' => 'notification.method.phpbb.email', ], + [], + false, + ], + [ + 3, + 'method_data' => [ + 'id' => 'notification.method.phpbb.wpn.webpush', + ], + [['endpoint' => 'https://web.push.test.localhost/foo3', 'expirationTime' => 1]], + true, + ], + [ + 5, + 'method_data' => [ + 'id' => 'notification.method.phpbb.wpn.webpush', + ], + [], + true, + ], + [ + 5, + 'method_data' => [ + 'id' => 'notification.method.phpbb.email', + ], + [], false, ], ]; @@ -180,8 +208,9 @@ public function get_ucp_template_data_data() /** * @dataProvider get_ucp_template_data_data */ - public function test_get_ucp_template_data($method_data, $expected) + public function test_get_ucp_template_data($user_id, $method_data, $subscriptions, $expected) { + $this->user->data['user_id'] = $user_id; $this->template->expects($expected ? self::once() : self::never()) ->method('assign_vars') ->with([ @@ -190,7 +219,7 @@ public function test_get_ucp_template_data($method_data, $expected) 'U_WEBPUSH_UNSUBSCRIBE' => $this->controller_helper->route('phpbb_webpushnotifications_ucp_push_unsubscribe_controller'), 'VAPID_PUBLIC_KEY' => $this->config['wpn_webpush_vapid_public'], 'U_WEBPUSH_WORKER_URL' => $this->controller_helper->route('phpbb_webpushnotifications_ucp_push_worker_controller'), - 'SUBSCRIPTIONS' => [['endpoint' => 'https://web.push.test.localhost/foo', 'expirationTime' => 0]], + 'SUBSCRIPTIONS' => $subscriptions, 'WEBPUSH_FORM_TOKENS' => $this->form_helper->get_form_tokens(ucp_webpush::FORM_TOKEN_UCP), ] );