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() { $topic = uniqid('topic-'); $callback1 = uniqid('callback-'); $callback2 = uniqid('callback-'); $storage = new \OCA\Web_Hooks\Subscriptions(); $id0 = $storage->add($callback1, $topic); $id1 = $storage->add($callback2, $topic); $this->assertSubscriptions($topic, 2); // use second instance to make sure the database is used $storage->deleteById($id0); $this->assertSubscriptions($topic, 1); $storage->deleteById($id1); $this->assertSubscriptions($topic, 0); }