Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/Push.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ public function flushPayloads(): void {
}

public function pushToDevice(int $id, INotification $notification, ?OutputInterface $output = null): void {
if (!$this->config->getSystemValueBool('has_internet_connection', true)) {
return;
}

$user = $this->userManager->get($notification->getUser());
if (!($user instanceof IUser)) {
return;
Expand Down
55 changes: 55 additions & 0 deletions tests/Unit/PushTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,38 @@ protected function getPush(array $methods = []) {
);
}

public function testPushToDeviceNoInternet() {
$push = $this->getPush();

$this->config->expects($this->once())
->method('getSystemValueBool')
->with('has_internet_connection', true)
->willReturn(false);
$this->keyManager->expects($this->never())
->method('getKey');
$this->clientService->expects($this->never())
->method('newClient');
$this->userManager->expects($this->never())
->method('get');

/** @var INotification|MockObject$notification */
$notification = $this->createMock(INotification::class);

$push->pushToDevice(23, $notification);
}

public function testPushToDeviceInvalidUser() {
$push = $this->getPush();
$this->keyManager->expects($this->never())
->method('getKey');
$this->clientService->expects($this->never())
->method('newClient');

$this->config->expects($this->once())
->method('getSystemValueBool')
->with('has_internet_connection', true)
->willReturn(true);

/** @var INotification|MockObject$notification */
$notification = $this->createMock(INotification::class);
$notification
Expand All @@ -159,6 +184,11 @@ public function testPushToDeviceNoDevices() {
$this->clientService->expects($this->never())
->method('newClient');

$this->config->expects($this->once())
->method('getSystemValueBool')
->with('has_internet_connection', true)
->willReturn(true);

/** @var INotification|MockObject $notification */
$notification = $this->createMock(INotification::class);
$notification
Expand Down Expand Up @@ -187,6 +217,11 @@ public function testPushToDeviceNotPrepared() {
$this->clientService->expects($this->never())
->method('newClient');

$this->config->expects($this->once())
->method('getSystemValueBool')
->with('has_internet_connection', true)
->willReturn(true);

/** @var INotification|MockObject $notification */
$notification = $this->createMock(INotification::class);
$notification
Expand Down Expand Up @@ -226,6 +261,11 @@ public function testPushToDeviceInvalidToken() {
$this->clientService->expects($this->never())
->method('newClient');

$this->config->expects($this->once())
->method('getSystemValueBool')
->with('has_internet_connection', true)
->willReturn(true);

/** @var INotification|MockObject $notification */
$notification = $this->createMock(INotification::class);
$notification
Expand Down Expand Up @@ -286,6 +326,11 @@ public function testPushToDeviceEncryptionError() {
$this->clientService->expects($this->never())
->method('newClient');

$this->config->expects($this->once())
->method('getSystemValueBool')
->with('has_internet_connection', true)
->willReturn(true);

/** @var INotification|MockObject $notification */
$notification = $this->createMock(INotification::class);
$notification
Expand Down Expand Up @@ -440,6 +485,11 @@ public function testPushToDeviceSending($isDebug) {
->method('newClient')
->willReturn($client);

$this->config->expects($this->once())
->method('getSystemValueBool')
->with('has_internet_connection', true)
->willReturn(true);

$e = new \Exception();
$client->expects($this->at(0))
->method('post')
Expand Down Expand Up @@ -645,6 +695,11 @@ public function testPushToDeviceTalkNotification(array $deviceTypes, $isTalkNoti
->willReturn($response);
}

$this->config->expects($this->once())
->method('getSystemValueBool')
->with('has_internet_connection', true)
->willReturn(true);

$push->pushToDevice(200718, $notification);
}

Expand Down