Example #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);
 }
Example #2
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);
 }
Example #3
0
 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);
 }