public function testRemoveUser()
 {
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Create a user
     $user = UserFactory::createUser();
     // Add user to contest
     ContestsFactory::addUser($contestData, $user);
     // Validate 0 users
     $r = new Request();
     $r['contest_alias'] = $contestData['request']['alias'];
     $r['auth_token'] = $this->login($contestData['director']);
     $response = ContestController::apiUsers($r);
     $this->assertEquals(1, count($response['users']));
     // Remove user
     $r = new Request();
     $r['contest_alias'] = $contestData['request']['alias'];
     $r['usernameOrEmail'] = $user->getUsername();
     $r['auth_token'] = $this->login($contestData['director']);
     ContestController::apiRemoveUser($r);
     // Validate 0 users in contest
     $r = new Request();
     $r['contest_alias'] = $contestData['request']['alias'];
     $r['auth_token'] = $this->login($contestData['director']);
     $response = ContestController::apiUsers($r);
     $this->assertEquals(0, count($response['users']));
 }
예제 #2
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"]));
 }
예제 #3
0
 /**
  * Contestant submits runs and admin is able to get them
  */
 public function testGetRunsForContest()
 {
     // Get a problem
     $problemData = ProblemsFactory::createProblem();
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestant
     $contestant = UserFactory::createUser();
     // Create a run
     $runData = RunsFactory::createRun($problemData, $contestData, $contestant);
     // Grade the run
     RunsFactory::gradeRun($runData);
     // Create request
     $r = new Request();
     $r["contest_alias"] = $contestData["request"]["alias"];
     $r["auth_token"] = $this->login($contestData["director"]);
     // Call API
     $response = ContestController::apiRuns($r);
     // Assert
     $this->assertEquals(1, count($response["runs"]));
     $this->assertEquals($runData["response"]["guid"], $response["runs"][0]["guid"]);
     $this->assertEquals($contestant->username, $response["runs"][0]["username"]);
     $this->assertEquals("J1", $response["runs"][0]["judged_by"]);
 }
예제 #4
0
 /**
  * Checks that, if there's no wait time, 0 is posted in max_wait_time
  */
 public function testGetStatsNoWaitTime()
 {
     // Get a problem
     $problemData = ProblemsFactory::createProblem();
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestant
     $contestant = UserFactory::createUser();
     $ACRunsCount = 2;
     $ACRunsData = array();
     for ($i = 0; $i < $ACRunsCount; $i++) {
         $ACRunsData[$i] = RunsFactory::createRun($problemData, $contestData, $contestant);
         // Grade the run
         RunsFactory::gradeRun($ACRunsData[$i]);
     }
     // Create request
     $r = new Request();
     $r['contest_alias'] = $contestData['request']['alias'];
     $r['auth_token'] = $this->login($contestData['director']);
     // Call API
     $response = ContestController::apiStats($r);
     // Check number of pending runs
     $this->assertEquals($ACRunsCount, $response['total_runs']);
     $this->assertEquals(0, $response['max_wait_time']);
     $this->assertEquals(0, $response['max_wait_time_guid']);
 }
예제 #5
0
 public function testEditContest()
 {
     // Login
     $author = $this->createUserAndLogin();
     // Create a problem
     $contestData = ContestsFactory::createContest(null, 1, $author);
     // Open problem create
     $this->open('/contestedit.php');
     sleep(1);
     $this->type('name=contests', $contestData["request"]["alias"]);
     $this->waitForValue('name=title', $contestData["request"]["title"]);
     $contestData["request"]["title"] = "new title";
     $contestData["request"]["description"] = "new description";
     $contestData["request"]["public"] = 0;
     $this->type('name=title', $contestData["request"]["title"]);
     $this->type('name=description', $contestData["request"]["description"]);
     $this->type('name=public', $contestData["request"]["public"]);
     // Click inicia sesion
     $this->click("//input[@value='Actualizar concurso']");
     $this->waitForElementPresent('id=status');
     sleep(1);
     $this->assertElementContainsText('//*[@id="content"]/div[2]/div', "Tu concurso ha sido editado!");
     // Check DB values
     $v = new OmegaupTestCase();
     $v->assertContest($contestData["request"]);
 }
예제 #6
0
 /**
  * Creates a valid clarification
  */
 public function testCreateValidClarification()
 {
     // Get a problem
     $problemData = ProblemsFactory::createProblem();
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestant who will submit the clarification
     $contestant = UserFactory::createUser();
     // Call the API
     $this->detourBroadcasterCalls();
     $clarificationData = ClarificationsFactory::createClarification($problemData, $contestData, $contestant);
     // Assert status of new contest
     $this->assertArrayHasKey("clarification_id", $clarificationData['response']);
     // Verify that clarification was inserted in the database
     $clarification = ClarificationsDAO::getByPK($clarificationData['response']['clarification_id']);
     // Verify our retreived clarificatoin
     $this->assertNotNull($clarification);
     $this->assertEquals($clarificationData['request']['message'], $clarification->getMessage());
     // We need to verify that the contest and problem IDs where properly saved
     // Extractiing the contest and problem from DB to check IDs
     $problem = ProblemsDAO::getByAlias($problemData["request"]["alias"]);
     $contest = ContestsDAO::getByAlias($contestData["request"]["alias"]);
     $this->assertEquals($contest->getContestId(), $clarification->getContestId());
     $this->assertEquals($problem->getProblemId(), $clarification->getProblemId());
 }
 public function testUpdateProblemTitleAndContents()
 {
     // Get a problem
     $problemData = ProblemsFactory::createProblem();
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestant
     $contestant = UserFactory::createUser();
     // Create a run
     $runData[0] = RunsFactory::createRun($problemData, $contestData, $contestant);
     $runData[1] = RunsFactory::createRun($problemData, $contestData, $contestant);
     // Grade the run
     RunsFactory::gradeRun($runData[0]);
     RunsFactory::gradeRun($runData[1]);
     // Get File Uploader Mock and tell Omegaup API to use it
     FileHandler::SetFileUploader($this->createFileUploaderMock());
     // Update Problem calls grader to rejudge, we need to detour grader calls
     // We will submit 2 runs to the problem, a call to grader to rejudge them
     $this->detourGraderCalls($this->exactly(1));
     // Prepare request
     $r = new Request();
     $r['title'] = 'new title';
     $r['time_limit'] = 12345;
     $r['problem_alias'] = $problemData['request']['alias'];
     $r['stack_limit'] = 12345;
     $r['message'] = 'Changed some properties';
     // Set file upload context
     $_FILES['problem_contents']['tmp_name'] = OMEGAUP_RESOURCES_ROOT . 'triangulos.zip';
     // Log in as contest director
     $r['auth_token'] = $this->login($problemData['author']);
     // Call API
     $response = ProblemController::apiUpdate($r);
     // Verify data in DB
     $problem_mask = new Problems();
     $problem_mask->setTitle($r['title']);
     $problems = ProblemsDAO::search($problem_mask);
     // Check that we only retreived 1 element
     $this->assertEquals(1, count($problems));
     // Validate rsponse
     $this->assertEquals('ok', $response['status']);
     $this->assertEquals(true, $response['rejudged']);
     $this->assertEquals('cases/1.in', $response['uploaded_files'][0]);
     // Verify problem contents were copied
     $targetpath = PROBLEMS_PATH . DIRECTORY_SEPARATOR . $r['problem_alias'] . DIRECTORY_SEPARATOR;
     $this->assertFileExists($targetpath . 'cases');
     $this->assertFileExists($targetpath . 'statements/es.html');
     $this->assertFileNotExists($targetpath . 'examples/sample.in');
     // Check update in statements
     $statement = file_get_contents($targetpath . 'statements' . DIRECTORY_SEPARATOR . 'es.html');
     $this->assertContains('perímetro', $statement);
     $this->assertEquals(12345, $problems[0]->stack_limit);
     // Call API again to add an example, should not trigger rejudge.
     $_FILES['problem_contents']['tmp_name'] = OMEGAUP_RESOURCES_ROOT . 'triangulos-examples.zip';
     $response = ProblemController::apiUpdate($r);
     $this->assertEquals('ok', $response['status']);
     $this->assertEquals(false, $response['rejudged']);
     $this->assertFileExists($targetpath . 'examples/sample.in');
 }
예제 #8
0
 /**
  * Contestant submits runs and admin is able to get them
  */
 public function testGetRunsForContest()
 {
     // Get a problem
     $problemData = ProblemsFactory::createProblem();
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestant
     $contestant = UserFactory::createUser();
     // Create a run
     $runData = RunsFactory::createRun($problemData, $contestData, $contestant);
     // Grade the run
     RunsFactory::gradeRun($runData);
     // Create request
     $r = new Request();
     $r['contest_alias'] = $contestData['request']['alias'];
     $r['auth_token'] = $this->login($contestData['director']);
     // Call API
     $response = ContestController::apiRuns($r);
     // Assert
     $this->assertEquals(1, count($response['runs']));
     $this->assertEquals($runData['response']['guid'], $response['runs'][0]['guid']);
     $this->assertEquals($contestant->username, $response['runs'][0]['username']);
     $this->assertEquals('J1', $response['runs'][0]['judged_by']);
 }
 public function testCoderOfTheMonthCalc()
 {
     $user = UserFactory::createUser();
     $contest = ContestsFactory::createContest();
     $problem = ProblemsFactory::createProblem();
     ContestsFactory::addProblemToContest($problem, $contest);
     ContestsFactory::addUser($contest, $user);
     // Creating 10 AC runs for our user in the last month
     $n = 10;
     $lastMonth = intval(date('m')) - 1;
     $runCreationDate = null;
     if ($lastMonth == 0) {
         $runCreationDate = date(intval(date('Y') - 1) . '-12-01');
     } else {
         $runCreationDate = date('Y-' . $lastMonth . '-01');
     }
     for ($i = 0; $i < $n; $i++) {
         $runData = RunsFactory::createRun($problem, $contest, $user);
         RunsFactory::gradeRun($runData);
         // Force the run to be in last month
         $run = RunsDAO::getByAlias($runData['response']['guid']);
         $run->setTime($runCreationDate);
         RunsDAO::save($run);
     }
     $response = UserController::apiCoderOfTheMonth(new Request());
     $this->assertEquals($user->getUsername(), $response['userinfo']['username']);
 }
예제 #10
0
 public function testSimpleRegistrationActions()
 {
     self::log("Started");
     //create a contest and its admin
     $contestData = ContestsFactory::createContest(null, 1);
     $contestAdmin = UserFactory::createUser();
     ContestsFactory::addAdminUser($contestData, $contestAdmin);
     //make it "registrable"
     self::log("Udate contest to make it registrable");
     $r1 = new Request();
     $r1["contest_alias"] = $contestData["request"]["alias"];
     $r1["contestant_must_register"] = true;
     $r1["auth_token"] = $this->login($contestAdmin);
     ContestController::apiUpdate($r1);
     //some user asks for contest
     $contestant = UserFactory::createUser();
     $r2 = new Request();
     $r2["contest_alias"] = $contestData["request"]["alias"];
     $r2["auth_token"] = $this->login($contestant);
     try {
         $response = ContestController::apiDetails($r2);
         $this->AssertFalse(true, "User gained access to contest even though its registration needed.");
     } catch (ForbiddenAccessException $fae) {
         // Expected. Continue.
     }
     self::log("user registers, into contest");
     ContestController::apiRegisterForContest($r2);
     //admin lists registrations
     $r3 = new Request();
     $r3["contest_alias"] = $contestData["request"]["alias"];
     $r3["auth_token"] = $this->login($contestAdmin);
     $result = ContestController::apiRequests($r3);
     $this->assertEquals(sizeof($result["users"]), 1);
     self::log("amin rejects registration");
     $r3["username"] = $contestant->username;
     $r3["resolution"] = false;
     ContestController::apiArbitrateRequest($r3);
     //ask for details again, this should fail again
     $r2 = new Request();
     $r2["contest_alias"] = $contestData["request"]["alias"];
     $r2["auth_token"] = $this->login($contestant);
     try {
         $response = ContestController::apiDetails($r2);
         $this->AssertFalse(true);
     } catch (ForbiddenAccessException $fae) {
         // Expected. Continue.
     }
     //admin admits user
     $r3["username"] = $contestant->username;
     $r3["resolution"] = true;
     ContestController::apiArbitrateRequest($r3);
     //user can now submit to contest
     $r2 = new Request();
     $r2["contest_alias"] = $contestData["request"]["alias"];
     $r2["auth_token"] = $this->login($contestant);
     // Explicitly join contest
     ContestController::apiOpen($r2);
     ContestController::apiDetails($r2);
 }
예제 #11
0
 public function testArenaRoot()
 {
     // Create a contest
     $contestData = ContestsFactory::createContest();
     // Open URL
     $this->open('/arena');
     // Sanity check: Arena at leasts says 'Arena', it is not badly broken
     $this->assertElementContainsText('//*[@id="root"]/h1', 'Arena');
     // Check that our latest contest is there
     $this->waitForElementPresent('//*[@id="current-contests"]/tr/td[1]/a');
     $this->assertElementContainsText('//*[@id="current-contests"]/tr/td[1]/a', $contestData["request"]["title"]);
 }
예제 #12
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);
 }
예제 #13
0
 /**
  * Tests that 2 contests with same name cannot be created
  *
  * @expectedException DuplicatedEntryInDatabaseException
  */
 public function testCreate2ContestsWithSameAlias()
 {
     // Create a valid contest Request object
     $contestData = ContestsFactory::getRequest();
     $r = $contestData['request'];
     $contestDirector = $contestData['director'];
     // Log in the user and set the auth token in the new request
     $r['auth_token'] = $this->login($contestDirector);
     // Call the API
     $response = ContestController::apiCreate($r);
     $this->assertEquals('ok', $response['status']);
     // Call the API for the 2nd time with same alias
     $response = ContestController::apiCreate($r);
 }
예제 #14
0
 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']);
 }
예제 #15
0
 /**
  * Test apiBestScore for submits inside a contest
  */
 public function testBestScoreInsideContest()
 {
     // Create problem and contest
     $problemData = ProblemsFactory::createProblem();
     $contestData = ContestsFactory::createContest();
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create contestant
     $contestant = UserFactory::createUser();
     // Create 2 runs, 100 and 50.
     $runDataOutsideContest = RunsFactory::createRunToProblem($problemData, $contestant);
     $runDataInsideContest = RunsFactory::createRun($problemData, $contestData, $contestant);
     RunsFactory::gradeRun($runDataOutsideContest);
     RunsFactory::gradeRun($runDataInsideContest, 0.5, "PA");
     // Call API
     $response = ProblemController::apiBestScore(new Request(array("auth_token" => $this->login($contestant), "problem_alias" => $problemData["request"]["alias"], "contest_alias" => $contestData["request"]["alias"])));
     $this->assertEquals(50.0, $response["score"]);
 }
 public function testCreateContest()
 {
     $contestData = ContestsFactory::getRequest();
     // Login
     $director = $this->createUserAndLogin();
     // Open contest create
     $this->open('/contestcreate.php');
     // Use preioi template
     $this->click('//*[@id="preioi"]');
     $this->type('name=title', $contestData['request']['title']);
     $this->type('name=alias', $contestData['request']['alias']);
     $this->type('name=description', $contestData['request']['description']);
     // Submit
     $this->click("//input[@value='Agendar concurso']");
     sleep(1);
     $this->assertElementContainsText('//*[@id="content"]/div[2]/div', 'Tu concurso ha sido creado!');
 }
예제 #17
0
 public static function createContest($title = null, $public = 1, Users $contestDirector = null, $languages = null, $finish_time = null)
 {
     // Create a valid contest Request object
     $contestData = ContestsFactory::getRequest($title, 0, $contestDirector, $languages, $finish_time);
     $r = $contestData['request'];
     $contestDirector = $contestData['director'];
     // Log in the user and set the auth token in the new request
     $r['auth_token'] = OmegaupTestCase::login($contestDirector);
     // Call the API
     $response = ContestController::apiCreate($r);
     if ($public === 1) {
         self::forcePublic($contestData);
         $r['public'] = 1;
     }
     $contest = ContestsDAO::getByAlias($r['alias']);
     return array('director' => $contestData['director'], 'request' => $r, 'contest' => $contest);
 }
예제 #18
0
 public static function createContest($title = null, $public = 1, Users $contestDirector = null, $languages = null)
 {
     // Create a valid contest Request object
     $contestData = ContestsFactory::getRequest($title, 0, $contestDirector, $languages);
     $r = $contestData["request"];
     $contestDirector = $contestData["director"];
     // Log in the user and set the auth token in the new request
     $r["auth_token"] = OmegaupTestCase::login($contestDirector);
     // Call the API
     $response = ContestController::apiCreate($r);
     if ($public === 1) {
         self::forcePublic($contestData);
         $r["public"] = 1;
     }
     $contest = ContestsDAO::getByAlias($r["alias"]);
     return array("director" => $contestData["director"], "request" => $r, "contest" => $contest);
 }
예제 #19
0
 public function testProblemArenaAndSubmbit()
 {
     // Create a contestant
     $contestant = UserFactory::createUser();
     // Create a problem
     $problemData = ProblemsFactory::createProblem();
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create a run
     $runData = RunsFactory::createRun($problemData, $contestData, $contestant);
     // Login
     $contestant = $this->createAdminUserAndLogin();
     // Open ADMIN
     $this->open('/arena/admin');
     // Wait for table to render with our run
     $this->waitForElementPresent('//*[@id="run_' . $runData['response']['guid'] . '"]/td[2]');
 }
예제 #20
0
 public function testRunTotals()
 {
     // Get a problem
     $problemData = ProblemsFactory::createProblem();
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestant
     $contestant = UserFactory::createUser();
     // Create a run
     $runData = RunsFactory::createRun($problemData, $contestData, $contestant);
     $runDataOld = RunsFactory::createRun($problemData, $contestData, $contestant);
     $run = RunsDAO::getByAlias($runDataOld['response']['guid']);
     $run->setTime(date('Y-m-d H:i:s', strtotime('-72 hours')));
     RunsDAO::save($run);
     $response = RunController::apiCounts(new Request());
     $this->assertGreaterThan(1, count($response));
 }
 /**
  * Basic test for getting the list of clarifications of a contest.
  * Create 4 clarifications in a contest with one user, then another 3 clarifications
  * with another user. 
  * Get the list for the first user, will see only his 4
  */
 public function testListPublicClarificationsForContestant()
 {
     // Get a problem
     $problemData = ProblemsFactory::createProblem();
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestant who will submit the clarification
     $contestant1 = UserFactory::createUser();
     // Create 4 clarifications with this contestant
     $clarificationData1 = array();
     $this->detourBroadcasterCalls($this->exactly(9));
     for ($i = 0; $i < 4; $i++) {
         $clarificationData1[$i] = ClarificationsFactory::createClarification($problemData, $contestData, $contestant1);
     }
     // Answer clarification 0 and 2
     ClarificationsFactory::answer($clarificationData1[0], $contestData);
     ClarificationsFactory::answer($clarificationData1[2], $contestData);
     // Create another contestant
     $contestant2 = UserFactory::createUser();
     // Create 3 clarifications with this contestant
     $clarificationData2 = array();
     for ($i = 0; $i < 3; $i++) {
         $clarificationData2[$i] = ClarificationsFactory::createClarification($problemData, $contestData, $contestant2);
     }
     // Prepare the request
     $r = new Request();
     $r["contest_alias"] = $contestData["request"]["alias"];
     // Log in with first user
     $r["auth_token"] = $this->login($contestant1);
     // Call API
     $response = ContestController::apiClarifications($r);
     // Check that we got all clarifications
     $this->assertEquals(count($clarificationData1), count($response["clarifications"]));
     // Check that the clarifications came in the order we expect
     // First we expect clarifications not answered
     $this->assertEquals($clarificationData1[3]["request"]["message"], $response["clarifications"][0]["message"]);
     $this->assertEquals($clarificationData1[1]["request"]["message"], $response["clarifications"][1]["message"]);
     // Then clarifications answered, newer first
     $this->assertEquals($clarificationData1[2]["request"]["message"], $response["clarifications"][2]["message"]);
     $this->assertEquals($clarificationData1[0]["request"]["message"], $response["clarifications"][3]["message"]);
 }
예제 #22
0
 /**
  * Check stats are ok for WA, AC, PA and total counts
  * Also validates the max wait time guid
  */
 public function testGetStats()
 {
     // Get a problem
     $problemData = ProblemsFactory::createProblem();
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestant
     $contestant = UserFactory::createUser();
     // Create some runs to be pending
     $pendingRunsCount = 5;
     $pendingRunsData = array();
     for ($i = 0; $i < $pendingRunsCount; $i++) {
         $pendingRunsData[$i] = RunsFactory::createRun($problemData, $contestData, $contestant);
     }
     $ACRunsCount = 2;
     $ACRunsData = array();
     for ($i = 0; $i < $ACRunsCount; $i++) {
         $ACRunsData[$i] = RunsFactory::createRun($problemData, $contestData, $contestant);
         // Grade the run
         RunsFactory::gradeRun($ACRunsData[$i]);
     }
     $WARunsCount = 1;
     $WARunsData = array();
     for ($i = 0; $i < $WARunsCount; $i++) {
         $WARunsData[$i] = RunsFactory::createRun($problemData, $contestData, $contestant);
         // Grade the run with WA
         RunsFactory::gradeRun($WARunsData[$i], 0, "WA");
     }
     // Create request
     $r = new Request();
     $r["problem_alias"] = $problemData["request"]["alias"];
     $r["auth_token"] = $this->login($problemData["author"]);
     // Call API
     $response = ProblemController::apiStats($r);
     // Check number of pending runs
     $this->assertEquals(count($pendingRunsData), count($response["pending_runs"]));
     $this->assertEquals(count($ACRunsData), $response["verdict_counts"]["AC"]);
     $this->assertEquals(count($WARunsData), $response["verdict_counts"]["WA"]);
     $this->assertEquals($pendingRunsCount + $ACRunsCount + $WARunsCount, $response["total_runs"]);
 }
예제 #23
0
 /**
  * Tests remove admins
  */
 public function testRemoveAdmin()
 {
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Get users
     $user = UserFactory::createUser();
     $user2 = UserFactory::createUser();
     ContestsFactory::addAdminUser($contestData, $user);
     ContestsFactory::addAdminUser($contestData, $user2);
     // Prepare request for remove one admin
     $r = new Request();
     $r["auth_token"] = $this->login($contestData["director"]);
     $r["usernameOrEmail"] = $user->getUsername();
     $r["contest_alias"] = $contestData["request"]["alias"];
     // Call api
     ContestController::apiRemoveAdmin($r);
     $contest = ContestsDAO::getByAlias($contestData['request']['alias']);
     $this->AssertFalse(Authorization::IsContestAdmin($user->getUserId(), $contest));
     $this->AssertTrue(Authorization::IsContestAdmin($user2->getUserId(), $contest));
 }
예제 #24
0
 public function testProblemsSolved()
 {
     $user = UserFactory::createUser();
     $contest = ContestsFactory::createContest();
     $problemOne = ProblemsFactory::createProblem();
     $problemTwo = ProblemsFactory::createProblem();
     ContestsFactory::addProblemToContest($problemOne, $contest);
     ContestsFactory::addProblemToContest($problemTwo, $contest);
     ContestsFactory::addUser($contest, $user);
     $runs = array();
     $runs[0] = RunsFactory::createRun($problemOne, $contest, $user);
     $runs[1] = RunsFactory::createRun($problemTwo, $contest, $user);
     $runs[2] = RunsFactory::createRun($problemOne, $contest, $user);
     RunsFactory::gradeRun($runs[0]);
     RunsFactory::gradeRun($runs[1]);
     RunsFactory::gradeRun($runs[2]);
     $r = new Request(array("auth_token" => self::login($user)));
     $response = UserController::apiProblemsSolved($r);
     $this->assertEquals(2, count($response["problems"]));
 }
예제 #25
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);
 }
예제 #26
0
 /**
  * Update from private to public with problems added
  * 
  */
 public function testUpdatePrivateContestToPublicWithProblems()
 {
     // Get a contest
     $contestData = ContestsFactory::createContest(null, 0);
     // Get a problem
     $problemData = ProblemsFactory::createProblem();
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Prepare request
     $r = new Request();
     $r["contest_alias"] = $contestData["request"]["alias"];
     // Log in with contest director
     $r["auth_token"] = $this->login($contestData["director"]);
     // Update public
     $r["public"] = 1;
     // Call API
     $response = ContestController::apiUpdate($r);
     $contestData["request"]["public"] = $r["public"];
     $this->assertContest($contestData["request"]);
 }
예제 #27
0
 /**
  * Test getting list of contests where the user is the admin
  */
 public function testAdminList()
 {
     // Our director
     $director = UserFactory::createUser();
     // Get two contests with another director, add $director to their admin list
     $contestAdminData[0] = ContestsFactory::createContest();
     ContestsFactory::addAdminUser($contestAdminData[0], $director);
     $contestAdminData[1] = ContestsFactory::createContest();
     ContestsFactory::addAdminUser($contestAdminData[1], $director);
     $contestDirectorData[0] = ContestsFactory::createContest(null, 1, $director);
     $contestDirectorData[1] = ContestsFactory::createContest(null, 1, $director);
     // Call api
     $r = new Request(array("auth_token" => self::login($director)));
     $response = UserController::apiContests($r);
     // Contests should come ordered by contest id desc
     $this->assertEquals(count($contestDirectorData) + count($contestAdminData), count($response["contests"]));
     $this->assertEquals($contestDirectorData[1]["request"]["alias"], $response["contests"][0]["alias"]);
     $this->assertEquals($contestDirectorData[0]["request"]["alias"], $response["contests"][1]["alias"]);
     $this->assertEquals($contestAdminData[1]["request"]["alias"], $response["contests"][2]["alias"]);
     $this->assertEquals($contestAdminData[0]["request"]["alias"], $response["contests"][3]["alias"]);
 }
예제 #28
0
 /**
  * Basic test of viewing run details
  * 
  */
 public function testShowRunDetailsValid()
 {
     // Get a problem
     $problemData = ProblemsFactory::createProblem();
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestant
     $contestant = UserFactory::createUser();
     // Create a run
     $runData = RunsFactory::createRun($problemData, $contestData, $contestant);
     // Prepare request
     $r = new Request();
     $r["auth_token"] = $this->login($contestant);
     $r["run_alias"] = $runData["response"]["guid"];
     // Call API
     $response = RunController::apiStatus($r);
     $this->assertEquals($r["run_alias"], $response["guid"]);
     $this->assertEquals("JE", $response["verdict"]);
     $this->assertEquals("new", $response["status"]);
 }
예제 #29
0
 /**
  * Basic test of viewing run details
  *
  */
 public function testShowRunDetailsValid()
 {
     // Get a problem
     $problemData = ProblemsFactory::createProblem();
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestant
     $contestant = UserFactory::createUser();
     // Create a run
     $runData = RunsFactory::createRun($problemData, $contestData, $contestant);
     // Prepare request
     $r = new Request();
     $r['auth_token'] = $this->login($contestant);
     $r['run_alias'] = $runData['response']['guid'];
     // Call API
     $response = RunController::apiStatus($r);
     $this->assertEquals($r['run_alias'], $response['guid']);
     $this->assertEquals('JE', $response['verdict']);
     $this->assertEquals('new', $response['status']);
 }
 /**
  * Basic test for answer
  *
  */
 public function testUpdateAnswer()
 {
     // Get a problem
     $problemData = ProblemsFactory::createProblem();
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestant who will submit the clarification
     $contestant = UserFactory::createUser();
     // Create clarification
     $this->detourBroadcasterCalls($this->exactly(2));
     $clarificationData = ClarificationsFactory::createClarification($problemData, $contestData, $contestant);
     // Update answer
     $newAnswer = 'new answer';
     $response = ClarificationsFactory::answer($clarificationData, $contestData, $newAnswer);
     // Get clarification from DB
     $clarification = ClarificationsDAO::getByPK($clarificationData['response']['clarification_id']);
     // Validate that clarification stays the same
     $this->assertEquals($clarificationData['request']['message'], $clarification->getMessage());
     $this->assertEquals($clarificationData['request']['public'], $clarification->getPublic());
     // Validate our update
     $this->assertEquals($newAnswer, $clarification->getAnswer());
 }