Ejemplo n.º 1
0
 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));
 }
Ejemplo n.º 2
0
 /**
  * @param string $topic
  * @param integer $count
  */
 private function assertSubscriptions($topic, $count)
 {
     // use second instance to make sure the database is used
     $storage2 = new \OCA\Web_Hooks\Subscriptions();
     $subscribers = $storage2->allByTopic($topic);
     $this->assertEquals($count, count($subscribers));
     return $subscribers;
 }