[ticket/17465] Cover more exceptions when handling notification

PHPBB-17465
This commit is contained in:
Marc Alexander 2025-01-28 21:15:33 +01:00
parent ac3e9f64d8
commit c5c6c96a50
No known key found for this signature in database
GPG key ID: 50E0D2423696F995

View file

@ -65,39 +65,85 @@ class test_ucp_controller_webpush_test extends phpbb_test_case
); );
} }
public function data_notification_no_data(): array public function data_notification_exceptions(): array
{ {
return [ return [
'logged_in_user' => [ 'not_ajax' => [
false,
false,
USER_NORMAL, USER_NORMAL,
2, 2,
[], [],
'NO_AUTH_OPERATION',
], ],
'anonymous_user' => [ 'is_bot' => [
true,
true,
USER_NORMAL,
2,
[],
'NO_AUTH_OPERATION',
],
'inactive_user' => [
true,
false,
USER_INACTIVE,
2,
[],
'NO_AUTH_OPERATION',
],
'ignore_user' => [
true,
false,
USER_IGNORE,
2,
[],
'NO_AUTH_OPERATION',
],
'no_notification' => [
true,
false,
USER_NORMAL,
2,
[],
'AJAX_ERROR_TEXT',
],
'no_notification_anonymous' => [
true,
false,
USER_NORMAL, USER_NORMAL,
ANONYMOUS, ANONYMOUS,
[ [
['token', '', false, request_interface::REQUEST, 'foobar'], ['token', '', false, request_interface::REQUEST, 'foobar'],
], ],
'AJAX_ERROR_TEXT',
],
'no_notification_anonymous_no_token' => [
true,
false,
USER_NORMAL,
ANONYMOUS,
[],
'NO_AUTH_OPERATION',
], ],
]; ];
} }
/** /**
* @dataProvider data_notification_no_data * @dataProvider data_notification_exceptions
*/ */
public function test_notification_no_data($user_type, $user_id, $request_data) public function test_notification_no_data($is_ajax, $is_bot, $user_type, $user_id, $request_data, $expected_message)
{ {
$this->request->method('is_ajax')->willReturn(true); $this->request->method('is_ajax')->willReturn($is_ajax);
$this->request->expects($this->any()) $this->request->expects($this->any())
->method('variable') ->method('variable')
->will($this->returnValueMap($request_data)); ->will($this->returnValueMap($request_data));
$this->user->data['is_bot'] = false; $this->user->data['is_bot'] = $is_bot;
$this->user->data['user_type'] = $user_type; $this->user->data['user_type'] = $user_type;
$this->user->method('id')->willReturn($user_id); $this->user->method('id')->willReturn($user_id);
$this->expectException(http_exception::class); $this->expectException(http_exception::class);
$this->expectExceptionMessage('AJAX_ERROR_TEXT'); $this->expectExceptionMessage($expected_message);
$this->controller->notification(); $this->controller->notification();
} }