public function testRemoveUser() { // Get a contest $contestData = ContestsFactory::createContest(); // Create a user $user = UserFactory::createUser(); // Add user to contest ContestsFactory::addUser($contestData, $user); // Validate 0 users $r = new Request(); $r['contest_alias'] = $contestData['request']['alias']; $r['auth_token'] = $this->login($contestData['director']); $response = ContestController::apiUsers($r); $this->assertEquals(1, count($response['users'])); // Remove user $r = new Request(); $r['contest_alias'] = $contestData['request']['alias']; $r['usernameOrEmail'] = $user->getUsername(); $r['auth_token'] = $this->login($contestData['director']); ContestController::apiRemoveUser($r); // Validate 0 users in contest $r = new Request(); $r['contest_alias'] = $contestData['request']['alias']; $r['auth_token'] = $this->login($contestData['director']); $response = ContestController::apiUsers($r); $this->assertEquals(0, count($response['users'])); }
/** * Returns a Request object with valid info to create a problem and the * author of the problem * * @param string $title * @param string $zipName * @return Array */ public static function getRequest($zipName = null, $title = null, $public = 1, Users $author = null, $languages = null) { if (is_null($author)) { $author = UserFactory::createUser(); } if (is_null($title)) { $title = Utils::CreateRandomString(); } if (is_null($zipName)) { $zipName = OMEGAUP_RESOURCES_ROOT . 'testproblem.zip'; } $r = new Request(); $r["title"] = $title; $r['alias'] = substr(preg_replace('/[^a-zA-Z0-9_-]/', '', str_replace(' ', '-', $r['title'])), 0, 32); $r["author_username"] = $author->getUsername(); $r["validator"] = "token"; $r["time_limit"] = 5000; $r["overall_wall_time_limit"] = 60000; $r["validator_time_limit"] = 30000; $r["extra_wall_time"] = 0; $r["memory_limit"] = 32000; $r["source"] = "yo"; $r["order"] = "normal"; $r["public"] = $public; $r["output_limit"] = 10240; if ($languages == null) { $r["languages"] = 'c,cpp,py'; } else { $r["languages"] = $languages; } $r["stack_limit"] = 10000; // Set file upload context $_FILES['problem_contents']['tmp_name'] = $zipName; return array("request" => $r, "author" => $author, "zip_path" => $zipName); }
/** * 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 testContestUsersValid() { // Get a contest $contestData = ContestsFactory::createContest(); // Create 10 users $n = 10; $users = array(); for ($i = 0; $i < $n; $i++) { // Create a user $users[$i] = UserFactory::createUser(); // Add it to the contest ContestsFactory::addUser($contestData, $users[$i]); } // Create a n+1 user who will just join to the contest withot being // added via API. For public contests, by entering to the contest, the user should be in // the list of contest's users. $nonRegisteredUser = UserFactory::createUser(); ContestsFactory::openContest($contestData, $nonRegisteredUser); // Prepare request $r = new Request(); $r["contest_alias"] = $contestData["request"]["alias"]; // Log in with the admin of the contest $r["auth_token"] = $this->login($contestData["director"]); // Call API $response = ContestController::apiUsers($r); // Check that we have n+1 users $this->assertEquals($n + 1, count($response["users"])); }
/** * 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"]); }
/** * 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()); }
/** * 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']); }
/** * Basic update test */ public function testUserUpdate() { // Create the user to edit $user = UserFactory::createUser(); $r = new Request(); // Login $r["auth_token"] = $this->login($user); // Change values $r["name"] = Utils::CreateRandomString(); $r["country_id"] = 'MX'; $r["state_id"] = 3; $r["scholar_degree"] = 'Maestría'; $r["birth_date"] = strtotime('1988-01-01'); $r["graduation_date"] = strtotime('2016-02-02'); // Call api $response = UserController::apiUpdate($r); // Check user from db $user_db = AuthTokensDAO::getUserByToken($r["auth_token"]); $this->assertEquals($user_db->getName(), $r["name"]); $this->assertEquals($user_db->getCountryId(), $r["country_id"]); $this->assertEquals($user_db->getStateId(), $r["state_id"]); $this->assertEquals($user_db->getScholarDegree(), $r["scholar_degree"]); $this->assertEquals($user_db->getBirthDate(), gmdate('Y-m-d', $r["birth_date"])); $this->assertEquals($user_db->getGraduationDate(), gmdate('Y-m-d', $r["graduation_date"])); }
/** * Returns a Request object with complete context to create a contest * * @param string $title * @param string $public * @param Users $contestDirector * @return Request */ public static function getRequest($title = null, $public = 0, Users $contestDirector = null, $languages = null) { if (is_null($contestDirector)) { $contestDirector = UserFactory::createUser(); } if (is_null($title)) { $title = Utils::CreateRandomString(); } // Set context $r = new Request(); $r["title"] = $title; $r["description"] = "description"; $r["start_time"] = Utils::GetPhpUnixTimestamp() - 60 * 60; $r["finish_time"] = Utils::GetPhpUnixTimestamp() + 60 * 60; $r["window_length"] = null; $r["public"] = $public; $r["alias"] = substr($title, 0, 20); $r["points_decay_factor"] = ".02"; $r["partial_score"] = "0"; $r["submissions_gap"] = "0"; $r["feedback"] = "yes"; $r["penalty"] = 100; $r["scoreboard"] = 100; $r["penalty_type"] = "contest_start"; $r["penalty_calc_policy"] = "sum"; $r['languages'] = $languages; return array("request" => $r, "director" => $contestDirector); }
/** * Returns a Request object with complete context to create a contest * * @param string $title * @param string $public * @param Users $contestDirector * @return Request */ public static function getRequest($title = null, $public = 0, Users $contestDirector = null, $languages = null, $finish_time = null) { if (is_null($contestDirector)) { $contestDirector = UserFactory::createUser(); } if (is_null($title)) { $title = Utils::CreateRandomString(); } // Set context $r = new Request(); $r['title'] = $title; $r['description'] = 'description'; $r['start_time'] = Utils::GetPhpUnixTimestamp() - 60 * 60; $r['finish_time'] = $finish_time == null ? Utils::GetPhpUnixTimestamp() + 60 * 60 : $finish_time; $r['window_length'] = null; $r['public'] = $public; $r['alias'] = substr($title, 0, 20); $r['points_decay_factor'] = '.02'; $r['partial_score'] = '0'; $r['submissions_gap'] = '0'; $r['feedback'] = 'yes'; $r['penalty'] = 100; $r['scoreboard'] = 100; $r['penalty_type'] = 'contest_start'; $r['penalty_calc_policy'] = 'sum'; $r['languages'] = $languages; $r['recommended'] = 0; // This is just a default value, it is not honored by apiCreate. return array('request' => $r, 'director' => $contestDirector); }
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); }
public function testCoderOfTheMonthList() { $user = UserFactory::createUser(); $auth_token = $this->login($user); $r = new Request(array('auth_token' => $auth_token)); $response = UserController::apiCoderOfTheMonthList($r); $this->assertEquals(1, count($response['coders'])); }
/** * Prepares and returns an article * * @param User $user * @param str $title * @param int $count * * @return Article */ public function prepareArticle(User $user = null, $title = null, $count = 1) { if (!$user) { $user = $this->userFactory->createUser(); } $article = $this->articleFactory->createArticle($user, $title, $count); return $article; }
public function testNoProblems() { $author = UserFactory::createUser(); // Call API // Call api $r = new Request(array("auth_token" => self::login($author))); $response = UserController::apiProblems($r); $this->assertEquals(0, count($response["problems"])); }
/** * @expectedException InvalidDatabaseOperationException */ public function testBadUserUpdate() { $user = UserFactory::createUser(); $r = new Request(); $r['auth_token'] = $this->login($user); $r['name'] = Utils::CreateRandomString(); // Invalid state_id $r['state_id'] = -1; UserController::apiUpdate($r); }
/** * Tests apiRankByProblemsSolved for a specific user with no runs */ public function testUserRankByProblemsSolvedWith0Runs() { // Create a user and sumbit a run with him $contestant = UserFactory::createUser(); // Call API $response = UserController::apiRankByProblemsSolved(new Request(array('username' => $contestant->getUsername()))); $this->assertEquals($response['name'], $contestant->getName()); $this->assertEquals($response['problems_solved'], 0); $this->assertEquals($response['rank'], 0); }
/** * Reset my password * * @expectedException InvalidParameterException */ public function testResetMyPasswordBadOldPassword() { // Create an user in omegaup $user = UserFactory::createUser(); $r = new Request(); $r["auth_token"] = $this->login($user); $r["username"] = $user->getUsername(); $r["password"] = Utils::CreateRandomString(); $r["old_password"] = "******"; // Call api UserController::apiChangePassword($r); }
/** * */ public function testCreateSchoolDuplicatedName() { $user = UserFactory::createUser(); $r = new Request(array('auth_token' => $this->login($user), 'name' => Utils::CreateRandomString())); // Call api $response = SchoolController::apiCreate($r); $this->assertEquals('ok', $response['status']); $this->assertEquals(1, count(SchoolsDAO::findByName($r['name']))); // Call api again $response = SchoolController::apiCreate($r); $this->assertEquals('ok', $response['status']); $this->assertEquals(1, count(SchoolsDAO::findByName($r['name']))); }
/** * * @expectedException ForbiddenAccessException */ public function testUpdateContestNonDirector() { // Get a contest $contestData = ContestsFactory::createContest(); // Prepare request $r = new Request(); $r["contest_alias"] = $contestData["request"]["alias"]; // Log in with contest director $r["auth_token"] = $this->login(UserFactory::createUser()); // Update title $r["title"] = Utils::CreateRandomString(); // Call API ContestController::apiUpdate($r); }
public function testContestActivityReport() { // Get a contest $contestData = ContestsFactory::createContest(); $user = UserFactory::createUser(); ContestsFactory::openContest($contestData, $user); ContestController::apiDetails(new Request(array('contest_alias' => $contestData['request']['alias'], 'auth_token' => $this->login($user)))); // Call API $response = ContestController::apiActivityReport(new Request(array('contest_alias' => $contestData['request']['alias'], 'auth_token' => $this->login($contestData['director'])))); // Check that we have entries in the log. $this->assertEquals(1, count($response['events'])); $this->assertEquals($user->username, $response['events'][0]['username']); $this->assertEquals(0, $response['events'][0]['ip']); $this->assertEquals('open', $response['events'][0]['event']['name']); }
/** * 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"]); }
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]'); }
public function testLogin() { // Turn off sending email on usere creation UserController::$sendEmailOnVerify = false; // Create a user $contestant = UserFactory::createUser(); // Open index $this->open('/'); // Click in Iniciar Sesion $this->clickAndWait('link=Inicia sesion'); // Type login data $this->type('user', $contestant->getUsername()); $this->type('pass', $contestant->getPassword()); // Click inicia sesion $this->clickAndWait("//input[@value='Inicia sesion']"); // Sanity check that we are logged in $this->waitForElementPresent('//*[@id="wrapper"]/div[1]/a'); $this->assertElementContainsText('//*[@id="wrapper"]/div[1]/a', $contestant->getUsername()); }
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)); }
/** * Create group * * @param type $owner * @param type $name * @param type $description */ public static function createGroup($owner = null, $name = null, $description = null, $alias = null) { if (is_null($owner)) { $owner = UserFactory::createUser(); } if (is_null($name)) { $name = Utils::CreateRandomString(); } if (is_null($description)) { $description = Utils::CreateRandomString(); } if (is_null($alias)) { $alias = Utils::CreateRandomString(); } $r = new Request(array("auth_token" => OmegaupTestCase::login($owner), "name" => $name, "description" => $description, "alias" => $alias)); $response = GroupController::apiCreate($r); $groups = GroupsDAO::search(new Groups(array("alias" => $alias))); return array("request" => $r, "response" => $response, "owner" => $owner, "group" => $groups[0]); }
/** * 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"]); }
/** * 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"]); }
/** * 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)); }
/** * 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"]); }