Ejemplo n.º 1
0
 /**
  * Creates a valid clarification
  */
 public function testCreateValidClarification()
 {
     // Get a problem
     $problemData = ProblemsFactory::createProblem();
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestant who will submit the clarification
     $contestant = UserFactory::createUser();
     // Call the API
     $this->detourBroadcasterCalls();
     $clarificationData = ClarificationsFactory::createClarification($problemData, $contestData, $contestant);
     // Assert status of new contest
     $this->assertArrayHasKey("clarification_id", $clarificationData['response']);
     // Verify that clarification was inserted in the database
     $clarification = ClarificationsDAO::getByPK($clarificationData['response']['clarification_id']);
     // Verify our retreived clarificatoin
     $this->assertNotNull($clarification);
     $this->assertEquals($clarificationData['request']['message'], $clarification->getMessage());
     // We need to verify that the contest and problem IDs where properly saved
     // Extractiing the contest and problem from DB to check IDs
     $problem = ProblemsDAO::getByAlias($problemData["request"]["alias"]);
     $contest = ContestsDAO::getByAlias($contestData["request"]["alias"]);
     $this->assertEquals($contest->getContestId(), $clarification->getContestId());
     $this->assertEquals($problem->getProblemId(), $clarification->getProblemId());
 }
Ejemplo n.º 2
0
 static function DeleteClarificationsFromProblem($problem_id)
 {
     self::ConnectToDB();
     // Get clarifications
     $clarifications = ClarificationsDAO::getAll();
     // Delete those who belong to problem_id
     foreach ($clarifications as $c) {
         if ($c->getProblemId() == $problem_id) {
             try {
                 ClarificationsDAO::delete($c);
             } catch (ApiException $e) {
                 var_dump($e->getArrayMessage());
                 throw $e;
             }
         }
     }
     self::cleanup();
 }
 /**
  * Basic test for answer
  *
  */
 public function testUpdateAnswer()
 {
     // Get a problem
     $problemData = ProblemsFactory::createProblem();
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestant who will submit the clarification
     $contestant = UserFactory::createUser();
     // Create clarification
     $this->detourBroadcasterCalls($this->exactly(2));
     $clarificationData = ClarificationsFactory::createClarification($problemData, $contestData, $contestant);
     // Update answer
     $newAnswer = 'new answer';
     $response = ClarificationsFactory::answer($clarificationData, $contestData, $newAnswer);
     // Get clarification from DB
     $clarification = ClarificationsDAO::getByPK($clarificationData['response']['clarification_id']);
     // Validate that clarification stays the same
     $this->assertEquals($clarificationData['request']['message'], $clarification->getMessage());
     $this->assertEquals($clarificationData['request']['public'], $clarification->getPublic());
     // Validate our update
     $this->assertEquals($newAnswer, $clarification->getAnswer());
 }
 public function testPublicClarificationsCanBeViewed()
 {
     // Get a problem
     $problemData = ProblemsFactory::createProblem();
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestant who will submit the clarification
     $contestant = UserFactory::createUser();
     // Create our contestant who will try to view the clarification
     $contestant2 = UserFactory::createUser();
     // Create the clarification, note that contestant will create it
     $this->detourBroadcasterCalls();
     $clarificationData = ClarificationsFactory::createClarification($problemData, $contestData, $contestant);
     // Manually set the just created clarification to PUBLIC
     $clarification = ClarificationsDAO::getByPK($clarificationData['response']['clarification_id']);
     $clarification->setPublic('1');
     ClarificationsDAO::save($clarification);
     // Prepare the request object
     $r = new Request();
     $r['clarification_id'] = $clarificationData['response']['clarification_id'];
     // Log in with the author of the clarification
     $r['auth_token'] = $this->login($contestant2);
     // Call API
     $response = ClarificationController::apiDetails($r);
     // Check the data we got
     $this->assertClarification($r['clarification_id'], $response);
 }
Ejemplo n.º 5
0
 /**
  *
  * Get clarifications of a contest
  *
  * @param Request $r
  * @return array
  * @throws InvalidDatabaseOperationException
  */
 public static function apiClarifications(Request $r)
 {
     self::authenticateRequest($r);
     self::validateClarifications($r);
     $is_contest_director = Authorization::IsContestAdmin($r['current_user_id'], $r['contest']);
     try {
         $clarifications = ClarificationsDAO::GetContestClarifications($r['contest']->getContestId(), $is_contest_director, $r['current_user_id'], $r['offset'], $r['rowcount']);
     } catch (Exception $e) {
         // Operation failed in the data layer
         throw new InvalidDatabaseOperationException($e);
     }
     foreach ($clarifications as &$clar) {
         $clar['time'] = (int) $clar['time'];
     }
     // Add response to array
     $response = array();
     $response['clarifications'] = $clarifications;
     $response['status'] = "ok";
     return $response;
 }
Ejemplo n.º 6
0
 /**
  * Entry point for Problem clarifications API
  *
  * @param Request $r
  * @throws InvalidFilesystemOperationException
  * @throws InvalidDatabaseOperationException
  */
 public static function apiClarifications(Request $r)
 {
     // Get user
     self::authenticateRequest($r);
     self::validateRuns($r);
     $is_problem_admin = Authorization::CanEditProblem($r['current_user_id'], $r['problem']);
     try {
         $clarifications = ClarificationsDAO::GetProblemClarifications($r['problem']->problem_id, $is_problem_admin, $r['current_user_id'], $r['offset'], $r['rowcount']);
     } catch (Exception $e) {
         // Operation failed in the data layer
         throw new InvalidDatabaseOperationException($e);
     }
     foreach ($clarifications as &$clar) {
         $clar['time'] = (int) $clar['time'];
     }
     // Add response to array
     $response = array();
     $response['clarifications'] = $clarifications;
     $response['status'] = 'ok';
     return $response;
 }
Ejemplo n.º 7
0
 /**
  * Update a clarification
  * 
  * @param Request $r
  * @return array
  * @throws InvalidDatabaseOperationException
  */
 public static function apiUpdate(Request $r)
 {
     // Authenticate user
     self::authenticateRequest($r);
     // Validate request
     self::validateUpdate($r);
     // Update clarification
     $valueProperties = array("message", "answer", "public");
     $clarification = $r['clarification'];
     self::updateValueProperties($r, $clarification, $valueProperties);
     $r['clarification'] = $clarification;
     // Let DB handle time update
     $time = time();
     $clarification->time = gmdate('Y-m-d H:i:s', $time);
     // Save the clarification
     try {
         ClarificationsDAO::save($clarification);
     } catch (Exception $e) {
         // Operation failed in the data layer
         throw new InvalidDatabaseOperationException($e);
     }
     $r['problem'] = $r['contest'] = $r['user'] = null;
     self::clarificationUpdated($r, $time);
     $response = array();
     $response["status"] = "ok";
     return $response;
 }