function testPush() { $topic0 = uniqid('topic-'); $topic1 = uniqid('topic-'); $callback = uniqid('callback-'); $payload = array('user' => 'peter', 'path' => '/Readme.txt'); $subscriptions = new \OCA\Web_Hooks\Subscriptions(); $subscriber0 = $subscriptions->add($callback, $topic0); $subscriber1 = $subscriptions->add($callback, $topic1); $notifications = new \OCA\Web_Hooks\Notifications(); $notifications->add($payload, $subscriber0); $notifications->add($payload, $subscriber1); $receivedNotifications = array(); $cron = new \OCA\Web_Hooks\Cron($notifications, $subscriptions, function ($notification) use(&$receivedNotifications) { $receivedNotifications[] = $notification; return true; }); $cron->pushNotifications(); $this->assertEquals(2, count($receivedNotifications)); foreach ($receivedNotifications as $one) { $this->assertTrue(is_array($one)); $this->assertArrayHasKey('id', $one); $this->assertArrayHasKey('topic', $one); $this->assertArrayHasKey('callback', $one); $this->assertArrayHasKey('payload', $one); } $remainingNotifications = $notifications->all(); $this->assertEquals(0, count($remainingNotifications)); }
function testDeleteById() { $payload = array('user' => 'peter', 'path' => '/Readme.txt'); $storage1 = new \OCA\Web_Hooks\Notifications(); $storage1->add($payload, 1); $storage1->add($payload, 2); $storage1->add($payload, 3); $storage1->add($payload, 4); $notifications = $this->assertNotifications(4); $notification = $notifications[0]; $storage1->deleteById($notification['id']); $this->assertNotifications(3); }