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 @@ -67,6 +67,10 @@ public function __construct(IDBConnection $connection, INotificationManager $not
}

public function pushToDevice(int $id, INotification $notification): 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 @@ -110,13 +110,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|\PHPUnit_Framework_MockObject_MockObject $notification */
$notification = $this->createMock(INotification::class);
$notification->expects($this->once())
Expand All @@ -138,6 +163,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|\PHPUnit_Framework_MockObject_MockObject $notification */
$notification = $this->createMock(INotification::class);
$notification->expects($this->exactly(2))
Expand Down Expand Up @@ -166,6 +196,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|\PHPUnit_Framework_MockObject_MockObject $notification */
$notification = $this->createMock(INotification::class);
$notification->expects($this->exactly(3))
Expand Down Expand Up @@ -209,6 +244,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|\PHPUnit_Framework_MockObject_MockObject $notification */
$notification = $this->createMock(INotification::class);
$notification->expects($this->exactly(3))
Expand Down Expand Up @@ -270,6 +310,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|\PHPUnit_Framework_MockObject_MockObject $notification */
$notification = $this->createMock(INotification::class);
$notification->expects($this->exactly(2))
Expand Down Expand Up @@ -421,6 +466,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 @@ -622,6 +672,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