예제 #1
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);
 }
 /**
  * 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));
 }
예제 #3
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"]);
 }
예제 #4
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));
 }
예제 #5
0
 /** 
  * 
  */
 public function testPrivateContestForContestAdmin()
 {
     $r = new Request();
     // Create new private contest
     $contestData = ContestsFactory::createContest(null, false);
     // Get a user for our scenario
     $contestant = UserFactory::createUser();
     // Add user to our private contest
     ContestsFactory::addAdminUser($contestData, $contestant);
     $r["auth_token"] = $this->login($contestant);
     $response = ContestController::apiList($r);
     // Assert our contest is there
     $this->assertTitleInList($response, $contestData);
 }
예제 #6
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']);
 }
 /**
  * Basic test of scoreboard, shows at least the run
  * just submitted
  */
 public function testBasicScoreboard()
 {
     // Get two problems
     $problemData = ProblemsFactory::createProblem();
     $problemData2 = ProblemsFactory::createProblem();
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Add the problems to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     ContestsFactory::addProblemToContest($problemData2, $contestData);
     // Create our contestants
     $contestant = UserFactory::createUser();
     $contestant2 = UserFactory::createUser();
     $contestant3 = UserFactory::createUser();
     $contestDirector = $contestData['director'];
     $contestAdmin = UserFactory::createUser();
     ContestsFactory::addAdminUser($contestData, $contestAdmin);
     // Create runs
     $runData = RunsFactory::createRun($problemData, $contestData, $contestant);
     $runData1 = RunsFactory::createRun($problemData, $contestData, $contestant);
     $runData2 = RunsFactory::createRun($problemData, $contestData, $contestant2);
     $runData3 = RunsFactory::createRun($problemData, $contestData, $contestant3);
     $runData4 = RunsFactory::createRun($problemData2, $contestData, $contestant);
     $runDataDirector = RunsFactory::createRun($problemData, $contestData, $contestDirector);
     $runDataAdmin = RunsFactory::createRun($problemData, $contestData, $contestAdmin);
     // Grade the runs
     RunsFactory::gradeRun($runData, 0, 'CE', 60);
     RunsFactory::gradeRun($runData1, 1, 'AC', 60);
     RunsFactory::gradeRun($runData2, 0.9, 'PA', 60);
     RunsFactory::gradeRun($runData3, 1, 'AC', 180);
     RunsFactory::gradeRun($runData4, 1, 'AC', 200);
     RunsFactory::gradeRun($runDataDirector, 1, 'AC', 120);
     RunsFactory::gradeRun($runDataAdmin, 1, 'AC', 110);
     // Create request
     $r = new Request();
     $r['contest_alias'] = $contestData['request']['alias'];
     $r['auth_token'] = $this->login($contestant);
     // Create API
     $response = ContestController::apiScoreboard($r);
     // Validate that we have ranking
     $this->assertEquals(3, count($response['ranking']));
     $this->assertEquals($contestant->getUsername(), $response['ranking'][0]['username']);
     //Check totals
     $this->assertEquals(200, $response['ranking'][0]['total']['points']);
     $this->assertEquals(260, $response['ranking'][0]['total']['penalty']);
     // Check places
     $this->assertEquals(1, $response['ranking'][0]['place']);
     $this->assertEquals(2, $response['ranking'][1]['place']);
     $this->assertEquals(3, $response['ranking'][2]['place']);
     // Check data per problem
     $this->assertEquals(100, $response['ranking'][0]['problems'][0]['points']);
     $this->assertEquals(60, $response['ranking'][0]['problems'][0]['penalty']);
     $this->assertEquals(1, $response['ranking'][0]['problems'][0]['runs']);
     $this->assertEquals(100, $response['ranking'][0]['problems'][1]['points']);
     $this->assertEquals(200, $response['ranking'][0]['problems'][1]['penalty']);
     $this->assertEquals(1, $response['ranking'][0]['problems'][1]['runs']);
     // Now get the scoreboard as an contest director
     $r = new Request();
     $r['contest_alias'] = $contestData['request']['alias'];
     $r['auth_token'] = $this->login($contestDirector);
     // Create API
     $response = ContestController::apiScoreboard($r);
     // Validate that we have ranking
     $this->assertEquals(3, count($response['ranking']));
     $this->assertEquals($contestant->getUsername(), $response['ranking'][0]['username']);
     //Check totals
     $this->assertEquals(200, $response['ranking'][0]['total']['points']);
     $this->assertEquals(260, $response['ranking'][0]['total']['penalty']);
     // Check places
     $this->assertEquals(1, $response['ranking'][0]['place']);
     $this->assertEquals(2, $response['ranking'][1]['place']);
     $this->assertEquals(3, $response['ranking'][2]['place']);
     // Check data per problem
     $this->assertEquals(100, $response['ranking'][0]['problems'][0]['points']);
     $this->assertEquals(60, $response['ranking'][0]['problems'][0]['penalty']);
     $this->assertEquals(1, $response['ranking'][0]['problems'][0]['runs']);
     $this->assertEquals(100, $response['ranking'][0]['problems'][1]['points']);
     $this->assertEquals(200, $response['ranking'][0]['problems'][1]['penalty']);
     $this->assertEquals(1, $response['ranking'][0]['problems'][1]['runs']);
 }
 /**
  * Tests contest report used in OMI
  */
 public function testContestReport()
 {
     // Get a contest
     $contestData = ContestsFactory::createContest();
     $contestDirector = $contestData['director'];
     // Get a problem
     $problemData = ProblemsFactory::createProblemWithAuthor($contestDirector);
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestants
     $contestants = array();
     array_push($contestants, UserFactory::createUser());
     array_push($contestants, UserFactory::createUser());
     array_push($contestants, UserFactory::createUser());
     $contestAdmin = UserFactory::createUser();
     ContestsFactory::addAdminUser($contestData, $contestAdmin);
     // Create runs
     $runsData = array();
     $runsData[0] = RunsFactory::createRun($problemData, $contestData, $contestants[0]);
     $runsData[1] = RunsFactory::createRun($problemData, $contestData, $contestants[0]);
     $runsData[2] = RunsFactory::createRun($problemData, $contestData, $contestants[1]);
     $runsData[3] = RunsFactory::createRun($problemData, $contestData, $contestants[2]);
     $runDataDirector = RunsFactory::createRun($problemData, $contestData, $contestDirector);
     $runDataAdmin = RunsFactory::createRun($problemData, $contestData, $contestAdmin);
     // Grade the runs
     RunsFactory::gradeRun($runsData[0], 0, 'CE');
     RunsFactory::gradeRun($runsData[1]);
     RunsFactory::gradeRun($runsData[2], 0.9, 'PA');
     RunsFactory::gradeRun($runsData[3], 1, 'AC', 180);
     RunsFactory::gradeRun($runDataDirector, 1, 'AC', 120);
     RunsFactory::gradeRun($runDataAdmin, 1, 'AC', 110);
     // Create API
     $response = ContestController::apiReport(new Request(array('contest_alias' => $contestData['request']['alias'], 'auth_token' => $this->login($contestDirector))));
     $this->assertEquals($problemData['request']['alias'], $response['problems'][0]['alias']);
     foreach ($contestants as $contestant) {
         $found = false;
         foreach ($response['ranking'] as $rank) {
             if ($rank['username'] == $contestant->username) {
                 $found = true;
                 break;
             }
         }
         $this->assertTrue($found);
     }
 }
예제 #9
0
 /**
  * Tests contest report used in OMI
  */
 public function testContestReport()
 {
     // Get a contest
     $contestData = ContestsFactory::createContest();
     $contestDirector = $contestData["director"];
     // Get a problem
     $problemData = ProblemsFactory::createProblemWithAuthor($contestDirector);
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestants
     $contestants = array();
     array_push($contestants, UserFactory::createUser());
     array_push($contestants, UserFactory::createUser());
     array_push($contestants, UserFactory::createUser());
     $contestAdmin = UserFactory::createUser();
     ContestsFactory::addAdminUser($contestData, $contestAdmin);
     // Create runs
     $runsData = array();
     $runsData[0] = RunsFactory::createRun($problemData, $contestData, $contestants[0]);
     $runsData[1] = RunsFactory::createRun($problemData, $contestData, $contestants[0]);
     $runsData[2] = RunsFactory::createRun($problemData, $contestData, $contestants[1]);
     $runsData[3] = RunsFactory::createRun($problemData, $contestData, $contestants[2]);
     $runDataDirector = RunsFactory::createRun($problemData, $contestData, $contestDirector);
     $runDataAdmin = RunsFactory::createRun($problemData, $contestData, $contestAdmin);
     // Grade the runs
     RunsFactory::gradeRun($runsData[0], 0, "CE");
     RunsFactory::gradeRun($runsData[1]);
     RunsFactory::gradeRun($runsData[2], 0.9, "PA");
     RunsFactory::gradeRun($runsData[3], 1, "AC", 180);
     RunsFactory::gradeRun($runDataDirector, 1, "AC", 120);
     RunsFactory::gradeRun($runDataAdmin, 1, "AC", 110);
     // Create API
     $response = ContestController::apiReport(new Request(array("contest_alias" => $contestData["request"]["alias"], "auth_token" => $this->login($contestDirector))));
     $this->assertEquals($problemData["request"]["alias"], $response["problems"][0]["alias"]);
     foreach ($contestants as $contestant) {
         $found = false;
         foreach ($response["ranking"] as $rank) {
             if ($rank["username"] == $contestant->username) {
                 $found = true;
                 break;
             }
         }
         $this->assertTrue($found);
     }
 }
예제 #10
0
 /**
  * Basic test of scoreboard, shows at least the run 
  * just submitted
  */
 public function testBasicScoreboard()
 {
     // Get a problem
     $problemData = ProblemsFactory::createProblem();
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestants
     $contestant = UserFactory::createUser();
     $contestant2 = UserFactory::createUser();
     $contestant3 = UserFactory::createUser();
     $contestDirector = $contestData["director"];
     $contestAdmin = UserFactory::createUser();
     ContestsFactory::addAdminUser($contestData, $contestAdmin);
     // Create runs
     $runData = RunsFactory::createRun($problemData, $contestData, $contestant);
     $runData1 = RunsFactory::createRun($problemData, $contestData, $contestant);
     $runData2 = RunsFactory::createRun($problemData, $contestData, $contestant2);
     $runData3 = RunsFactory::createRun($problemData, $contestData, $contestant3);
     $runDataDirector = RunsFactory::createRun($problemData, $contestData, $contestDirector);
     $runDataAdmin = RunsFactory::createRun($problemData, $contestData, $contestAdmin);
     // Grade the runs
     RunsFactory::gradeRun($runData, 0, "CE");
     RunsFactory::gradeRun($runData1);
     RunsFactory::gradeRun($runData2, 0.9, "PA");
     RunsFactory::gradeRun($runData3, 1, "AC", 180);
     RunsFactory::gradeRun($runDataDirector, 1, "AC", 120);
     RunsFactory::gradeRun($runDataAdmin, 1, "AC", 110);
     // Create request
     $r = new Request();
     $r["contest_alias"] = $contestData["request"]["alias"];
     $r["auth_token"] = $this->login($contestant);
     // Create API
     $response = ContestController::apiScoreboard($r);
     // Validate that we have ranking
     $this->assertEquals(3, count($response["ranking"]));
     $this->assertEquals($contestant->getUsername(), $response["ranking"][0]["username"]);
     //Check totals
     $this->assertEquals(100, $response["ranking"][0]["total"]["points"]);
     $this->assertEquals(60, $response["ranking"][0]["total"]["penalty"]);
     /* 60 because contest started 60 mins ago in the default factory */
     // Check places
     $this->assertEquals(1, $response["ranking"][0]["place"]);
     $this->assertEquals(2, $response["ranking"][1]["place"]);
     $this->assertEquals(3, $response["ranking"][2]["place"]);
     // Check data per problem
     $this->assertEquals(100, $response["ranking"][0]["problems"][0]["points"]);
     $this->assertEquals(60, $response["ranking"][0]["problems"][0]["penalty"]);
     $this->assertEquals(1, $response["ranking"][0]["problems"][0]["runs"]);
     // Now get the scoreboard as an contest director
     $r = new Request();
     $r["contest_alias"] = $contestData["request"]["alias"];
     $r["auth_token"] = $this->login($contestDirector);
     // Create API
     $response = ContestController::apiScoreboard($r);
     // Validate that we have ranking
     $this->assertEquals(3, count($response["ranking"]));
     $this->assertEquals($contestant->getUsername(), $response["ranking"][0]["username"]);
     //Check totals
     $this->assertEquals(100, $response["ranking"][0]["total"]["points"]);
     $this->assertEquals(60, $response["ranking"][0]["total"]["penalty"]);
     /* 60 because contest started 60 mins ago in the default factory */
     // Check places
     $this->assertEquals(1, $response["ranking"][0]["place"]);
     $this->assertEquals(2, $response["ranking"][1]["place"]);
     $this->assertEquals(3, $response["ranking"][2]["place"]);
     // Check data per problem
     $this->assertEquals(100, $response["ranking"][0]["problems"][0]["points"]);
     $this->assertEquals(60, $response["ranking"][0]["problems"][0]["penalty"]);
     $this->assertEquals(1, $response["ranking"][0]["problems"][0]["runs"]);
 }