Esempio n. 1
0
 public function testContestUsersValid()
 {
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Create 10 users
     $n = 10;
     $users = array();
     for ($i = 0; $i < $n; $i++) {
         // Create a user
         $users[$i] = UserFactory::createUser();
         // Add it to the contest
         ContestsFactory::addUser($contestData, $users[$i]);
     }
     // Create a n+1 user who will just join to the contest withot being
     // added via API. For public contests, by entering to the contest, the user should be in
     // the list of contest's users.
     $nonRegisteredUser = UserFactory::createUser();
     ContestsFactory::openContest($contestData, $nonRegisteredUser);
     // Prepare request
     $r = new Request();
     $r["contest_alias"] = $contestData["request"]["alias"];
     // Log in with the admin of the contest
     $r["auth_token"] = $this->login($contestData["director"]);
     // Call API
     $response = ContestController::apiUsers($r);
     // Check that we have n+1 users
     $this->assertEquals($n + 1, count($response["users"]));
 }
Esempio n. 2
0
 /**
  * Creates a run
  *
  * @param type $problemData
  * @param type $contestData
  * @param Users $contestant
  * @return array
  */
 public static function createRun($problemData, $contestData, $contestant)
 {
     // Our contestant has to open the contest before sending a run
     ContestsFactory::openContest($contestData, $contestant);
     // Then we need to open the problem
     ContestsFactory::openProblemInContest($contestData, $problemData, $contestant);
     $r = self::createRequestCommon($problemData, $contestData, $contestant);
     // Call API
     RunController::$grader = new GraderMock();
     $response = RunController::apiCreate($r);
     // Clean up
     unset($_REQUEST);
     return array('request' => $r, 'contestant' => $contestant, 'response' => $response);
 }
 public function testContestActivityReport()
 {
     // Get a contest
     $contestData = ContestsFactory::createContest();
     $user = UserFactory::createUser();
     ContestsFactory::openContest($contestData, $user);
     ContestController::apiDetails(new Request(array('contest_alias' => $contestData['request']['alias'], 'auth_token' => $this->login($user))));
     // Call API
     $response = ContestController::apiActivityReport(new Request(array('contest_alias' => $contestData['request']['alias'], 'auth_token' => $this->login($contestData['director']))));
     // Check that we have entries in the log.
     $this->assertEquals(1, count($response['events']));
     $this->assertEquals($user->username, $response['events'][0]['username']);
     $this->assertEquals(0, $response['events'][0]['ip']);
     $this->assertEquals('open', $response['events'][0]['event']['name']);
 }
Esempio n. 4
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);
 }
Esempio n. 5
0
 /**
  * Languages must be validated against the problem's allowed languages.
  *
  * @expectedException InvalidParameterException
  */
 public function testRunInvalidContestLanguage()
 {
     $problemData = ProblemsFactory::createProblem();
     // Get a contest
     $contestData = ContestsFactory::createContest(null, 1, null, 'cpp');
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestant
     $contestant = UserFactory::createUser();
     // Our contestant has to open the contest before sending a run
     ContestsFactory::openContest($contestData, $contestant);
     // Then we need to open the problem
     ContestsFactory::openProblemInContest($contestData, $problemData, $contestant);
     // Create an empty request
     $r = new Request();
     // Log in as contest director
     $r["auth_token"] = $this->login($contestant);
     // Build request
     $r["contest_alias"] = $contestData["request"]["alias"];
     $r["problem_alias"] = $problemData["request"]["alias"];
     $r["language"] = "c";
     $r["source"] = "#include <stdio.h>\nint main() { printf(\"3\"); return 0; }";
     //PHPUnit does not set IP address, doing it manually
     $_SERVER["REMOTE_ADDR"] = "127.0.0.1";
     // Call API
     $response = RunController::apiCreate($r);
 }
Esempio n. 6
0
 /**
  * Languages must be validated against the problem's allowed languages.
  *
  * @expectedException InvalidParameterException
  */
 public function testRunInvalidContestLanguage()
 {
     $problemData = ProblemsFactory::createProblem();
     // Get a contest
     $contestData = ContestsFactory::createContest(null, 1, null, 'cpp');
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestant
     $contestant = UserFactory::createUser();
     // Our contestant has to open the contest before sending a run
     ContestsFactory::openContest($contestData, $contestant);
     // Then we need to open the problem
     ContestsFactory::openProblemInContest($contestData, $problemData, $contestant);
     // Create an empty request
     $r = new Request();
     // Log in as contest director
     $r['auth_token'] = $this->login($contestant);
     // Build request
     $r['contest_alias'] = $contestData['request']['alias'];
     $r['problem_alias'] = $problemData['request']['alias'];
     $r['language'] = 'c';
     $r['source'] = "#include <stdio.h>\nint main() { printf(\"3\"); return 0; }";
     // Call API
     $response = RunController::apiCreate($r);
 }