Esempio n. 1
0
 /**
  * Returns a Request object with valid info to create a problem and the 
  * author of the problem
  * 
  * @param string $title
  * @param string $zipName
  * @return Array
  */
 public static function getRequest($zipName = null, $title = null, $public = 1, Users $author = null, $languages = null)
 {
     if (is_null($author)) {
         $author = UserFactory::createUser();
     }
     if (is_null($title)) {
         $title = Utils::CreateRandomString();
     }
     if (is_null($zipName)) {
         $zipName = OMEGAUP_RESOURCES_ROOT . 'testproblem.zip';
     }
     $r = new Request();
     $r["title"] = $title;
     $r['alias'] = substr(preg_replace('/[^a-zA-Z0-9_-]/', '', str_replace(' ', '-', $r['title'])), 0, 32);
     $r["author_username"] = $author->getUsername();
     $r["validator"] = "token";
     $r["time_limit"] = 5000;
     $r["overall_wall_time_limit"] = 60000;
     $r["validator_time_limit"] = 30000;
     $r["extra_wall_time"] = 0;
     $r["memory_limit"] = 32000;
     $r["source"] = "yo";
     $r["order"] = "normal";
     $r["public"] = $public;
     $r["output_limit"] = 10240;
     if ($languages == null) {
         $r["languages"] = 'c,cpp,py';
     } else {
         $r["languages"] = $languages;
     }
     $r["stack_limit"] = 10000;
     // Set file upload context
     $_FILES['problem_contents']['tmp_name'] = $zipName;
     return array("request" => $r, "author" => $author, "zip_path" => $zipName);
 }
Esempio n. 2
0
 /**
  * Returns a Request object with complete context to create a contest
  * 
  * @param string $title
  * @param string $public
  * @param Users $contestDirector
  * @return Request
  */
 public static function getRequest($title = null, $public = 0, Users $contestDirector = null, $languages = null)
 {
     if (is_null($contestDirector)) {
         $contestDirector = UserFactory::createUser();
     }
     if (is_null($title)) {
         $title = Utils::CreateRandomString();
     }
     // Set context
     $r = new Request();
     $r["title"] = $title;
     $r["description"] = "description";
     $r["start_time"] = Utils::GetPhpUnixTimestamp() - 60 * 60;
     $r["finish_time"] = Utils::GetPhpUnixTimestamp() + 60 * 60;
     $r["window_length"] = null;
     $r["public"] = $public;
     $r["alias"] = substr($title, 0, 20);
     $r["points_decay_factor"] = ".02";
     $r["partial_score"] = "0";
     $r["submissions_gap"] = "0";
     $r["feedback"] = "yes";
     $r["penalty"] = 100;
     $r["scoreboard"] = 100;
     $r["penalty_type"] = "contest_start";
     $r["penalty_calc_policy"] = "sum";
     $r['languages'] = $languages;
     return array("request" => $r, "director" => $contestDirector);
 }
 public function testShouldRefuseNotRegisteredEmailAddresses()
 {
     $this->setExpectedException('InvalidParameterException');
     $email = Utils::CreateRandomString() . '@mail.com';
     $r = new Request();
     $response = ResetController::apiCreate($r);
 }
Esempio n. 4
0
 public function testIsContestAdminCheck()
 {
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Get a user
     $user = UserFactory::createUser();
     // Prepare request
     $r = new Request();
     $r["auth_token"] = $this->login($contestData["director"]);
     $r["usernameOrEmail"] = $user->getUsername();
     $r["contest_alias"] = $contestData["request"]["alias"];
     // Call api
     ContestController::apiAddAdmin($r);
     // Prepare request for an update
     $r = new Request();
     $r["contest_alias"] = $contestData["request"]["alias"];
     // Log in with contest director
     $r["auth_token"] = $this->login($user);
     // Update title
     $r["title"] = Utils::CreateRandomString();
     // Call API
     $response = ContestController::apiUpdate($r);
     // To validate, we update the title to the original request and send
     // the entire original request to assertContest. Any other parameter
     // should not be modified by Update api
     $contestData["request"]["title"] = $r["title"];
     $this->assertContest($contestData["request"]);
 }
Esempio n. 5
0
 /**
  * Basic update test
  */
 public function testUserUpdate()
 {
     // Create the user to edit
     $user = UserFactory::createUser();
     $r = new Request();
     // Login
     $r["auth_token"] = $this->login($user);
     // Change values
     $r["name"] = Utils::CreateRandomString();
     $r["country_id"] = 'MX';
     $r["state_id"] = 3;
     $r["scholar_degree"] = 'Maestría';
     $r["birth_date"] = strtotime('1988-01-01');
     $r["graduation_date"] = strtotime('2016-02-02');
     // Call api
     $response = UserController::apiUpdate($r);
     // Check user from db
     $user_db = AuthTokensDAO::getUserByToken($r["auth_token"]);
     $this->assertEquals($user_db->getName(), $r["name"]);
     $this->assertEquals($user_db->getCountryId(), $r["country_id"]);
     $this->assertEquals($user_db->getStateId(), $r["state_id"]);
     $this->assertEquals($user_db->getScholarDegree(), $r["scholar_degree"]);
     $this->assertEquals($user_db->getBirthDate(), gmdate('Y-m-d', $r["birth_date"]));
     $this->assertEquals($user_db->getGraduationDate(), gmdate('Y-m-d', $r["graduation_date"]));
 }
Esempio n. 6
0
 /**
  * Returns a Request object with complete context to create a contest
  *
  * @param string $title
  * @param string $public
  * @param Users $contestDirector
  * @return Request
  */
 public static function getRequest($title = null, $public = 0, Users $contestDirector = null, $languages = null, $finish_time = null)
 {
     if (is_null($contestDirector)) {
         $contestDirector = UserFactory::createUser();
     }
     if (is_null($title)) {
         $title = Utils::CreateRandomString();
     }
     // Set context
     $r = new Request();
     $r['title'] = $title;
     $r['description'] = 'description';
     $r['start_time'] = Utils::GetPhpUnixTimestamp() - 60 * 60;
     $r['finish_time'] = $finish_time == null ? Utils::GetPhpUnixTimestamp() + 60 * 60 : $finish_time;
     $r['window_length'] = null;
     $r['public'] = $public;
     $r['alias'] = substr($title, 0, 20);
     $r['points_decay_factor'] = '.02';
     $r['partial_score'] = '0';
     $r['submissions_gap'] = '0';
     $r['feedback'] = 'yes';
     $r['penalty'] = 100;
     $r['scoreboard'] = 100;
     $r['penalty_type'] = 'contest_start';
     $r['penalty_calc_policy'] = 'sum';
     $r['languages'] = $languages;
     $r['recommended'] = 0;
     // This is just a default value, it is not honored by apiCreate.
     return array('request' => $r, 'director' => $contestDirector);
 }
Esempio n. 7
0
 /**
  * Creates a native user in Omegaup and returns an array with the data used
  * to create the user.
  * @param $verify
  * @return array
  */
 public static function generateUser($verify = true)
 {
     $username = Utils::CreateRandomString();
     $password = Utils::CreateRandomString();
     $email = Utils::CreateRandomString() . "@mail.com";
     self::createUser($username, $password, $email, $verify);
     return array("username" => $username, "password" => $password, "email" => $email);
 }
Esempio n. 8
0
 /**
  * Creates a native user in Omegaup and returns an array with the data used
  * to create the user.
  * @param $verify
  * @return array
  */
 public static function generateUser($verify = true)
 {
     $username = Utils::CreateRandomString();
     $password = Utils::CreateRandomString();
     $email = Utils::CreateRandomString() . '@mail.com';
     self::createUser($username, $password, $email, $verify);
     return array('username' => $username, 'password' => $password, 'email' => $email);
 }
Esempio n. 9
0
 /**
  * Test user login with invalid credentials, email and password
  *
  * @expectedException InvalidCredentialsException
  */
 public function testNativeLoginByEmailInvalidPassword()
 {
     // Create an user in omegaup
     $email = Utils::CreateRandomString() . '@mail.com';
     $user = UserFactory::createUser(null, null, $email);
     // Inflate request with user data
     $r = new Request(array('usernameOrEmail' => $email, 'password' => 'badpasswordD:'));
     // Call the API
     $response = UserController::apiLogin($r);
 }
Esempio n. 10
0
 /**
  * @expectedException InvalidDatabaseOperationException
  */
 public function testBadUserUpdate()
 {
     $user = UserFactory::createUser();
     $r = new Request();
     $r['auth_token'] = $this->login($user);
     $r['name'] = Utils::CreateRandomString();
     // Invalid state_id
     $r['state_id'] = -1;
     UserController::apiUpdate($r);
 }
Esempio n. 11
0
 /**
  * Reset my password
  * 
  * @expectedException InvalidParameterException
  */
 public function testResetMyPasswordBadOldPassword()
 {
     // Create an user in omegaup
     $user = UserFactory::createUser();
     $r = new Request();
     $r["auth_token"] = $this->login($user);
     $r["username"] = $user->getUsername();
     $r["password"] = Utils::CreateRandomString();
     $r["old_password"] = "******";
     // Call api
     UserController::apiChangePassword($r);
 }
 /**
  *
  */
 public function testCreateSchoolDuplicatedName()
 {
     $user = UserFactory::createUser();
     $r = new Request(array('auth_token' => $this->login($user), 'name' => Utils::CreateRandomString()));
     // Call api
     $response = SchoolController::apiCreate($r);
     $this->assertEquals('ok', $response['status']);
     $this->assertEquals(1, count(SchoolsDAO::findByName($r['name'])));
     // Call api again
     $response = SchoolController::apiCreate($r);
     $this->assertEquals('ok', $response['status']);
     $this->assertEquals(1, count(SchoolsDAO::findByName($r['name'])));
 }
Esempio n. 13
0
 /**
  * 
  * @expectedException ForbiddenAccessException
  */
 public function testUpdateContestNonDirector()
 {
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Prepare request
     $r = new Request();
     $r["contest_alias"] = $contestData["request"]["alias"];
     // Log in with contest director
     $r["auth_token"] = $this->login(UserFactory::createUser());
     // Update title
     $r["title"] = Utils::CreateRandomString();
     // Call API
     ContestController::apiUpdate($r);
 }
Esempio n. 14
0
 /**
  * Creates a scoreboard in a group
  *
  * @param array $groupData
  * @param type $name
  * @param type $description
  * @param type $alias
  */
 public static function createGroupScoreboard(array $groupData, $name = null, $description = null, $alias = null)
 {
     if (is_null($name)) {
         $name = Utils::CreateRandomString();
     }
     if (is_null($description)) {
         $description = Utils::CreateRandomString();
     }
     if (is_null($alias)) {
         $alias = Utils::CreateRandomString();
     }
     $request = new Request(array('auth_token' => OmegaupTestCase::login($groupData['owner']), 'group_alias' => $groupData['group']->alias, 'name' => $name, 'alias' => $alias, 'description' => $description));
     $response = GroupController::apiCreateScoreboard($request);
     $scoreboards = GroupsScoreboardsDAO::search(new GroupsScoreboards(array('alias' => $alias)));
     return array('request' => $request, 'response' => $response, 'scoreboard' => $scoreboards[0]);
 }
Esempio n. 15
0
 /**
  * Creates a scoreboard in a group
  * 
  * @param array $groupData
  * @param type $name
  * @param type $description
  * @param type $alias
  */
 public static function createGroupScoreboard(array $groupData, $name = null, $description = null, $alias = null)
 {
     if (is_null($name)) {
         $name = Utils::CreateRandomString();
     }
     if (is_null($description)) {
         $description = Utils::CreateRandomString();
     }
     if (is_null($alias)) {
         $alias = Utils::CreateRandomString();
     }
     $request = new Request(array("auth_token" => OmegaupTestCase::login($groupData["owner"]), "group_alias" => $groupData["group"]->alias, "name" => $name, "alias" => $alias, "description" => $description));
     $response = GroupController::apiCreateScoreboard($request);
     $scoreboards = GroupsScoreboardsDAO::search(new GroupsScoreboards(array("alias" => $alias)));
     return array("request" => $request, "response" => $response, "scoreboard" => $scoreboards[0]);
 }
Esempio n. 16
0
 /**
  * Creates a clarification in a problem inside a contest
  * 
  * @param type $problemData
  * @param type $contestData
  * @param type $contestant
  */
 public static function createClarification($problemData, $contestData, $contestant)
 {
     // Our contestant has to open the contest before sending a clarification
     ContestsFactory::openContest($contestData, $contestant);
     // Then we need to open the problem
     ContestsFactory::openProblemInContest($contestData, $problemData, $contestant);
     // Create the request for our api
     $r = new Request();
     $r["message"] = Utils::CreateRandomString();
     $r["contest_alias"] = $contestData["request"]["alias"];
     $r["problem_alias"] = $problemData["request"]["alias"];
     $r["public"] = '0';
     // Log in our user and set the auth_token properly
     $r["auth_token"] = OmegaupTestCase::login($contestant);
     // Call the API
     $response = ClarificationController::apiCreate($r);
     // Clean up stuff
     unset($_REQUEST);
     return array("request" => $r, "response" => $response);
 }
 public function testIsContestGroupAdminCheck()
 {
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Get a user
     $user = UserFactory::createUser();
     // Get a group
     $groupData = GroupsFactory::createGroup();
     GroupsFactory::addUserToGroup($groupData, $user);
     // Prepare request
     $r = new Request();
     $r['auth_token'] = $this->login($contestData['director']);
     $r['group'] = $groupData['request']['alias'];
     $r['contest_alias'] = $contestData['request']['alias'];
     // Call api
     ContestController::apiAddGroupAdmin($r);
     // Prepare request for an update
     $r = new Request();
     $r['contest_alias'] = $contestData['request']['alias'];
     // Log in with contest director
     $r['auth_token'] = $this->login($user);
     // Update title
     $r['title'] = Utils::CreateRandomString();
     // Call API
     $response = ContestController::apiUpdate($r);
     // To validate, we update the title to the original request and send
     // the entire original request to assertContest. Any other parameter
     // should not be modified by Update api
     $contestData['request']['title'] = $r['title'];
     $this->assertContest($contestData['request']);
 }
Esempio n. 18
0
 /**
  * Test add a scoreboard
  */
 public function testCreateScoreboard()
 {
     $groupData = GroupsFactory::createGroup();
     $name = Utils::CreateRandomString();
     $description = Utils::CreateRandomString();
     $alias = Utils::CreateRandomString();
     $response = GroupController::apiCreateScoreboard(new Request(array("auth_token" => self::login($groupData["owner"]), "group_alias" => $groupData["group"]->alias, "name" => $name, "alias" => $alias, "description" => $description)));
     $this->assertEquals("ok", $response["status"]);
     $groupScoreboards = GroupsScoreboardsDAO::search(new GroupsScoreboards(array("alias" => $alias)));
     $groupScoreboard = $groupScoreboards[0];
     $this->assertNotNull($groupScoreboard);
     $this->assertEquals($description, $groupScoreboard->getDescription());
     $this->assertEquals($groupData["group"]->group_id, $groupScoreboard->getGroupId());
 }
Esempio n. 19
0
 /**
  * Test add a scoreboard
  */
 public function testCreateScoreboard()
 {
     $groupData = GroupsFactory::createGroup();
     $name = Utils::CreateRandomString();
     $description = Utils::CreateRandomString();
     $alias = Utils::CreateRandomString();
     $response = GroupController::apiCreateScoreboard(new Request(array('auth_token' => self::login($groupData['owner']), 'group_alias' => $groupData['group']->alias, 'name' => $name, 'alias' => $alias, 'description' => $description)));
     $this->assertEquals('ok', $response['status']);
     $groupScoreboards = GroupsScoreboardsDAO::search(new GroupsScoreboards(array('alias' => $alias)));
     $groupScoreboard = $groupScoreboards[0];
     $this->assertNotNull($groupScoreboard);
     $this->assertEquals($description, $groupScoreboard->getDescription());
     $this->assertEquals($groupData['group']->group_id, $groupScoreboard->getGroupId());
 }
Esempio n. 20
0
 /**
  * Admin can verify users only with username
  * Testing invalid username
  *
  * @expectedException NotFoundException
  */
 public function testUsernameVerificationByAdminInvalidUsername()
 {
     // Admin will verify $user
     $admin = UserFactory::createAdminUser();
     // Call api using admin
     $response = UserController::apiVerifyEmail(new Request(array('auth_token' => $this->login($admin), 'usernameOrEmail' => Utils::CreateRandomString())));
 }