Пример #1
0
 public function test()
 {
     $xmlFile1 = file_get_contents("./files/registerNewUserRequest.xml");
     $p1 = simplexml_load_string($xmlFile1);
     //isValidReigsterNewUerRequest
     $this->assertTrue(XmlRequestValidator::isValidReigsterNewUerRequest($p1), "[isValidReigsterNewUerRequest]");
     unset($p1->body->email);
     $this->assertFalse(XmlRequestValidator::isValidReigsterNewUerRequest($p1), "[isValidReigsterNewUerRequest]");
     $p1 = simplexml_load_string($xmlFile1);
     $this->assertTrue(XmlRequestValidator::isValidReigsterNewUerRequest($p1), "[isValidReigsterNewUerRequest]");
     unset($p1->body->username);
     $this->assertFalse(XmlRequestValidator::isValidReigsterNewUerRequest($p1), "[isValidReigsterNewUerRequest]");
     $p1 = simplexml_load_string($xmlFile1);
     $this->assertTrue(XmlRequestValidator::isValidReigsterNewUerRequest($p1), "[isValidReigsterNewUerRequest]");
     unset($p1->body->password);
     $this->assertFalse(XmlRequestValidator::isValidReigsterNewUerRequest($p1), "[isValidReigsterNewUerRequest]");
     $p1 = simplexml_load_string($xmlFile1);
     $this->assertTrue(XmlRequestValidator::isValidReigsterNewUerRequest($p1), "[isValidReigsterNewUerRequest]");
     $p1->body->username = "";
     $this->assertFalse(XmlRequestValidator::isValidReigsterNewUerRequest($p1), "[isValidReigsterNewUerRequest]");
     $p1 = simplexml_load_string($xmlFile1);
     $this->assertTrue(XmlRequestValidator::isValidReigsterNewUerRequest($p1), "[isValidReigsterNewUerRequest]");
     $p1->body->password = "";
     $this->assertFalse(XmlRequestValidator::isValidReigsterNewUerRequest($p1), "[isValidReigsterNewUerRequest]");
     $p1 = simplexml_load_string($xmlFile1);
     $this->assertTrue(XmlRequestValidator::isValidReigsterNewUerRequest($p1), "[isValidReigsterNewUerRequest]");
     $p1->body->email = "";
     $this->assertFalse(XmlRequestValidator::isValidReigsterNewUerRequest($p1), "[isValidReigsterNewUerRequest]");
     //isValidNewSessionRequest($request)
     $xmlFile2 = file_get_contents("./files/newSessionRequest.xml");
     $p2 = simplexml_load_string($xmlFile2);
     $this->assertTrue(XmlRequestValidator::isValidNewSessionRequest($p2), "[isValidNewSessionRequest()]");
     unset($p2->body->username);
     $this->assertFalse(XmlRequestValidator::isValidNewSessionRequest($p2), "[isValidNewSessionRequest]");
     $p2 = simplexml_load_string($xmlFile2);
     $this->assertTrue(XmlRequestValidator::isValidNewSessionRequest($p2), "[isValidNewSessionRequest]");
     unset($p2->body->password);
     $this->assertFalse(XmlRequestValidator::isValidNewSessionRequest($p2), "[isValidNewSessionRequest]");
     $p2 = simplexml_load_string($xmlFile2);
     $this->assertTrue(XmlRequestValidator::isValidNewSessionRequest($p2), "[isValidNewSessionRequest]");
     $p2->body->username = "";
     $this->assertFalse(XmlRequestValidator::isValidNewSessionRequest($p2), "[isValidNewSessionRequest]");
     $p2 = simplexml_load_string($xmlFile2);
     $this->assertTrue(XmlRequestValidator::isValidNewSessionRequest($p2), "[isValidNewSessionRequest]");
     $p2->body->password = "";
     $this->assertFalse(XmlRequestValidator::isValidNewSessionRequest($p2), "[isValidNewSessionRequest]");
     $p2 = simplexml_load_string($xmlFile2);
     $this->assertTrue(XmlRequestValidator::isValidNewSessionRequest($p2), "[isValidNewSessionRequest]");
     unset($p2->body->gcm);
     $this->assertFalse(XmlRequestValidator::isValidNewSessionRequest($p2), "[isValidNewSessionRequest]");
     $p2 = simplexml_load_string($xmlFile2);
     $this->assertTrue(XmlRequestValidator::isValidNewSessionRequest($p2), "[isValidNewSessionRequest]");
     $p2->body->gcm = "";
     $this->assertFalse(XmlRequestValidator::isValidNewSessionRequest($p2), "[isValidNewSessionRequest]");
     //isValidEndSessionRequest($request)
     $xmlFile2 = file_get_contents("./files/endSessionRequest.xml");
     $p2 = simplexml_load_string($xmlFile2);
     $this->assertTrue(XmlRequestValidator::isValidEndSessionRequest($p2), "[isValidEndSessionRequest()]");
     unset($p2->body->session);
     $this->assertFalse(XmlRequestValidator::isValidEndSessionRequest($p2), "[isValidEndSessionRequest()]");
     //isValidregisterGCMRequest($request)
     $xmlFile2 = file_get_contents("./files/registerGCMRequest.xml");
     $p2 = simplexml_load_string($xmlFile2);
     $this->assertTrue(XmlRequestValidator::isValidregisterGCMRequest($p2), "[isValidregisterGCMRequest()]");
     unset($p2->body->session);
     $this->assertFalse(XmlRequestValidator::isValidregisterGCMRequest($p2), "[isValidregisterGCMRequest()]");
     $p2 = simplexml_load_string($xmlFile2);
     unset($p2->body->gcm);
     $this->assertFalse(XmlRequestValidator::isValidregisterGCMRequest($p2), "[isValidregisterGCMRequest()]");
     //isValidStartPendingGameRequest($request)
     $xmlFile2 = file_get_contents("./files/startPendingGameRequest.xml");
     $p2 = simplexml_load_string($xmlFile2);
     $this->assertTrue(XmlRequestValidator::isValidStartPendingGameRequest($p2), "[isValidStartPendingGameRequest()]");
     unset($p2->body->session);
     $this->assertFalse(XmlRequestValidator::isValidStartPendingGameRequest($p2), "[isValidStartPendingGameRequest()]");
     $p2 = simplexml_load_string($xmlFile2);
     unset($p2->body->size);
     $this->assertFalse(XmlRequestValidator::isValidStartPendingGameRequest($p2), "[isValidStartPendingGameRequest()]");
 }
Пример #2
0
 public function startNewGame()
 {
     if (XmlRequestValidator::isValidStartPendingGameRequest($this->requestData)) {
         $session = $this->requestData->body->session;
         $size = $this->requestData->body->size;
         if (safe_input::is_valid_session_hash($session) && safe_input::is_number($size) && $size > 1) {
             //chkec if the session hash exists
             $session_info = session::get_session_by_hash($session);
             if ($session_info != null) {
                 $res = Execute::newPendingGame($session, $size);
                 if ($res) {
                     $this->response = XmlBuilder::startNewPendingGameSuccessfullResponse("plain", $session);
                 } else {
                     //faild to add new game
                     Report::error(__METHOD__ . "," . __LINE__, "failed to add new pending game");
                     $this->response = XmlBuilder::failed_response("plain", 5, 0, "failed to add new pending game, try again");
                 }
             } else {
                 //the given hash doesn't exist in the database
                 Report::warning(__METHOD__ . "," . __LINE__, "start new pending game request contains a session hash that does not exist in the database: hash=" . $session);
                 $this->response = XmlBuilder::failed_response("plain", 5, 1, "expired session");
             }
         } else {
             //invalid data passed
             Report::error(__METHOD__ . "," . __LINE__, "start new pending game request contains an incorrectly formatted session hash or game size, size:" . $size);
             $this->response = XmlBuilder::failed_response("plain", 5, 0, "invalid session or gcm id");
         }
     } else {
         //xml request was not formatted correctly
         Report::error(__METHOD__ . "," . __LINE__, "invalid new pending game request!");
         $this->invalidRequest();
     }
 }