/**
  * 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']);
 }
 /**
  * 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 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']);
 }
Esempio n. 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"]);
 }
Esempio n. 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());
 }
 /**
  * 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']);
 }
Esempio n. 7
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);
 }
 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']");
 }
Esempio n. 9
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"]);
 }
Esempio n. 12
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));
 }
 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]');
 }
Esempio n. 14
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"]);
 }
Esempio n. 15
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"]);
 }
Esempio n. 16
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"]));
 }
Esempio n. 17
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"]);
 }
Esempio n. 18
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']);
 }
Esempio n. 19
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']);
 }
 /**
  * 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 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));
 }
Esempio n. 22
0
 /**
  * Add a problem to contest with unauthorized user
  * 
  * @expectedException ForbiddenAccessException
  */
 public function testAddProblemToContestWithUnauthorizedUser()
 {
     // Get a problem
     $problemData = ProblemsFactory::createProblem();
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Create an empty request
     $r = new Request();
     // Log in as another random user
     $user = UserFactory::createUser();
     $r["auth_token"] = $this->login($user);
     // Build request
     $r["contest_alias"] = $contestData["request"]["alias"];
     $r["problem_alias"] = $problemData["request"]["alias"];
     $r["points"] = 100;
     $r["order_in_contest"] = 1;
     // Call API
     $response = ContestController::apiAddProblem($r);
 }
 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);
 }
 /**
  * Language filter works.
  */
 public function testGetContestDetailsWithLanguageFilter()
 {
     // Get a contest
     $contestData = ContestsFactory::createContest(null, 1, null, 'c,cpp,java');
     // Get some problems into the contest
     $problemData = ProblemsFactory::createProblem(null, null, 1, null, 'cpp,java,py');
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Get a user for our scenario
     $contestant = UserFactory::createUser();
     // Prepare our request
     $r = new Request();
     $r['contest_alias'] = $contestData['request']['alias'];
     // Log in the user
     $r['auth_token'] = $this->login($contestant);
     // Explicitly join contest
     ContestController::apiOpen($r);
     // Call api
     $response = ContestController::apiDetails($r);
     $this->assertEquals(1, count($response['problems']));
     // Verify that the allowed languages for the problem are the intersection of
     // the allowed languages.
     $this->assertEquals('cpp,java', $response['problems'][0]['languages']);
 }
 /**
  * Tests problem admins list API
  */
 public function testProblemAdmins()
 {
     // Get a problem
     $problemData = ProblemsFactory::createProblem();
     // Create our new admin
     $problemAdmin = UserFactory::createUser();
     // Add admin to the problem
     $response = ProblemController::apiAddAdmin(new Request(array('usernameOrEmail' => $problemAdmin->username, 'problem_alias' => $problemData['request']['alias'], 'auth_token' => $this->login($problemData['author']))));
     $this->assertEquals('ok', $response['status']);
     // Get the list of admins
     $response = ProblemController::apiAdmins(new Request(array('problem_alias' => $problemData['request']['alias'], 'auth_token' => $this->login($problemData['author']))));
     $adminFound = false;
     $authorFound = false;
     foreach ($response['admins'] as $adminEntry) {
         if ($adminEntry['username'] == $problemAdmin->username) {
             $adminFound = true;
         }
         if ($adminEntry['username'] == $problemData['author']->username) {
             $authorFound = true;
         }
     }
     $this->assertTrue($adminFound);
     $this->assertTrue($authorFound);
 }
Esempio n. 26
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]);
                     }
                 }
             }
         }
     }
 }
Esempio n. 27
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"]);
 }
 /**
  * Basic tests for shareable scoreboard url
  */
 public function testScoreboardUrlNoLogin()
 {
     // Get a private contest with 0% of scoreboard show percentage
     $contestData = ContestsFactory::createContest(null, 0);
     ContestsFactory::setScoreboardPercentage($contestData, 0);
     // Create problem
     $problemData = ProblemsFactory::createProblem();
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestant, will submit 1 run
     $contestant = UserFactory::createUser();
     ContestsFactory::addUser($contestData, $contestant);
     $runData = RunsFactory::createRun($problemData, $contestData, $contestant);
     RunsFactory::gradeRun($runData);
     // Get the scoreboard url by using the MyList api being the
     // contest director
     $response = ContestController::apiMyList(new Request(array('auth_token' => $this->login($contestData['director']))));
     // Look for our contest from the list and save the scoreboard tokens
     $scoreboard_url = null;
     $scoreboard_admin_url = null;
     foreach ($response['results'] as $c) {
         if ($c['alias'] === $contestData['request']['alias']) {
             $scoreboard_url = $c['scoreboard_url'];
             $scoreboard_admin_url = $c['scoreboard_url_admin'];
             break;
         }
     }
     $this->assertNotNull($scoreboard_url);
     $this->assertNotNull($scoreboard_admin_url);
     // Call scoreboard api from the user
     $scoreboardResponse = ContestController::apiScoreboard(new Request(array('contest_alias' => $contestData['request']['alias'], 'token' => $scoreboard_url)));
     $this->assertEquals('0', $scoreboardResponse['ranking'][0]['total']['points']);
     // Call scoreboard api from the user with admin token
     $scoreboardResponse = ContestController::apiScoreboard(new Request(array('contest_alias' => $contestData['request']['alias'], 'token' => $scoreboard_admin_url)));
     $this->assertEquals('100', $scoreboardResponse['ranking'][0]['total']['points']);
 }
Esempio n. 29
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']);
 }
Esempio n. 30
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']);
 }