diff --git a/tests/Unit/PushTest.php b/tests/Unit/PushTest.php index 011ab1caa..dc1a07652 100644 --- a/tests/Unit/PushTest.php +++ b/tests/Unit/PushTest.php @@ -37,6 +37,7 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamInterface; use Psr\Log\LoggerInterface; +use Symfony\Component\Console\Output\OutputInterface; use Test\TestCase; /** @@ -453,6 +454,22 @@ public function testPushToDeviceSending(bool $isDebug, string $padding): void { ->method('getUser') ->willReturn('valid'); + $notification + ->method('getParsedSubject') + ->willReturn('ParsedSubject'); + + $notification + ->method('getApp') + ->willReturn('PushTestApp'); + + $notification + ->method('getObjectType') + ->willReturn('PushTestType'); + + $notification + ->method('getObjectId') + ->willReturn('PushTestObjectId'); + /** @var IUser&MockObject $user */ $user = $this->createMock(IUser::class); @@ -714,7 +731,27 @@ public function testPushToDeviceSending(bool $isDebug, string $padding): void { $push->method('deletePushTokenByDeviceIdentifier') ->with('badrequest-with-devices', '123456'); + /** @var OutputInterface&MockObject $user */ + $output = $this->createMock(OutputInterface::class); + $foundExpectedJsonData = false; + $output + ->method('writeln') + ->willReturnCallback(function ($string) use (&$foundExpectedJsonData) { + if (str_contains($string, '"subject":"ParsedSubject"') + && str_contains($string, '"nid":207787') + && str_contains($string, '"type":"PushTestType"') + && str_contains($string, '"id":"PushTestObjectId"') + && str_contains($string, '"app":"PushTestApp"')) { + + $foundExpectedJsonData = true; + } + }); + + $push->setOutput($output); + $push->pushToDevice(207787, $notification); + + $this->assertTrue($foundExpectedJsonData, 'Failed to find correct subject, nid, type, id or app in json encoded push data'); } public static function dataPushToDeviceTalkNotification(): array {