Skip to content

Commit

Permalink
Add more data to test
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Friedman <[email protected]>
  • Loading branch information
iMattPro committed Jan 9, 2024
1 parent 88aaaff commit 39240b9
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
18 changes: 17 additions & 1 deletion tests/event/fixtures/webpush.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,23 @@
<row>
<value>1</value>
<value>2</value>
<value>https://web.push.test.localhost/foo</value>
<value>https://web.push.test.localhost/foo2</value>
<value></value>
<value></value>
<value>0</value>
</row>
<row>
<value>2</value>
<value>3</value>
<value>https://web.push.test.localhost/foo3</value>
<value></value>
<value></value>
<value>1</value>
</row>
<row>
<value>3</value>
<value>4</value>
<value>https://web.push.test.localhost/foo4</value>
<value></value>
<value></value>
<value>0</value>
Expand Down
41 changes: 35 additions & 6 deletions tests/event/listener_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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());
Expand Down Expand Up @@ -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,
],
];
Expand All @@ -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([
Expand All @@ -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),
]
);
Expand Down

0 comments on commit 39240b9

Please sign in to comment.