Пример #1
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']);
 }
 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']);
 }
Пример #3
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());
 }
Пример #4
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']);
 }
Пример #5
0
 public function testEditProblem()
 {
     // Login
     $author = $this->createUserAndLogin();
     // Create a problem
     $problemData = ProblemsFactory::createProblem(null, null, 1, $author);
     // Open problem create
     $this->open('/problemedit.php');
     sleep(1);
     $this->type('name=edit-problem-list', $problemData["request"]["alias"]);
     $this->waitForValue('name=title', $problemData["request"]["title"]);
     $problemNewData = ProblemsFactory::getRequest();
     $this->type('name=title', $problemNewData["request"]["title"]);
     $this->type('source', $problemNewData["request"]["source"]);
     $this->type('time_limit', '666');
     $this->type('memory_limit', '1234');
     $this->type('validator', 'token-caseless');
     $this->type('public', '1');
     // Click inicia sesion
     $this->clickAndWait("//input[@value='Actualizar problema']");
     $this->assertElementContainsText('//*[@id="content"]/div[2]/div', "Problem updated succesfully!");
     // Verify data in DB
     $problem_mask = new Problems();
     $problem_mask->setTitle($problemNewData["request"]["title"]);
     $problems = ProblemsDAO::search($problem_mask);
     // Check that we only retreived 1 element
     $this->assertEquals(1, count($problems));
     $this->assertEquals($problemNewData["request"]["source"], $problems[0]->getSource());
     $this->assertEquals(666, $problems[0]->getTimeLimit());
     $this->assertEquals(1234, $problems[0]->getMemoryLimit());
     $this->assertEquals('token-caseless', $problems[0]->getValidator());
     $this->assertEquals('1', $problems[0]->getPublic());
 }
Пример #6
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"]);
 }
Пример #7
0
 public function testOpenCreatePageWithoutLogin()
 {
     // Create a problem
     $problemData = ProblemsFactory::getRequest();
     // Open problem create
     $this->open('/problemnew.php');
     $this->waitForElementPresent('//*[@id="content"]/div[2]/div[1]/h1');
     $this->assertElementContainsText('//*[@id="content"]/div[2]/div[1]/h1', "¡Inicia sesion en Omegaup!");
 }
Пример #8
0
 /**
  * Tests apiRankByProblemsSolved for a specific user
  */
 public function testUserRankByProblemsSolved()
 {
     // Create a user and sumbit a run with him
     $contestant = UserFactory::createUser();
     $problemData = ProblemsFactory::createProblem();
     $runData = RunsFactory::createRunToProblem($problemData, $contestant);
     RunsFactory::gradeRun($runData);
     // Call API
     $response = UserController::apiRankByProblemsSolved(new Request(array('username' => $contestant->getUsername())));
     $this->assertEquals($response['name'], $contestant->getName());
     $this->assertEquals($response['problems_solved'], 1);
 }
Пример #9
0
 public function testProblemRedirectsToLogin()
 {
     // Create a problem
     $problemData = ProblemsFactory::createProblem();
     // Open index
     $this->open('/');
     // Click in Problems
     $this->clickAndWait('link=Problemas');
     // Click in Problem $problemData
     $this->waitForElementPresent('//*[@id="problems_list"]/table/tbody/tr[2]/td/a');
     $this->clickAndWait('link=' . $problemData['request']['title']);
     // Verify we are in login page
     $this->waitForElementPresent("//input[@value='Inicia sesion']");
 }
Пример #10
0
 public function testEditableProblems()
 {
     $author = UserFactory::createUser();
     $problemData[0] = ProblemsFactory::createProblemWithAuthor($author);
     $problemData[1] = ProblemsFactory::createProblemWithAuthor($author);
     $problemData[2] = ProblemsFactory::createProblemWithAuthor($author);
     // Call API
     // Call api
     $r = new Request(array("auth_token" => self::login($author)));
     $response = UserController::apiProblems($r);
     $this->assertEquals(count($problemData), count($response["problems"]));
     $this->assertEquals($problemData[2]["request"]["alias"], $response["problems"][0]["alias"]);
     $this->assertEquals($problemData[1]["request"]["alias"], $response["problems"][1]["alias"]);
     $this->assertEquals($problemData[0]["request"]["alias"], $response["problems"][2]["alias"]);
 }
Пример #11
0
 /**
  * Test apiBestScore for submits in a problem for other user
  */
 public function testBestScoreInProblemOtherUser()
 {
     // Create problem
     $problemData = ProblemsFactory::createProblem();
     // Create contestant
     $contestant = UserFactory::createUser();
     // Create user who will use the API
     $user = UserFactory::createUser();
     // Create 2 runs, 100 and 50.
     $runData = RunsFactory::createRunToProblem($problemData, $contestant);
     $runDataPA = RunsFactory::createRunToProblem($problemData, $contestant);
     RunsFactory::gradeRun($runData);
     RunsFactory::gradeRun($runDataPA, 0.5, "PA");
     // Call API
     $response = ProblemController::apiBestScore(new Request(array("auth_token" => $this->login($user), "problem_alias" => $problemData["request"]["alias"], "username" => $contestant->getUsername())));
     $this->assertEquals(100.0, $response["score"]);
 }
 /**
  * Test apiBestScore for submits in a problem for other user
  */
 public function testBestScoreInProblemOtherUser()
 {
     // Create problem
     $problemData = ProblemsFactory::createProblem();
     // Create contestant
     $contestant = UserFactory::createUser();
     // Create user who will use the API
     $user = UserFactory::createUser();
     // Create 2 runs, 100 and 50.
     $runData = RunsFactory::createRunToProblem($problemData, $contestant);
     $runDataPA = RunsFactory::createRunToProblem($problemData, $contestant);
     RunsFactory::gradeRun($runData);
     RunsFactory::gradeRun($runDataPA, 0.5, 'PA');
     // Call API
     $response = ProblemController::apiBestScore(new Request(array('auth_token' => $this->login($user), 'problem_alias' => $problemData['request']['alias'], 'username' => $contestant->getUsername())));
     $this->assertEquals(100.0, $response['score']);
 }
 /**
  * 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"]);
 }
Пример #14
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));
 }
Пример #15
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]');
 }
Пример #16
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"]);
 }
Пример #17
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"]));
 }
Пример #18
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"]);
 }
Пример #19
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']);
 }
Пример #20
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"]);
 }
Пример #21
0
 /**
  * Basic test of rerun
  */
 public function testRejudgeWithoutCompileError()
 {
     // 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);
     // Detour grader calls expecting one call
     $this->detourGraderCalls($this->once());
     // Build request
     $r = new Request();
     $r['run_alias'] = $runData['response']['guid'];
     $r['auth_token'] = $this->login($contestData['director']);
     // Call API
     $response = RunController::apiRejudge($r);
     $this->assertEquals('ok', $response['status']);
 }
Пример #22
0
 public function testAddProblemToContest()
 {
     // Login
     $author = $this->createUserAndLogin();
     // Create a problem
     $problemData = ProblemsFactory::createProblem(null, null, 1, $author);
     // Create a contest
     $contestData = ContestsFactory::createContest();
     ContestsFactory::addAdminUser($contestData, $author);
     // Open page
     $this->open('/addproblemtocontest.php');
     // Wait for ajax to populate
     sleep(1);
     $this->type('name=problems', $problemData["request"]["alias"]);
     $this->type('name=contests', $contestData["request"]["alias"]);
     // Click Agregar problema
     $this->click("//input[@value='Agregar problema']");
     // Assert
     $this->waitForElementPresent('id=status');
     sleep(1);
     $this->assertElementContainsText('id=status', "Problem successfully added!");
     // Check db
     AddProblemToContestTest::assertProblemAddedToContest($problemData, $contestData, array("points" => 100, "order_in_contest" => 1));
 }
 /**
  * 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());
 }
 public function testPublicClarificationsCanBeViewed()
 {
     // 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 our contestant who will try to view the clarification
     $contestant2 = UserFactory::createUser();
     // Create the clarification, note that contestant will create it
     $this->detourBroadcasterCalls();
     $clarificationData = ClarificationsFactory::createClarification($problemData, $contestData, $contestant);
     // Manually set the just created clarification to PUBLIC
     $clarification = ClarificationsDAO::getByPK($clarificationData['response']['clarification_id']);
     $clarification->setPublic('1');
     ClarificationsDAO::save($clarification);
     // Prepare the request object
     $r = new Request();
     $r['clarification_id'] = $clarificationData['response']['clarification_id'];
     // Log in with the author of the clarification
     $r['auth_token'] = $this->login($contestant2);
     // Call API
     $response = ClarificationController::apiDetails($r);
     // Check the data we got
     $this->assertClarification($r['clarification_id'], $response);
 }
Пример #25
0
 /**
  * apiDetails with only AC and Weights
  */
 public function testScoreboardDetailsOnlyAcAndWeight()
 {
     $groupData = GroupsFactory::createGroup();
     $scoreboardData = GroupsFactory::createGroupScoreboard($groupData);
     $contestsData = array();
     // Create contestants to submit runs
     $contestantInGroup = UserFactory::createUser();
     GroupsFactory::addUserToGroup($groupData, $contestantInGroup);
     $contestantInGroupNoAc = UserFactory::createUser();
     GroupsFactory::addUserToGroup($groupData, $contestantInGroupNoAc);
     $n = 5;
     for ($i = 0; $i < $n; $i++) {
         $contestsData[] = ContestsFactory::createContest();
         ContestsFactory::addAdminUser($contestsData[$i], $groupData['owner']);
         GroupsFactory::addContestToScoreboard($contestsData[$i], $scoreboardData, $groupData, 1, $i === 0 ? 3 : 1);
         // Create a problem to solve
         $problemData = ProblemsFactory::createProblem();
         ContestsFactory::addProblemToContest($problemData, $contestsData[$i]);
         // Submit runs
         $run1 = RunsFactory::createRun($problemData, $contestsData[$i], $contestantInGroup);
         $run2 = RunsFactory::createRun($problemData, $contestsData[$i], $contestantInGroupNoAc);
         RunsFactory::gradeRun($run1);
         RunsFactory::gradeRun($run2, 0.5, 'PA');
     }
     $response = GroupScoreboardController::apiDetails(new Request(array('auth_token' => self::login($groupData['owner']), 'group_alias' => $groupData['request']['alias'], 'scoreboard_alias' => $scoreboardData['request']['alias'])));
     $this->assertEquals($n, count($response['contests']));
     $this->assertEquals($scoreboardData['request']['alias'], $response['scoreboard']['alias']);
     // 2 users in the merged scoreboard is expected
     $this->assertEquals(2, count($response['ranking']));
     $this->assertEquals($n, count($response['ranking'][0]['contests']));
     // Only AC is expected
     $this->assertEquals(100, $response['ranking'][0]['contests'][$contestsData[1]['request']['alias']]['points']);
     $this->assertEquals(0, $response['ranking'][1]['contests'][$contestsData[1]['request']['alias']]['points']);
     // Weight x3 in the first contest for 1st user
     $this->assertEquals(300, $response['ranking'][0]['contests'][$contestsData[0]['request']['alias']]['points']);
     $this->assertEquals(700, $response['ranking'][0]['total']['points']);
 }
Пример #26
0
 /**
  * Test SessionController::apiCurrentSession private_problems_count
  * when there's 1 public problem
  */
 public function testSessionControlerPrivateProblemsCountWithPublicProblem()
 {
     // Create public problem
     $problemData = ProblemsFactory::createProblem(null, null, 1);
     $user = $problemData['author'];
     $this->mockSessionManager();
     // Login
     $auth_token = $this->login($user);
     // Prepare COOKIE as SessionMannager->getCookie expects
     $_COOKIE[OMEGAUP_AUTH_TOKEN_COOKIE_NAME] = $auth_token;
     // Call CurrentSession api
     $response = SessionController::apiCurrentSession();
     $this->assertEquals(0, $response['private_problems_count']);
 }
Пример #27
0
 /**
  * Basic test for uploadin problem missing outputs
  *
  * @expectedException InvalidParameterException
  */
 public function testCreateProblemMissingOutput()
 {
     // Get the problem data
     $problemData = ProblemsFactory::getRequest(OMEGAUP_RESOURCES_ROOT . 'missingout.zip');
     $r = $problemData['request'];
     $problemAuthor = $problemData['author'];
     // Login user
     $r['auth_token'] = $this->login($problemAuthor);
     // Get File Uploader Mock and tell Omegaup API to use it
     FileHandler::SetFileUploader($this->createFileUploaderMock());
     // Call the API
     $response = ProblemController::apiCreate($r);
 }
Пример #28
0
 /**
  * Best score is returned, problem inside a contest
  */
 public function testScoreInDetailsInsideContest()
 {
     // 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::apiDetails(new Request(array("auth_token" => $this->login($contestant), "problem_alias" => $problemData["request"]["alias"], "contest_alias" => $contestData["request"]["alias"])));
     $this->assertEquals(50.0, $response["score"]);
 }
Пример #29
0
 /**
  * Add too many problems to a contest.
  */
 public function testAddTooManyProblemsToContest()
 {
     // Get a contest
     $contestData = ContestsFactory::createContest();
     $auth_token = $this->login($contestData["director"]);
     for ($i = 0; $i < MAX_PROBLEMS_IN_CONTEST + 1; $i++) {
         // Get a problem
         $problemData = ProblemsFactory::createProblemWithAuthor($contestData['director']);
         // Build request
         $r = new Request(array("auth_token" => $auth_token, "contest_alias" => $contestData["contest"]->alias, "problem_alias" => $problemData["request"]["alias"], "points" => 100, "order_in_contest" => $i + 1));
         try {
             // Call API
             $response = ContestController::apiAddProblem($r);
             $this->assertLessThan(MAX_PROBLEMS_IN_CONTEST, $i);
             // Validate
             $this->assertEquals("ok", $response["status"]);
             self::assertProblemAddedToContest($problemData, $contestData, $r);
         } catch (ApiException $e) {
             $this->assertEquals($e->getMessage(), "contestAddproblemTooManyProblems");
             $this->assertEquals($i, MAX_PROBLEMS_IN_CONTEST);
         }
     }
 }
Пример #30
0
 /**
  * Test 'page', 'order_by' and 'mode' parametes of the apiList() method, and search by title.
  */
 public function testProblemListPager()
 {
     // Create a user and some problems with submissions for the tests.
     $contestant = UserFactory::createUser();
     for ($i = 0; $i < 6; $i++) {
         $problemData[$i] = ProblemsFactory::createProblem(null, null, 1);
         $runs = $i / 2;
         for ($r = 0; $r < $runs; $r++) {
             $runData = RunsFactory::createRunToProblem($problemData[$i], $contestant);
             $points = rand(0, 100);
             $verdict = 'WA';
             if ($points > 0) {
                 $verdict = $points == 100 ? 'AC' : 'PA';
             }
             RunsFactory::gradeRun($runData, $points / 100, $verdict);
         }
     }
     $request = new Request();
     $request['auth_token'] = $this->login($contestant);
     $response = ProblemController::apiList($request);
     // Test search by title
     $titles = array();
     foreach ($response['results'] as $problem) {
         array_push($titles, $problem['title']);
     }
     foreach ($titles as $title) {
         $request['query'] = $title;
         $response = ProblemController::apiList($request);
         $this->assertTrue(count($response['results']) == 1);
         $this->assertTrue($title === $response['results'][0]['title']);
     }
     $request['query'] = null;
     $response = ProblemController::apiList($request);
     $total = $response['total'];
     $pages = intval(($total + PROBLEMS_PER_PAGE - 1) / PROBLEMS_PER_PAGE);
     // The following tests will try the different scenarios that can occur
     // with the additions of the three features to apiList(), that is, paging,
     // order by column and order mode: Call apiList() with and without
     // pagination, for each allowed ordering and each possible order mode.
     $modes = array('asc', 'desc');
     $columns = array('title', 'submissions', 'accepted', 'ratio', 'points', 'score');
     $counter = 0;
     for ($paging = 0; $paging <= 1; $paging++) {
         foreach ($columns as $col) {
             foreach ($modes as $mode) {
                 $first = null;
                 $last = null;
                 $request['mode'] = $mode;
                 $request['order_by'] = $col;
                 if ($paging == 1) {
                     // Clear offset and rowcount if set.
                     if (isset($request['offset'])) {
                         unset($request['offset']);
                     }
                     if (isset($request['rowcount'])) {
                         unset($request['rowcount']);
                     }
                     $request['page'] = 1;
                     $response = ProblemController::apiList($request);
                     $first = $response['results'];
                     $request['page'] = $pages;
                     $response = ProblemController::apiList($request);
                     $last = $response['results'];
                     // Test number of problems per page
                     $this->assertEquals(PROBLEMS_PER_PAGE, count($first));
                 } else {
                     $request['page'] = null;
                     $response = ProblemController::apiList($request);
                     $first = $response['results'];
                     $last = $first;
                 }
                 $i = 0;
                 $j = count($last) - 1;
                 if ($col === 'title') {
                     $comp = strcmp($first[$i]['title'], $last[$j]['title']);
                     if ($mode === 'asc') {
                         $this->assertTrue($comp <= 0);
                     } else {
                         $this->assertTrue($comp >= 0);
                     }
                 } else {
                     if ($mode === 'asc') {
                         $this->assertTrue($first[$i][$col] <= $last[$j][$col]);
                     } else {
                         $this->assertTrue($first[$i][$col] >= $last[$j][$col]);
                     }
                 }
             }
         }
     }
 }