예제 #1
0
 public function testCreatedCommand()
 {
     $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) {
         SendChatMsgTest::$command = $pushMessage->getCommand();
         SendChatMsgTest::$pushMessageCount++;
     }));
     $user1 = new User();
     // This is a receiver
     $user1->setConversationId('addeimnpr');
     $user1->setUser('derp');
     $user1->setSessionId('c08809598b01894c4asdfasdf68873fab54291aa');
     $user2 = new User();
     // This is a sender but is also stored in the DB -> no need to create a pushmessage
     $user2->setConversationId('addeimnpr');
     $user2->setUser('admin');
     $user2->setSessionId('c08809598b01894c468873fab54291aa');
     $this->container['UserMapper'] = $this->getMockBuilder('\\OCA\\Chat\\OCH\\Db\\UserMapper')->disableOriginalConstructor()->getMock();
     $this->container['UserMapper']->expects($this->any())->method('findSessionsByConversation')->will($this->returnValue(array($user1, $user2)));
     $this->container['messageMapper'] = $this->getMockBuilder('\\OCA\\Chat\\OCH\\Db\\MessageMapper')->disableOriginalConstructor()->getMock();
     $sendChatMsg = new SendChatMsg($this->container);
     $sendChatMsg->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'), 'session_id' => 'c08809598b01894c468873fab54291aa', 'timestamp' => 1397328934.658, 'conv_id' => 'addeimnpr', 'chat_msg' => 'test'));
     $sendChatMsg->execute();
     $expectedCommand = json_encode(array('type' => 'send_chat_msg', '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', 'timestamp' => 1397328934.658, 'chat_msg' => 'test')));
     $this->assertEquals($expectedCommand, SendChatMsgTest::$command);
     $this->assertEquals(1, SendChatMsgTest::$pushMessageCount);
 }
예제 #2
0
파일: Invite.php 프로젝트: arun-TK/chat
 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);
 }
예제 #3
0
파일: join.php 프로젝트: arun-TK/chat
 public function execute()
 {
     // Add the user to the conversation
     $user = new User();
     $user->setConversationId($this->requestData['conv_id']);
     $user->setJoined(time());
     $user->setUser($this->requestData['user']['id']);
     $this->userMapper->insertUnique($user);
     $this->getUsers->setRequestData(array("conv_id" => $this->requestData['conv_id']));
     $users = $this->getUsers->execute();
     $users = $users['users'];
     if (count($users) > 2) {
         // we are in a group conv this mean we have to let the other users now we joined it
         $command = json_encode(array("type" => "joined", "data" => array("conv_id" => $this->requestData['conv_id'], "users" => $users)));
         $this->pushMessageMapper->createForAllUsersInConv($this->requestData['user']['id'], $this->requestData['conv_id'], $command);
     }
     $this->getUsers->setRequestData(array("conv_id" => $this->requestData['conv_id']));
     $users = $this->getUsers->execute();
     return $users;
 }
예제 #4
0
 public function messageProvider()
 {
     $msgs = array();
     $users = array('foo', 'bar', 'foobar');
     $convId = md5(time());
     for ($i = 0; $i < 20; $i++) {
         $msg = new Message();
         $rand = rand(0, 2);
         $msg->setUser($users[$rand]);
         $msg->setConvid($convId);
         $msg->setMessage('Test Message');
         $msg->setTimestamp($i);
         $msgs[] = $msg;
     }
     $user = new User();
     $user->setConversationId($convId);
     $user->setUser('foo');
     $user->setJoined(5);
     return array(array($msgs, $convId, $user));
 }
예제 #5
0
 public function existsByUserProvider()
 {
     $conv1Id = md5(time());
     $conv1 = new Conversation();
     $conv1->setConversationId($conv1Id);
     $user1InConv1 = new User();
     $user1InConv1->setConversationId($conv1Id);
     $user1InConv1->setUser('foo');
     $user1InConv1->setJoined(time() - 53353);
     $user2InConv1 = new User();
     $user2InConv1->setConversationId($conv1Id);
     $user2InConv1->setUser('bar');
     $user2InConv1->setJoined(time() - 53353);
     $conv2Id = md5(time() - 3434);
     $conv2 = new Conversation();
     $conv2->setConversationId($conv2Id);
     $user1InConv2 = new User();
     $user1InConv2->setConversationId($conv2Id);
     $user1InConv2->setUser('foo');
     $user1InConv2->setJoined(time() - 53353);
     $user2InConv2 = new User();
     $user2InConv2->setConversationId($conv2Id);
     $user2InConv2->setUser('bar');
     $user2InConv2->setJoined(time() - 53353);
     $user3InConv2 = new User();
     $user3InConv2->setConversationId($conv2Id);
     $user3InConv2->setUser('foobar');
     $user3InConv2->setJoined(time() - 53353);
     return array(array($conv1, $user1InConv1, $user2InConv1, $conv2, $user1InConv2, $user2InConv2, $user3InConv2));
 }
예제 #6
0
 public function insertUniqueProvider()
 {
     $user = new User();
     $user->setUser('foo');
     $user->setConversationId(md5(time() - 2342));
     $user->setJoined(234234234);
     return array(array($user));
 }
예제 #7
0
파일: Join.php 프로젝트: arun-TK/chat
 public function testInsertNoPushMessagesNoGroupConv()
 {
     $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')))));
     $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::$pushMessageNoGroup[] = $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();
     $this->assertEquals(null, JoinTest::$pushMessageNoGroup);
 }
예제 #8
0
 public function createForAllUsersInConvProvider()
 {
     $convId = md5(time() - 354235);
     $sessionId1 = md5(time() + rand(0, 1000));
     $sessionId2 = md5(time() + rand(0, 1000));
     $user1 = new User();
     $user1->setUser('foo');
     $user1->setConversationId($convId);
     $user1->setJoined(time() - 3434);
     $user2 = new User();
     $user2->setUser('bar');
     $user2->setConversationId($convId);
     $user2->setJoined(time() - 4345675);
     $session1 = new UserOnline();
     $session1->setSessionId($sessionId1);
     $session1->setUser('foo');
     $session1->setLastOnline(time() - 400);
     $session2 = new UserOnline();
     $session2->setSessionId($sessionId2);
     $session2->setUser('bar');
     $session2->setLastOnline(time() - 3435);
     return array(array(array($user1, $user2), array($session1, $session2), $convId));
 }