Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/notifications.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Push.php4
-rw-r--r--tests/Unit/PushTest.php55
2 files changed, 59 insertions, 0 deletions
diff --git a/lib/Push.php b/lib/Push.php
index d6b9b12..d377df8 100644
--- a/lib/Push.php
+++ b/lib/Push.php
@@ -108,6 +108,10 @@ class Push {
}
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;
diff --git a/tests/Unit/PushTest.php b/tests/Unit/PushTest.php
index 57efa14..be6c36d 100644
--- a/tests/Unit/PushTest.php
+++ b/tests/Unit/PushTest.php
@@ -125,6 +125,26 @@ class PushTest extends TestCase {
);
}
+ 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())
@@ -132,6 +152,11 @@ class PushTest extends TestCase {
$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->expects($this->once())
@@ -153,6 +178,11 @@ class PushTest extends TestCase {
$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->expects($this->exactly(2))
@@ -181,6 +211,11 @@ class PushTest extends TestCase {
$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->expects($this->exactly(3))
@@ -224,6 +259,11 @@ class PushTest extends TestCase {
$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->expects($this->exactly(3))
@@ -288,6 +328,11 @@ class PushTest extends TestCase {
$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->expects($this->exactly(2))
@@ -447,6 +492,11 @@ class PushTest extends TestCase {
->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')
@@ -656,6 +706,11 @@ class PushTest extends TestCase {
->willReturn($response);
}
+ $this->config->expects($this->once())
+ ->method('getSystemValueBool')
+ ->with('has_internet_connection', true)
+ ->willReturn(true);
+
$push->pushToDevice(200718, $notification);
}