Ejemplo n.º 1
0
 public function test()
 {
     $username = "******";
     $password = "******";
     $email = "*****@*****.**";
     $username2 = "bla2";
     $password2 = "pass2";
     $email2 = "*****@*****.**";
     $username3 = "gue";
     $password3 = "pass3";
     $email3 = "*****@*****.**";
     user::create_new_user($username, $password, $email);
     $this->assertEquals(1, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     user::create_new_user($username2, $password2, $email2);
     $this->assertEquals(2, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     user::create_new_user($username3, $password3, $email3);
     $this->assertEquals(3, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     $user1ID = user::getUserByUsername($username)['id'];
     $user2ID = user::getUserByUsername($username2)['id'];
     $user3ID = user::getUserByUsername($username3)['id'];
     $uuid1 = "352584060201362";
     $this->assertTrue(safe_input::is_valid_uuid($uuid1), "safe_input::is_valid_uuid()");
     $ip1 = '196.168.2.16';
     $this->assertTrue(safe_input::is_valid_ip($ip1), "safe_input::is_valid_ip()");
     $this->assertEquals(0, log::get_logs_count(), "[get_logs_count()]");
     $this->assertTrue(log::addNewLog($user1ID, $ip1, $uuid1), "[log::addNewLog()]");
     $this->assertEquals(1, log::get_logs_count(), "[get_logs_count()]");
     $this->assertTrue(log::addNewLog($user1ID, $ip1, $uuid1), "[log::addNewLog()]");
     $this->assertEquals(2, log::get_logs_count(), "[get_logs_count()]");
     //$this->assertTrue(log::deleteSimilarLogs(),"[deleteSimilarLogs()]") ;
     //$this->assertEquals(1,log::get_logs_count(),"[get_logs_count()]") ;
 }
Ejemplo n.º 2
0
 public function test()
 {
     $username = "******";
     $password = "******";
     $email = "*****@*****.**";
     $username2 = "bla2";
     $password2 = "pass2";
     $email2 = "*****@*****.**";
     user::create_new_user($username, $password, $email);
     $this->assertEquals(1, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     user::create_new_user($username2, $password2, $email2);
     $this->assertEquals(2, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     $user1ID = user::getUserByUsername($username)['id'];
     $user2ID = user::getUserByUsername($username2)['id'];
     $game_size = 6;
     $this->assertTrue(game::add_new_game($user1ID, $game_size, $user1ID, $user2ID), "failed to add a new game");
     $game_id1 = game::$last_inserted_id;
     $this->assertTrue(game::add_new_game($user2ID, $game_size, $user2ID, $user1ID), "failed to add a new game");
     $game_id2 = game::$last_inserted_id;
     //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
     //message::get_all_messages_for_game_id($game_id)
     //message::add_new_message($game_id,$user_id,$message)
     $message = "helllo";
     $this->assertNull(message::get_all_messages_for_game_id($game_id1), "null should be returned because no messages added for the given game_id [get_all_messages_for_game_id()]");
     $this->assertNull(message::get_all_messages_for_game_id("rr"), "null should be returned because an invalid game_id was passed [get_all_messages_for_game_id()]");
     $this->assertFalse(message::add_new_message("hhh", $user1ID, $message), "false should be reutnred because an invalid game_id was passed [add_new_message()]");
     $this->assertFalse(message::add_new_message($game_id1, "blla", $message), "false should be reutnred because an invalid user_id was passed [add_new_message()]");
     $this->assertTrue(message::add_new_message($game_id1, $user1ID, $message), "falied to add new message [add_new_message()]");
     $this->assertEquals(1, count(message::get_all_messages_for_game_id($game_id1)), "expecting to get an array with one message [get_all_messages_for_game_id()]");
     $messages = message::get_all_messages_for_game_id($game_id1);
     $this->assertEquals($message, $messages[0]['message_text'], "[add_new_message()]");
     $this->assertEquals($game_id1, $messages[0]['gameID'], "[add_new_message()]");
     $this->assertEquals($user1ID, $messages[0]['userID'], "[add_new_message()]");
     $this->assertTrue(message::add_new_message($game_id2, $user1ID, "yolooo"), "falied to add new message [add_new_message()]");
     $message2 = "where are you";
     $this->assertTrue(message::add_new_message($game_id1, $user2ID, $message2), "falied to add new message [add_new_message()]");
     $this->assertEquals(2, count(message::get_all_messages_for_game_id($game_id1)), "expecting to get an array with two messages [get_all_messages_for_game_id()]");
     //message::get_message_count($game_id)
     $this->assertEquals(2, message::get_message_count($game_id1), "[message::get_message_count()]");
     $this->assertEquals(-1, message::get_message_count("asdasdasd"), "providing an invalid game_id so it should be rejected[message::get_message_count()]");
     message::clear_table();
     $this->assertEquals(0, message::get_message_count($game_id1), "[message::get_message_count()]");
     $this->assertTrue(message::add_new_message($game_id1, $user1ID, $message), "falied to add new message [add_new_message()]");
     $this->assertTrue(message::add_new_message($game_id1, $user2ID, $message2), "falied to add new message [add_new_message()]");
     $this->assertTrue(message::add_new_message($game_id2, $user1ID, "yolooo"), "falied to add new message [add_new_message()]");
     $this->assertEquals(1, message::get_message_count($game_id2), "[message::get_message_count()]");
     $messages = message::get_all_messages_for_game_id($game_id1);
     //message::get_all_messages_after_given_date($game_id,$date)
     $this->assertNull(message::get_all_messages_after_given_date(0, 0), "get_all_messages_after_given_date()");
     $this->assertNull(message::get_all_messages_after_given_date($messages[1]['gameID'], $messages[1]['date']), "get_all_messages_after_given_date()");
     $this->assertEquals(1, count(message::get_all_messages_after_given_date($messages[0]['gameID'], $messages[0]['date'])), "get_all_messages_after_given_date()");
     $this->assertEquals(2, count(message::get_all_messages_after_given_date($messages[0]['gameID'], $messages[0]['date'] - 0.1)), "get_all_messages_after_given_date()");
     //message::delete_message($message_id)
     $this->assertFalse(message::delete_message("dddd"), "[delete_message()]");
     $this->assertTrue(message::delete_message($messages[0]['id']), "[delete_message()]");
     $this->assertEquals(1, count(message::get_all_messages_after_given_date($messages[0]['gameID'], $messages[0]['date'] - 0.1)), "get_all_messages_after_given_date()");
     //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
 }
Ejemplo n.º 3
0
 public function test()
 {
     $username = "******";
     $password = "******";
     $email = "*****@*****.**";
     user::create_new_user($username, $password, $email);
     $this->assertEquals(1, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     $r = user::getUserByUsername($username);
     $this->assertEquals($username, $r['username'], "username was not saved correctly");
     $this->assertEquals($email, $r['email'], "email is not saved correctly");
     $this->assertEquals(md5(md5($password) . md5($r['salt'])), $r['password'], "password not correct");
     user::clear_table();
     $this->assertEquals(0, user::getNumberOfUsers());
     $this->assertFalse(user::doesUsernameExist($username), "doesUsernameExist() in user is broken");
     user::create_new_user($username, $password, $email);
     $this->assertTrue(user::doesUsernameExist($username), "doesUsernameExist() in user is broken");
     $this->assertFalse(user::doesEmailExist($email . "bla"), "doesEmailExist() in user is broken");
     $this->assertTrue(user::doesEmailExist($email), "doesEmailExist() in user is broken");
     $newPassword = "******";
     user::resetPassword($username, $newPassword);
     $r = user::getUserByUsername($username);
     $this->assertEquals(md5(md5($newPassword) . md5($r['salt'])), $r['password'], "restting password is broken");
     $newEmail = "*****@*****.**";
     user::setEmail($username, $newEmail);
     $r = user::getUserByUsername($username);
     $this->assertEquals($newEmail, $r['email'], "setEmail is broken");
     user::deleteUserByUsername($username);
     $this->assertFalse(user::doesUsernameExist($username), "deleteUserByUsername() in user is broken");
     user::create_new_user($username, $password, $email);
     $this->assertTrue(user::isLogin($username, $password), "isLogin is broken");
     $this->assertFalse(user::isLogin($username, $password . "d"), "isLogin is broken");
     $this->assertFalse(user::isLogin($username . "d", $password), "isLogin is broken");
     $user_info = user::getUserByUsername($username);
     $user_info2 = user::getUserById($user_info['id']);
     $this->assertEquals($user_info['username'], $user_info2['username'], "mismatched usernames when getting user by ID");
     $gcm_id1 = "APA91bFpUo1z8PfiyCZG7HzThDyJ0MIg86BB1kj0A-ZGASK_iJ-RTu8pUB4t_5jMgwqkolWCahT4QOOAnp9nNdCox7pd9vlJao1-ncYHqvlS89lOpjdoci2_3XXGxcIWgrWwTz1tC8OlURokekQdbDCGKWuqfzfXLKrhisGxJYpF1ivuItZtJns";
     $this->assertTrue(safe_input::is_valid_gcm_id($gcm_id1), "[is_valid_gcm_id()]");
     //user::setGCM($user_id,$gcm_id)
     $this->assertTrue(user::setGCM($user_info['id'], $gcm_id1), "[user::setGCM()]");
     $user_info = user::getUserByUsername($username);
     $this->assertEquals($gcm_id1, $user_info['gcmID'], "setGCM()");
     $gcm_id2 = "APA91bHGJbxPpIUNirvnCQib7kojM12Qu2MBBd9dGHXSu0hsfB_Al2rQ4E8UWgpMXhNVIGT6IlSjLE-MB2F0RrBeN_llEYzPErIQoewxnDeON6uqBIHkLcMIY2NQtQHX3TNYBrlNc74wmh7aYec9kLMp5QGogVYSao1Q-RtIx4QV140YHBBASXM";
     $this->assertTrue(user::setGCM($user_info2['id'], $gcm_id2), "[user::setGCM()]");
     $user_info2 = user::getUserById($user_info['id']);
     $this->assertEquals($gcm_id2, $user_info2['gcmID'], "setGCM()");
 }
Ejemplo n.º 4
0
 public function test()
 {
     $username = "******";
     $password = "******";
     $email = "*****@*****.**";
     $username2 = "bla2";
     $password2 = "pass2";
     $email2 = "*****@*****.**";
     user::create_new_user($username, $password, $email);
     $this->assertEquals(1, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     user::create_new_user($username2, $password2, $email2);
     $this->assertEquals(2, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     $user1ID = user::getUserByUsername($username)['id'];
     $user2ID = user::getUserByUsername($username2)['id'];
     $gmae_size = 6;
     $this->assertFalse(game::add_new_game($user1ID, "z", $user1ID, $user2ID), "invalid size went through OK!");
     $this->assertFalse(game::add_new_game("s", $gmae_size, $user1ID, $user2ID), "invalid curent player id went through OK!");
     $this->assertFalse(game::add_new_game($user1ID, $gmae_size, "x", $user2ID), "invalid player 1 id went through OK!");
     $this->assertFalse(game::add_new_game($user1ID, $gmae_size, $user1ID, "d"), "invalid player 2 id went through OK!");
     $this->assertFalse(game::add_new_game(20, $gmae_size, $user1ID, $user2ID), "current turn id was different from p1 and p2 and it when through!");
     $this->assertTrue(game::add_new_game($user1ID, $gmae_size, $user1ID, $user2ID), "failed to add a new game");
     $this->assertEquals($gmae_size, game::getGameById(1)['size'], "incorrect game size");
     $this->assertEquals($user1ID, game::getGameById(1)['player1ID'], "incorrect player 1 id ");
     $this->assertEquals($user2ID, game::getGameById(1)['player2ID'], "incorrect player 2 id ");
     $this->assertNull(game::getGameById(1)['winnerID'], "winnder ID should be null");
     $this->assertNull(game::getGameById(1)['lastActivityDate'], "lastActivityDate should be null");
     $this->assertEquals(1, game::getNumberOfGames(), "number of games should be equal to 1");
     game::clear_table();
     $this->assertEquals(0, game::getNumberOfGames(), "number of games should be equal to 0");
     game::add_new_game($user1ID, $gmae_size, $user1ID, $user2ID);
     $game_id = game::$last_inserted_id;
     $this->assertTrue(game::setLastActivityDate($game_id), "setLastActivityDate is not working");
     $this->assertEquals(time() / 60 % 60, game::getGameById($game_id)['lastActivityDate'] / 60 % 60);
     game::clear_table();
     //security test: passing a user id that is not a number
     $this->assertEquals(-1, game::getNumberOfGamesForUserId("ff"), "getNumberOfGamesForUserId() should accept only numbers");
     //the user shouldn't have any games
     $this->assertEquals(0, game::getNumberOfGamesForUserId($user2ID), "The player shouldn't have any games [getNumberOfGamesForUserId()]");
     game::add_new_game($user1ID, $gmae_size, $user1ID, $user2ID);
     $game_id1 = game::$last_inserted_id;
     $this->assertEquals(1, game::getNumberOfGamesForUserId($user1ID), "player should have 1 game [getNumberOfGamesForUserId()]");
     $username3 = "bla3";
     $password3 = "pass3";
     $email3 = "*****@*****.**";
     user::create_new_user($username3, $password3, $email3);
     $user3ID = user::getUserByUsername($username3)['id'];
     $this->assertEquals(3, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     $this->assertTrue(game::add_new_game($user3ID, $gmae_size, $user3ID, $user1ID), "failed to add a new game");
     $game_id2 = game::$last_inserted_id;
     $this->assertEquals(2, game::getNumberOfGames(), "number of games should be equal to 2");
     $this->assertEquals(2, game::getNumberOfGamesForUserId($user1ID), "player should have two games [getNumberOfGamesForUserId()]");
     $this->assertEquals(1, game::getNumberOfGamesForUserId($user2ID), "player should have one game [getNumberOfGamesForUserId()]");
     $this->assertEquals(1, game::getNumberOfGamesForUserId($user3ID), "player should have one game [getNumberOfGamesForUserId()]");
     $this->assertEquals(2, count(game::getAllGamesForUserId($user1ID)), "two games should be returned [game::getAllGamesForUserId()]");
     $this->assertEquals($user1ID, game::getAllGamesForUserId($user1ID)[0]['player1ID'], "[game::getAllGamesForUserId()]");
     $this->assertEquals($user1ID, game::getAllGamesForUserId($user1ID)[1]['player2ID'], "[game::getAllGamesForUserId()]");
     $this->assertNull(game::getAllGamesForUserId(88), "should return null because player doesn't have games [game::getAllGamesForUserId()]");
     $this->assertNull(game::getOpponentId(1000, 1000), "[game::getOpponentId]");
     $this->assertNull(game::getOpponentId(1000, 1000), "[game::getOpponentId]");
     $this->assertNull(game::getOpponentId($game_id1, 1000), "[game::getOpponentId]");
     $this->assertNull(game::getOpponentId(1000, $user1ID), "[game::getOpponentId]");
     $this->assertEquals($user2ID, game::getOpponentId($game_id1, $user1ID), "[game::getOpponentId]");
     $this->assertEquals($user1ID, game::getOpponentId($game_id1, $user2ID), "[game::getOpponentId]");
     $this->assertEquals($user1ID, game::getOpponentId($game_id2, $user3ID), "[game::getOpponentId]");
     $this->assertEquals($user3ID, game::getOpponentId($game_id2, $user1ID), "[game::getOpponentId]");
     $this->assertNull(game::getOpponentId($game_id2, $user2ID), "[game::getOpponentId]");
 }
Ejemplo n.º 5
0
 public function test()
 {
     $username = "******";
     $password = "******";
     $email = "*****@*****.**";
     $username2 = "bla2";
     $password2 = "pass2";
     $email2 = "*****@*****.**";
     $username3 = "gue";
     $password3 = "pass3";
     $email3 = "*****@*****.**";
     user::create_new_user($username, $password, $email);
     $this->assertEquals(1, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     user::create_new_user($username2, $password2, $email2);
     $this->assertEquals(2, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     user::create_new_user($username3, $password3, $email3);
     $this->assertEquals(3, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     $user1ID = user::getUserByUsername($username)['id'];
     $user2ID = user::getUserByUsername($username2)['id'];
     $user3ID = user::getUserByUsername($username3)['id'];
     $this->assertTrue(safe_input::is_valid_session_hash(md5("\$3dfsd43^^%")), "safe_input::is_valid_session_hash()");
     $this->assertFalse(safe_input::is_valid_session_hash("x = 2 "), "safe_input::is_valid_session_hash()");
     //get_last_session_for_user_id($user_id)
     //add_new_session($user_id,$hash,$encryption_key)
     $this->assertFalse(session::add_new_session("hh", md5("bla"), md5("bla2")), "[add_new_session()]");
     $this->assertTrue(session::add_new_session($user1ID, md5("bla"), md5("bla2")), "failed to add new session[add_new_session()]");
     $s1 = session::$last_inserted_id;
     $this->assertFalse(session::is_unique_hash(md5("bla")), "[session::is_unique_hash()]");
     $this->assertTrue(session::is_unique_hash(md5("bddla")), "[session::is_unique_hash()]");
     //$this->assertNull(session::add_new_session($user2ID,md5("bla"),md5("mmm")),"Hash has to be unique! [add_new_session()]") ;
     $this->assertTrue(session::add_new_session($user2ID, md5("hash2"), md5("bla2")), "failed to add new session[add_new_session()]");
     $this->assertTrue(session::add_new_session($user1ID, md5("hash2sss"), md5("blssssa2")), "failed to add new session[add_new_session()]");
     $s2 = session::$last_inserted_id;
     $s_info = session::get_last_session_for_user_id($user1ID);
     $this->assertEquals($s_info['encryptionKey'], md5("blssssa2"), "[get_last_session_for_user_id()]");
     $this->assertFalse(session::is_unique_hash($s_info['hash']), "[is_unique_hash()]");
     $this->assertTrue(session::is_unique_hash(md5("asdfasefds")), "[is_unique_hash()]");
     $this->assertTrue(session::does_user_have_session($user2ID), "[does_user_have_session()]");
     $this->assertFalse(session::does_user_have_session($user3ID), "[does_user_have_session()]");
     //delete_all_sessions_for_user_id($user_id)
     $this->assertFalse(session::delete_all_sessions_for_user_id("sadsadsad"), "[delete_all_sessions_for_user_id()]");
     $this->assertTrue(session::delete_all_sessions_for_user_id($user2ID), "[delete_all_sessions_for_user_id()]");
     $this->assertFalse(session::does_user_have_session($user2ID), "[does_user_have_session()]");
     $this->assertTrue(session::does_user_have_session($user1ID), "[does_user_have_session()]");
     //session::delete_session_by_id($session_id)
     $s_info = session::get_last_session_for_user_id($user1ID);
     $this->assertTrue(session::add_new_session($user2ID, md5("hash2"), md5("bla2")), "failed to add new session[add_new_session()]");
     $s2_info = session::get_last_session_for_user_id($user2ID);
     $this->assertTrue(session::delete_session_by_id($s2_info['id']), "[delete_session_by_id()]");
     $this->assertFalse(session::does_user_have_session($user2ID), "[does_user_have_session()]");
     $this->assertTrue(session::does_user_have_session($user1ID), "[does_user_have_session()]");
     //session::delete_session_by_hash($hash)
     $s_info = session::get_last_session_for_user_id($user1ID);
     $this->assertTrue(session::add_new_session($user2ID, md5("hash2"), md5("bla2")), "failed to add new session[add_new_session()]");
     $s2_info = session::get_last_session_for_user_id($user2ID);
     $this->assertTrue(session::delete_session_by_hash($s2_info['hash']), "[delete_session_by_id()]");
     $this->assertFalse(session::does_user_have_session($user2ID), "[does_user_have_session()]");
     $this->assertTrue(session::does_user_have_session($user1ID), "[does_user_have_session()]");
     //session::get_session_by_hash($hash)
     $s_infos = session::get_session_by_hash($s_info['hash']);
     $this->assertEquals($s_info['id'], $s_infos['id'], "session::get_session_by_hash()");
 }
Ejemplo n.º 6
0
 public function testNewGameRequest()
 {
     //startNewGame()
     $username = "******";
     $password = "******";
     $email = "*****@*****.**";
     $username2 = "sandy";
     $password2 = "booha";
     $email2 = "*****@*****.**";
     user::create_new_user($username, $password, $email);
     user::create_new_user($username2, $password2, $email2);
     $user_info = user::getUserByUsername($username);
     $user_info2 = user::getUserByUsername($username2);
     $session = md5("dfgfds4543");
     $session2 = md5("rtyertyerty");
     $this->assertTrue(session::add_new_session($user_info['id'], $session, "0"));
     $this->assertTrue(session::add_new_session($user_info2['id'], $session2, "0"));
     $xmlFile = file_get_contents("./files/newPendingGameRequest.xml");
     $p = simplexml_load_string($xmlFile);
     $p->body->session = $session;
     $p->body->size = 6;
     $req = $p->asXML();
     $obj = new XmlParseRequest();
     $obj->processRequest($req);
     $response = $obj->getResponse();
     $pr = simplexml_load_string($response);
     $this->assertEquals("successful", $pr->body->status, "[new pending game]");
     $this->assertEquals("5", $pr->body->id, "[new pending game]");
     $this->assertEquals($session, $pr->body->session, "[new pending game]");
     $games = pending_game::get_all_pending_games_for_user_id($user_info['id']);
     $this->assertEquals(1, count($games), "[new pending game]");
     $this->assertEquals(6, $games[0]['size'], "[new pending game]");
     //send an invalid session hash
     $p->body->session = md5("invalid_session");
     $req = $p->asXML();
     $obj = new XmlParseRequest();
     $obj->processRequest($req);
     $response = $obj->getResponse();
     $pr = simplexml_load_string($response);
     $this->assertEquals("failed", $pr->body->status, "[new pending game]");
     $this->assertEquals("1", $pr->body->error_code, "error code is not correct (invalid session hash passed)[new pending game]");
     // add a second pending game fo the same user and check that the system dodn't match the games since they belong to the same user!
     $p->body->session = $session;
     $req = $p->asXML();
     $obj = new XmlParseRequest();
     $obj->processRequest($req);
     $response = $obj->getResponse();
     $pr = simplexml_load_string($response);
     $this->assertEquals("successful", $pr->body->status, "[new pending game]");
     $p->body->session = $session;
     $req = $p->asXML();
     $obj = new XmlParseRequest();
     $obj->processRequest($req);
     $response = $obj->getResponse();
     $pr = simplexml_load_string($response);
     $this->assertEquals("successful", $pr->body->status, "[new pending game]");
     $obj->processRequest($req);
     $response = $obj->getResponse();
     $pr = simplexml_load_string($response);
     $this->assertEquals("successful", $pr->body->status, "[new pending game]");
     $this->AssertEquals(0, game::getNumberOfGames(), "one pending games with the same size added[new pending game]");
     $p->body->session = $session2;
     $req = $p->asXML();
     $obj = new XmlParseRequest();
     $obj->processRequest($req);
     $response = $obj->getResponse();
     $pr = simplexml_load_string($response);
     $this->assertEquals("successful", $pr->body->status, "[new pending game]");
     $this->assertEquals("5", $pr->body->id, "[new pending game]");
     $this->assertEquals($session2, $pr->body->session, "[new pending game]");
     $this->AssertEquals(1, game::getNumberOfGames(), "two pending games with the same size added[new pending game]");
     $obj->processRequest($req);
     $response = $obj->getResponse();
     $pr = simplexml_load_string($response);
     $this->assertEquals("successful", $pr->body->status, "[new pending game]");
     $this->assertEquals("5", $pr->body->id, "[new pending game]");
     $this->assertEquals($session2, $pr->body->session, "[new pending game]");
     $this->AssertEquals(2, game::getNumberOfGames(), "two pending games with the same size added[new pending game]");
 }
Ejemplo n.º 7
0
 public function test()
 {
     $username = "******";
     $password = "******";
     $email = "*****@*****.**";
     $username2 = "bla2";
     $password2 = "pass2";
     $email2 = "*****@*****.**";
     user::create_new_user($username, $password, $email);
     $this->assertEquals(1, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     user::create_new_user($username2, $password2, $email2);
     $this->assertEquals(2, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     $user1ID = user::getUserByUsername($username)['id'];
     $user2ID = user::getUserByUsername($username2)['id'];
     $game_size = 6;
     $this->assertTrue(game::add_new_game($user1ID, $game_size, $user1ID, $user2ID), "failed to add a new game");
     $game_id1 = game::$last_inserted_id;
     $this->assertFalse(move::add_new_move(100, 1, 1, 1, $user1ID), "accepted invalid game_id [move::add_new_move]");
     $this->assertFalse(move::add_new_move($game_id1, -1, 1, 1, $user1ID), "accepted invalid x coordinate [move::add_new_move]");
     $this->assertFalse(move::add_new_move($game_id1, 1, -5, 1, $user1ID), "accepted invalid y coordinate [move::add_new_move]");
     $this->assertFalse(move::add_new_move($game_id1, 8, 1, 1, $user1ID), "accepted invalid x coordinate (larger than the size) [move::add_new_move]");
     $this->assertFalse(move::add_new_move($game_id1, 1, 8, 1, $user1ID), "accepted invalid y coordinate (larger than the size) [move::add_new_move]");
     $this->assertFalse(move::add_new_move($game_id1, 1, 1, 5, $user1ID), "accepted invalid edge position  [move::add_new_move]");
     $this->assertFalse(move::add_new_move($game_id1, 1, 1, 2, 90), "accepted invalid playerID (ID doesn't even exist)  [move::add_new_move]");
     $this->assertFalse(move::add_new_move($game_id1, 1, 1, 2, $user2ID), "accepted invalid playerID (not the player turn)  [move::add_new_move]");
     $game_info = game::getGameById($game_id1);
     $this->assertNull($game_info['lastActivityDate'], "when move fails the transaction is not rolledback![move::add_new_move]");
     $this->assertTrue(move::add_new_move($game_id1, 1, 1, 1, $user1ID), "failed to add new move");
     $game_info = game::getGameById($game_id1);
     $this->assertTrue($game_info['currentTurnPlayerID'] == $user2ID, "when adding a new move, method failed to change the player's turn");
     //get_last_move_for_game_id($game_id)
     $move = move::get_last_move_for_game_id($game_id1);
     $this->assertEquals($game_id1, $move['gameID'], "inccorect last move [get_last_move_for_game_id()]");
     $this->assertEquals(1, $move['x'], "inccorect last move [get_last_move_for_game_id()]");
     $this->assertEquals(1, $move['y'], "inccorect last move [get_last_move_for_game_id()]");
     $this->assertEquals(1, $move['edgePosition'], "inccorect last move [get_last_move_for_game_id()]");
     $this->assertEquals($user1ID, $move['playerID'], "inccorect last move [get_last_move_for_game_id()]");
     $this->assertEquals($game_info['lastActivityDate'], $move['date'], "the last activity date in the game table is not consistent with the move table! [move::add_new_move]");
     $this->assertTrue(move::add_new_move($game_id1, 2, 3, 4, $user2ID), "failed to add new move");
     $move2 = move::get_last_move_for_game_id($game_id1);
     $this->assertEquals($user2ID, $move2['playerID'], "inccorect last move [get_last_move_for_game_id()]");
     $this->assertEquals(2, $move2['x'], "inccorect last move [get_last_move_for_game_id()]");
     $this->assertEquals(3, $move2['y'], "inccorect last move [get_last_move_for_game_id()]");
     $this->assertEquals(4, $move2['edgePosition'], "inccorect last move [get_last_move_for_game_id()]");
     move::add_new_move($game_id1, 2, 1, 4, $user1ID);
     move::add_new_move($game_id1, 2, 2, 4, $user2ID);
     $move3 = move::get_last_move_for_game_id($game_id1);
     $this->assertEquals($user2ID, $move3['playerID'], "inccorect last move [get_last_move_for_game_id()]");
     $this->assertEquals(2, $move3['y'], "inccorect last move [get_last_move_for_game_id()]");
     move::clear_table();
     $this->assertFalse(move::get_last_move_for_game_id($game_id1), "inccorect last move [get_last_move_for_game_id()]");
     //count_moves($game_id)
     $this->assertEquals(0, move::count_moves($game_id1), "number of moves should be ZERO [count_moves()]");
     $this->assertTrue(move::add_new_move($game_id1, 2, 3, 4, $user1ID), "failed to add new move");
     $this->assertEquals(1, move::count_moves($game_id1), "number of moves should be ONE [count_moves()]");
     //get_all_moves_after_given_date($game_id,$timestamp)
     $move4 = move::get_last_move_for_game_id($game_id1);
     $this->assertNull(move::get_all_moves_after_given_date($game_id1, $move4['date']), "[move::get_all_moves_after_given_date()]");
     $this->assertTrue(move::add_new_move($game_id1, 4, 3, 1, $user2ID), "failed to add new move");
     $this->assertEquals(2, move::count_moves($game_id1), "number of moves should be two [count_moves()]");
     $move5 = move::get_all_moves_after_given_date($game_id1, $move4['date']);
     $this->assertEquals(1, count($move5), "number of moves returned should be one [move::get_all_moves_after_given_date()]");
     $this->assertEquals($game_id1, $move5[0]['gameID'], "[move::get_all_moves_after_given_date()]");
     $this->assertTrue(move::add_new_move($game_id1, 5, 5, 2, $user1ID), "failed to add new move");
     $this->assertEquals(2, count(move::get_all_moves_after_given_date($game_id1, $move4['date'])), "number of moves returned should be two [move::get_all_moves_after_given_date()]");
     //move::delete_move($move_id)
     $move_id = $move5[0]['gameID'];
     move::delete_move($move_id);
     $this->assertEquals(1, count(move::get_all_moves_after_given_date($game_id1, $move5[0]['date'])), "[move::delet_move()]");
     //move::get_all_moves_for_game_id($game_id)
     $this->assertEquals(move::count_moves($game_id1), count(move::get_all_moves_for_game_id($game_id1)), "[move::get_all_moves_for_game_id()]");
     $this->assertNull(move::get_all_moves_for_game_id("bla"), "[move::get_all_moves_for_game_id()]");
     $this->assertNull(move::get_all_moves_for_game_id("0"), "[move::get_all_moves_for_game_id()]");
 }
Ejemplo n.º 8
0
 public function test()
 {
     $username = "******";
     $password = "******";
     $email = "*****@*****.**";
     $username2 = "bla2";
     $password2 = "pass2";
     $email2 = "*****@*****.**";
     $username3 = "gue";
     $password3 = "pass3";
     $email3 = "*****@*****.**";
     user::create_new_user($username, $password, $email);
     $this->assertEquals(1, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     user::create_new_user($username2, $password2, $email2);
     $this->assertEquals(2, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     user::create_new_user($username3, $password3, $email3);
     $this->assertEquals(3, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     $user1ID = user::getUserByUsername($username)['id'];
     $user2ID = user::getUserByUsername($username2)['id'];
     $user3ID = user::getUserByUsername($username3)['id'];
     //GameControl::matchPendingGames() ;
     $this->assertTrue(pending_game::add_new_pending_game($user1ID, 3), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $g1_id = pending_game::$last_inserted_id;
     $this->assertTrue(pending_game::add_new_pending_game($user2ID, 4), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $g2_id = pending_game::$last_inserted_id;
     $this->assertTrue(pending_game::add_new_pending_game($user1ID, 4), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $g3_id = pending_game::$last_inserted_id;
     $this->assertEquals(0, game::getNumberOfGames(), "[pending_game::mathc()]");
     $this->assertEquals(2, pending_game::get_count_pending_by_size(4), "[pending_game::mathc()]");
     GameControl::matchPendingGames();
     $this->assertEquals(1, game::getNumberOfGames(), "[pending_game::mathc()]");
     $this->assertEquals(1, pending_game::get_count_pending_by_size(3), "[pending_game::mathc()]");
     $this->assertEquals(0, pending_game::get_count_pending_by_size(4), "[pending_game::mathc()]");
     $this->assertTrue(pending_game::add_new_pending_game($user2ID, 4), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $g4_id = pending_game::$last_inserted_id;
     $this->assertTrue(pending_game::add_new_pending_game($user1ID, 4), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $g5_id = pending_game::$last_inserted_id;
     $this->assertTrue(pending_game::add_new_pending_game($user2ID, 4), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $g6_id = pending_game::$last_inserted_id;
     $this->assertTrue(pending_game::add_new_pending_game($user1ID, 4), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $g7_id = pending_game::$last_inserted_id;
     $this->assertEquals(4, pending_game::get_count_pending_by_size(4), "[pending_game::mathc()]");
     GameControl::matchPendingGames();
     $this->assertEquals(0, pending_game::get_count_pending_by_size(4), "[pending_game::mathc()]");
     $this->assertEquals(3, game::getNumberOfGames(), "[pending_game::mathc()]");
     $this->assertTrue(pending_game::add_new_pending_game($user2ID, 4), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $g8_id = pending_game::$last_inserted_id;
     $this->assertTrue(pending_game::add_new_pending_game($user1ID, 4), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $g9_id = pending_game::$last_inserted_id;
     $this->assertTrue(pending_game::add_new_pending_game($user2ID, 4), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $g10_id = pending_game::$last_inserted_id;
     $this->assertTrue(pending_game::add_new_pending_game($user1ID, 4), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $g11_id = pending_game::$last_inserted_id;
     $this->assertTrue(pending_game::add_new_pending_game($user2ID, 5), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $g12_id = pending_game::$last_inserted_id;
     $this->assertTrue(pending_game::add_new_pending_game($user1ID, 5), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $g13_id = pending_game::$last_inserted_id;
     $this->assertTrue(pending_game::add_new_pending_game($user2ID, 7), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $g14_id = pending_game::$last_inserted_id;
     $this->assertTrue(pending_game::add_new_pending_game($user1ID, 7), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $g15_id = pending_game::$last_inserted_id;
     $this->assertEquals(3, game::getNumberOfGames(), "[pending_game::mathc()]");
     GameControl::matchPendingGames();
     $this->assertEquals(7, game::getNumberOfGames(), "[pending_game::mathc()]");
 }
Ejemplo n.º 9
0
 public static function registerNewUser($username, $password, $email)
 {
     return user::create_new_user($username, $password, $email);
 }
Ejemplo n.º 10
0
 public function test()
 {
     $username = "******";
     $password = "******";
     $email = "*****@*****.**";
     $username2 = "bla2";
     $password2 = "pass2";
     $email2 = "*****@*****.**";
     $username3 = "gue";
     $password3 = "pass3";
     $email3 = "*****@*****.**";
     user::create_new_user($username, $password, $email);
     $this->assertEquals(1, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     user::create_new_user($username2, $password2, $email2);
     $this->assertEquals(2, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     user::create_new_user($username3, $password3, $email3);
     $this->assertEquals(3, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     $user1ID = user::getUserByUsername($username)['id'];
     $user2ID = user::getUserByUsername($username2)['id'];
     $user3ID = user::getUserByUsername($username3)['id'];
     //pending_game::add_new_pending_game($user_id,$size) ;
     //pending_game::get_pending_game_by_id($id) ;
     $this->assertFalse(pending_game::add_new_pending_game($user1ID, -1), "[pending_game::add_new_pending_game()]");
     $this->assertFalse(pending_game::add_new_pending_game("sdfdsf", 3), "[pending_game::add_new_pending_game()]");
     $this->assertTrue(pending_game::add_new_pending_game($user1ID, 3), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $pg_id = pending_game::$last_inserted_id;
     $this->assertTrue(pending_game::add_new_pending_game($user2ID, 4), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $pg_info = pending_game::get_pending_game_by_id($pg_id);
     $this->assertEquals(3, $pg_info['size'], '[pending_game::add_new_pending_game()]');
     $this->assertEquals($user1ID, $pg_info['userID'], '[pending_game::add_new_pending_game()]');
     //get_all_pending_games_for_user_id($user_id)
     $this->assertEquals(1, count(pending_game::get_all_pending_games_for_user_id($user1ID)), "[get_all_pending_games_for_user_id()]");
     $this->assertTrue(pending_game::add_new_pending_game($user1ID, 3), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $this->assertEquals(2, count(pending_game::get_all_pending_games_for_user_id($user1ID)), "[get_all_pending_games_for_user_id()]");
     $this->assertNull(pending_game::get_all_pending_games_for_user_id("hhh"), "[get_all_pending_games_for_user_id()]");
     $this->assertNull(pending_game::get_all_pending_games_for_user_id($user3ID), "[get_all_pending_games_for_user_id()]");
     $this->assertEquals($user1ID, pending_game::get_all_pending_games_for_user_id($user1ID)[0]['userID'], "[get_all_pending_games_for_user_id()]");
     //get_all_pending_games_by_size($size)
     pending_game::clear_table();
     $this->assertTrue(pending_game::add_new_pending_game($user1ID, 3), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $pg_id1 = pending_game::$last_inserted_id;
     $this->assertTrue(pending_game::add_new_pending_game($user2ID, 3), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $this->assertTrue(pending_game::add_new_pending_game($user1ID, 4), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $this->assertEquals(2, count(pending_game::get_all_pending_games_by_size(3)), "[get_all_pending_games_by_size()]");
     $this->assertEquals(1, count(pending_game::get_all_pending_games_by_size(4)), "[get_all_pending_games_by_size()]");
     $this->assertNull(pending_game::get_all_pending_games_by_size(5), "[get_all_pending_games_by_size()]");
     //get_all_pending_games()
     $this->assertEquals(3, count(pending_game::get_all_pending_games()), "[get_all_pending_games()]");
     //get_count_pending_games()
     $this->assertEquals(3, pending_game::get_count_pending_games(), "[get_count_pending_games()]");
     //get_count_pending_by_size($size)
     $this->assertEquals(0, pending_game::get_count_pending_by_size(10), "[get_count_pending_by_size()]");
     $this->assertEquals(0, pending_game::get_count_pending_by_size("sdfdf"), "[get_count_pending_by_size()]");
     $this->assertEquals(2, pending_game::get_count_pending_by_size(3), "[get_count_pending_by_size()]");
     $this->assertEquals(1, pending_game::get_count_pending_by_size(4), "[get_count_pending_by_size()]");
     //pending_game::delete_pending_game_by_id($id)
     $this->assertFalse(pending_game::delete_pending_game_by_id("sds"), "[pending_game::delete_pending_game_by_id()]");
     $this->assertEquals($pg_id1, pending_game::get_pending_game_by_id($pg_id1)['id'], "[delete_pending_game_by_id()]");
     $this->assertTrue(pending_game::delete_pending_game_by_id($pg_id1), "[pending_game::delete_pending_game_by_id()]");
     $this->assertNull(pending_game::get_pending_game_by_id($pg_id1), "[delete_pending_game_by_id()]");
     //pending_game::delete_all_pending_games_for_user_id($user_id)
     $this->assertFalse(pending_game::delete_all_pending_games_for_user_id("ddd"), "[pending_game::delete_all_pending_games_for_user_id()]");
     pending_game::clear_table();
     $this->assertTrue(pending_game::add_new_pending_game($user1ID, 3), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $this->assertTrue(pending_game::add_new_pending_game($user2ID, 3), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $this->assertTrue(pending_game::add_new_pending_game($user1ID, 4), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $this->assertEquals(2, count(pending_game::get_all_pending_games_for_user_id($user1ID)), "[get_all_pending_games_for_user_id()]");
     $this->assertEquals(3, pending_game::get_count_pending_games(), "[get_count_pending_games()]");
     $this->assertTrue(pending_game::delete_all_pending_games_for_user_id($user1ID), "[pending_game::delete_all_pending_games_for_user_id()]");
     $this->assertEquals(1, pending_game::get_count_pending_games(), "[get_count_pending_games()]");
     $this->assertEquals(1, count(pending_game::get_all_pending_games_for_user_id($user2ID)), "[get_all_pending_games_for_user_id()]");
     $this->assertNull(pending_game::get_all_pending_games_for_user_id($user1ID), "[get_all_pending_games_for_user_id()]");
     //pending_game::match($game_id1,$game_id2)
     pending_game::clear_table();
     $this->assertTrue(pending_game::add_new_pending_game($user1ID, 3), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $g1_id = pending_game::$last_inserted_id;
     $this->assertTrue(pending_game::add_new_pending_game($user2ID, 4), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $g2_id = pending_game::$last_inserted_id;
     $this->assertTrue(pending_game::add_new_pending_game($user1ID, 4), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $g3_id = pending_game::$last_inserted_id;
     $this->assertFalse(pending_game::match($g1_id, $g2_id));
     $this->assertFalse(pending_game::match("d", $g2_id));
     $this->assertFalse(pending_game::match($g1_id, "d"));
     $this->assertEquals(0, game::getNumberOfGames(), "[pending_game::mathc()]");
     $this->assertEquals(2, pending_game::get_count_pending_by_size(4), "[pending_game::mathc()]");
     $this->assertTrue(pending_game::match($g3_id, $g2_id));
     $this->assertEquals(1, game::getNumberOfGames(), "[pending_game::mathc()]");
     $this->assertEquals(0, pending_game::get_count_pending_by_size(4), "[pending_game::mathc()]");
     $this->assertTrue(!empty(game::getAllGamesForUserId($user1ID)), "[pending_game::mathc()]");
     $this->assertTrue(!empty(game::getAllGamesForUserId($user2ID)), "[pending_game::mathc()]");
 }