Ejemplo n.º 1
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']);
 }
 /**
  * Tests remove group admins
  */
 public function testRemoveGroupAdmin()
 {
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Get users
     $user = UserFactory::createUser();
     $user2 = UserFactory::createUser();
     // Get a group
     $groupData = GroupsFactory::createGroup();
     GroupsFactory::addUserToGroup($groupData, $user);
     GroupsFactory::addUserToGroup($groupData, $user2);
     // Prepare request
     $r = new Request();
     $r['auth_token'] = $this->login($contestData['director']);
     $r['group'] = $groupData['request']['alias'];
     $r['contest_alias'] = $contestData['request']['alias'];
     // Call api
     ContestController::apiAddGroupAdmin($r);
     $contest = $contestData['contest'];
     $this->AssertTrue(Authorization::IsContestAdmin($user->getUserId(), $contest));
     $this->AssertTrue(Authorization::IsContestAdmin($user2->getUserId(), $contest));
     // Prepare request for remove the group
     $r = new Request();
     $r['auth_token'] = $this->login($contestData['director']);
     $r['group'] = $groupData['request']['alias'];
     $r['contest_alias'] = $contestData['request']['alias'];
     // Call api
     ContestController::apiRemoveGroupAdmin($r);
     $this->AssertFalse(Authorization::IsContestAdmin($user->getUserId(), $contest));
     $this->AssertFalse(Authorization::IsContestAdmin($user2->getUserId(), $contest));
 }
Ejemplo n.º 3
0
 /**
  * An added admin group should see those problems as well
  */
 public function testAllPrivateProblemsShowToAddedAdminGroup()
 {
     $author = UserFactory::createUser();
     $problemDataPrivate = ProblemsFactory::createProblem(null, null, 0, $author);
     $addedAdmin = UserFactory::createUser();
     $r = new Request();
     $r['auth_token'] = $this->login($addedAdmin);
     // Should not be contained in problem list.
     $response = ProblemController::apiList($r);
     $this->assertArrayNotContainsInKey($response['results'], 'alias', $problemDataPrivate['request']['alias']);
     $group = GroupsFactory::createGroup($addedAdmin);
     $r2 = new Request();
     $r2['auth_token'] = $this->login($author);
     $r2['problem_alias'] = $problemDataPrivate['request']['alias'];
     $r2['group'] = $group['group']->alias;
     $response = ProblemController::apiAddGroupAdmin($r2);
     $this->assertEquals('ok', $response['status']);
     // Now it should be visible.
     $response = ProblemController::apiList($r);
     $this->assertArrayContainsInKey($response['results'], 'alias', $problemDataPrivate['request']['alias']);
 }