Esempio n. 1
0
 public function testExecute()
 {
     $this->container['API']->expects($this->once())->method('getUsers')->will($this->returnValue(array("admin", "herp", "derp")));
     // Simulation of the OC users
     $this->container['UserOnlineMapper'] = $this->getMockBuilder('\\OCA\\Chat\\OCH\\Db\\UserOnlineMapper')->disableOriginalConstructor()->getMock();
     $this->container['PushMessageMapper'] = $this->getMockBuilder('\\OCA\\Chat\\OCH\\Db\\PushMessageMapper')->disableOriginalConstructor()->getMock();
     $this->container['PushMessageMapper']->expects($this->any())->method('insert')->will($this->returnCallback(function ($pushMessage) {
         InviteTest::$pushMessage = $pushMessage;
     }));
     $this->container['UserMapper'] = $this->getMockBuilder('\\OCA\\Chat\\OCH\\Db\\UserMapper')->disableOriginalConstructor()->getMock();
     $this->container['UserMapper']->expects($this->any())->method('insertUnique')->will($this->returnValue(true));
     $this->container['UserOnlineMapper'] = $this->getMockBuilder('\\OCA\\Chat\\OCH\\Db\\UserOnlineMapper')->disableOriginalConstructor()->getMock();
     $userToInviteSession = new User();
     $userToInviteSession->setUser('foo');
     $userToInviteSession->setSessionId(md5(time()));
     $this->container['UserOnlineMapper']->expects($this->any())->method('findByUser')->will($this->returnValue(array($userToInviteSession)));
     $expectedPushMessage = new PushMessage();
     $expectedPushMessage->setSender('admin');
     $expectedPushMessage->setReceiver('foo');
     $expectedPushMessage->setReceiverSessionId(md5(time()));
     $expectedPushMessage->setCommand(json_encode(array('type' => 'invite', 'data' => array('user' => array('id' => 'admin', 'online' => false, 'displayname' => 'admin', 'backends' => array('och' => array('id' => NULL, 'displayname' => 'ownCloud Handle', 'protocol' => 'x-owncloud-handle', 'namespace' => 'och', 'value' => 'admin')), 'address_book_id' => 'admin', 'address_book_backend' => 'localusers'), 'conv_id' => 'addeimnpr', 'user_to_invite' => array('id' => 'derp', 'online' => false, 'displayname' => 'derp', 'backends' => array('och' => array('id' => NULL, 'displayname' => 'ownCloud Handle', 'protocol' => 'x-owncloud-handle', 'namespace' => 'och', 'value' => 'derp')), 'address_book_id' => 'admin', 'address_book_backend' => 'localusers')))));
     // logic
     $invite = new Invite($this->container);
     $invite->setRequestData(array('user' => array('id' => 'admin', 'online' => false, 'displayname' => 'admin', 'backends' => array('och' => array('id' => NULL, 'displayname' => 'ownCloud Handle', 'protocol' => 'x-owncloud-handle', 'namespace' => 'och', 'value' => 'admin')), 'address_book_id' => 'admin', 'address_book_backend' => 'localusers'), 'user_to_invite' => array('id' => 'derp', 'online' => false, 'displayname' => 'derp', 'backends' => array('och' => array('id' => NULL, 'displayname' => 'ownCloud Handle', 'protocol' => 'x-owncloud-handle', 'namespace' => 'och', 'value' => 'derp')), 'address_book_id' => 'admin', 'address_book_backend' => 'localusers'), 'session_id' => 'c08809598b01894c468873fab54291aa', 'timestamp' => 1397328934.658, 'conv_id' => 'addeimnpr'));
     $invite->execute();
     $this->assertEquals($expectedPushMessage, InviteTest::$pushMessage);
 }
Esempio n. 2
0
 public function execute()
 {
     foreach ($this->requestData['ids'] as $id) {
         $pushMessage = new PushMessage();
         $pushMessage->setId($id);
         $this->pushMessageMapper->delete($pushMessage);
     }
     return new JSONResponse(array('status' => 'success'));
 }
Esempio n. 3
0
 private function sendPushMessage($path)
 {
     $users = $this->userMapper->findSessionsByConversation($this->requestData['conv_id']);
     $command = json_encode(array('type' => 'file_removed', 'data' => array('user' => $this->requestData['user'], 'conv_id' => $this->requestData['conv_id'], 'timestamp' => $this->requestData['timestamp'], 'path' => $path)));
     foreach ($users as $receiver) {
         if ($receiver->getUser() !== $this->requestData['user']['id']) {
             $pushMessage = new PushMessage();
             $pushMessage->setSender($this->requestData['user']['id']);
             $pushMessage->setReceiver($receiver->getUser());
             $pushMessage->setReceiverSessionId($receiver->getSessionId());
             $pushMessage->setCommand($command);
             $this->pushMessageMapper->insert($pushMessage);
         }
     }
 }
Esempio n. 4
0
 public function createForAllSessions($sender, $command)
 {
     $sessions = $this->userOnlineMapper->getAll();
     foreach ($sessions as $session) {
         $pushMessage = new PushMessage();
         $pushMessage->setSender($sender);
         $pushMessage->setCommand($command);
         $pushMessage->setReceiver($session->getUser());
         $pushMessage->setReceiverSessionId($session->getSessionId());
         $this->insert($pushMessage);
     }
 }
Esempio n. 5
0
 public function pushMessageProvider()
 {
     $msgs = array();
     $senders = array('bar', 'foobar');
     $sessionId = md5(time() + rand(0, 1000));
     for ($i = 0; $i < 20; $i++) {
         $msg = new PushMessage();
         $rand = rand(0, 1);
         $msg->setSender($senders[$rand]);
         $msg->setReceiver('foo');
         if ($i > 10) {
             $msg->setReceiverSessionId($sessionId);
         } else {
             $msg->setReceiverSessionId(md5(time() + rand(0, 1000)));
         }
         $msg->setCommand('{"command": "true}');
         $msgs[] = $msg;
     }
     return array(array($msgs, $sessionId));
 }
Esempio n. 6
0
 private function sendOfflineMsg()
 {
     // first check if we're really offline
     $sessions = $this->userOnlineMapper->findByUser($this->requestData['user']['id']);
     if (count($sessions) === 0) {
         $command = json_encode(array('type' => 'offline', 'data' => array('user' => $this->requestData['user'], 'timestamp' => $this->requestData['timestamp'])));
         $users = $this->userOnlineMapper->getAll();
         $sender = $this->requestData['user']['id'];
         foreach ($users as $user) {
             if ($user->getUser() !== $sender) {
                 $pushMessage = new PushMessage();
                 $pushMessage->setSender($sender);
                 $pushMessage->setReceiver($user->getUser());
                 $pushMessage->setReceiverSessionId($user->getSessionId());
                 $pushMessage->setCommand($command);
                 $this->pushMessageMapper->insert($pushMessage);
             }
         }
     }
 }
Esempio n. 7
0
 public function testPushMessageInsertGroupConv()
 {
     $this->container['InitConvMapper'] = $this->getMockBuilder('\\OCA\\Chat\\OCH\\Db\\InitConvMapper')->disableOriginalConstructor()->getMock();
     $this->container['InitConvMapper']->expects($this->any())->method('insertUnique')->will($this->returnValue(true));
     $this->container['GetUsersData'] = $this->getMockBuilder('\\OCA\\Chat\\OCH\\Data\\GetUsers')->disableOriginalConstructor()->getMock();
     $this->container['GetUsersData']->expects($this->any())->method('execute')->will($this->returnValue(array("users" => array(0 => array('id' => 'derp', 'online' => false, 'displayname' => 'derp', 'backends' => array('och' => array('id' => NULL, 'displayname' => 'ownCloud Handle', 'protocol' => 'x-owncloud-handle', 'namespace' => 'och', 'value' => 'derp')), 'address_book_id' => 'admin', 'address_book_backend' => 'localusers'), 1 => array('id' => 'admin', 'online' => true, 'displayname' => 'admin', 'backends' => array('och' => array('id' => NULL, 'displayname' => 'ownCloud Handle', 'protocol' => 'x-owncloud-handle', 'namespace' => 'och', 'value' => 'admin')), 'address_book_id' => 'admin', 'address_book_backend' => 'localusers'), 2 => array('id' => 'foo', 'online' => true, 'displayname' => 'foo', 'backends' => array('och' => array('id' => NULL, 'displayname' => 'ownCloud Handle', 'protocol' => 'x-owncloud-handle', 'namespace' => 'och', 'value' => 'foo')), 'address_book_id' => 'admin', 'address_book_backend' => 'localusers')))));
     $this->container['MessagesData'] = $this->getMockBuilder('\\OCA\\Chat\\OCH\\Data\\Messages')->disableOriginalConstructor()->getMock();
     $this->container['MessagesData']->expects($this->any())->method('execute')->will($this->returnValue(array("messages" => array())));
     $this->container['UserMapper'] = $this->getMockBuilder('\\OCA\\Chat\\OCH\\Db\\UserMapper')->disableOriginalConstructor()->getMock();
     $derpSession = new User();
     $derpSession->setUser('derp');
     $derpSession->setSessionId('session-id-2');
     $adminSession = new User();
     $adminSession->setUser('admin');
     $adminSession->setSessionId('session-id-1');
     $this->container['UserMapper']->expects($this->any())->method('findSessionsByConversation')->will($this->returnValue(array($derpSession, $adminSession)));
     $this->container['PushMessageMapper'] = $this->getMockBuilder('\\OCA\\Chat\\OCH\\Db\\PushMessageMapper')->disableOriginalConstructor()->getMock();
     $this->container['PushMessageMapper']->expects($this->any())->method('insert')->will($this->returnCallback(function ($pushMessage) {
         JoinTest::$pushMessages[] = $pushMessage;
     }));
     $expectedInitConv = new InitConv();
     $expectedInitConv->setConvId('dasdfwffws');
     $expectedInitConv->setUser('admin');
     $join = new Join($this->container);
     $join->setRequestData(array("user" => array("id" => "admin", "displayname" => "admin", "backends" => array("och" => array("id" => NULL, "displayname" => "wnCloud Handle", "protocol" => "x-owncloud-handle", "namespace" => "och", "value" => "admin")), "address_book_id" => "admin", "address_book_backend" => "localusers"), "session_id" => "87ce2b3faeb92f0fb745645e7827f51a", "timestamp" => 1397193430.516, 'conv_id' => 'dasdfwffws'));
     $join->execute();
     $expectedPushMessage1 = new PushMessage();
     $expectedPushMessage1->setSender('admin');
     $expectedPushMessage1->setReceiver('derp');
     $expectedPushMessage1->setReceiverSessionId('session-id-2');
     $expectedPushMessage1->setCommand(json_encode(array("type" => "joined", "data" => array("conv_id" => 'dasdfwffws', "messages" => array(), "users" => array(0 => array('id' => 'derp', 'online' => false, 'displayname' => 'derp', 'backends' => array('och' => array('id' => NULL, 'displayname' => 'ownCloud Handle', 'protocol' => 'x-owncloud-handle', 'namespace' => 'och', 'value' => 'derp')), 'address_book_id' => 'admin', 'address_book_backend' => 'localusers'), 1 => array('id' => 'admin', 'online' => true, 'displayname' => 'admin', 'backends' => array('och' => array('id' => NULL, 'displayname' => 'ownCloud Handle', 'protocol' => 'x-owncloud-handle', 'namespace' => 'och', 'value' => 'admin')), 'address_book_id' => 'admin', 'address_book_backend' => 'localusers'), 2 => array('id' => 'foo', 'online' => true, 'displayname' => 'foo', 'backends' => array('och' => array('id' => NULL, 'displayname' => 'ownCloud Handle', 'protocol' => 'x-owncloud-handle', 'namespace' => 'och', 'value' => 'foo')), 'address_book_id' => 'admin', 'address_book_backend' => 'localusers'))))));
     $expectedPushMessage2 = new PushMessage();
     $expectedPushMessage2->setSender('admin');
     $expectedPushMessage2->setReceiver('admin');
     $expectedPushMessage2->setReceiverSessionId('session-id-1');
     $expectedPushMessage2->setCommand(json_encode(array("type" => "joined", "data" => array("conv_id" => 'dasdfwffws', "messages" => array(), "users" => array(0 => array('id' => 'derp', 'online' => false, 'displayname' => 'derp', 'backends' => array('och' => array('id' => NULL, 'displayname' => 'ownCloud Handle', 'protocol' => 'x-owncloud-handle', 'namespace' => 'och', 'value' => 'derp')), 'address_book_id' => 'admin', 'address_book_backend' => 'localusers'), 1 => array('id' => 'admin', 'online' => true, 'displayname' => 'admin', 'backends' => array('och' => array('id' => NULL, 'displayname' => 'ownCloud Handle', 'protocol' => 'x-owncloud-handle', 'namespace' => 'och', 'value' => 'admin')), 'address_book_id' => 'admin', 'address_book_backend' => 'localusers'), 2 => array('id' => 'foo', 'online' => true, 'displayname' => 'foo', 'backends' => array('och' => array('id' => NULL, 'displayname' => 'ownCloud Handle', 'protocol' => 'x-owncloud-handle', 'namespace' => 'och', 'value' => 'foo')), 'address_book_id' => 'admin', 'address_book_backend' => 'localusers'))))));
     $this->assertEquals(array($expectedPushMessage1, $expectedPushMessage2), JoinTest::$pushMessages);
 }