/** * */ public static function createProblem($zipName = null, $title = null, $public = 1, Users $author = null, $languages = null) { if (is_null($zipName)) { $zipName = OMEGAUP_RESOURCES_ROOT . 'testproblem.zip'; } // Get a user $problemData = self::getRequest($zipName, $title, $public, $author, $languages); $r = $problemData["request"]; $problemAuthor = $problemData["author"]; // Login user $r["auth_token"] = OmegaupTestCase::login($problemAuthor); // Get File Uploader Mock and tell Omegaup API to use it FileHandler::SetFileUploader(new FileUploaderMock()); // Call the API ProblemController::apiCreate($r); // Clean up our mess unset($_REQUEST); return array("request" => $r, "author" => $problemAuthor); }
/** * Basic test for uploadin problem missing outputs * * @expectedException InvalidParameterException */ public function testCreateProblemMissingOutput() { // Get the problem data $problemData = ProblemsFactory::getRequest(OMEGAUP_RESOURCES_ROOT . 'missingout.zip'); $r = $problemData['request']; $problemAuthor = $problemData['author']; // Login user $r['auth_token'] = $this->login($problemAuthor); // Get File Uploader Mock and tell Omegaup API to use it FileHandler::SetFileUploader($this->createFileUploaderMock()); // Call the API $response = ProblemController::apiCreate($r); }
/** * Tests update problem: on error, original contents should persist */ public function testUpdateProblemFailed() { // Get a problem $problemData = ProblemsFactory::createProblem(); // Get File Uploader Mock and tell Omegaup API to use it FileHandler::SetFileUploader($this->createFileUploaderMock()); // Update Problem calls grader to rejudge, we need to detour grader calls // We will submit 2 runs to the problem, so we can expect 2 calls to grader // to rejudge them $this->detourGraderCalls($this->exactly(0)); // Prepare request $r = new Request(); $r['title'] = 'new title'; $r['time_limit'] = 12345; $r['problem_alias'] = $problemData['request']['alias']; $r['message'] = 'This shoudl fail'; // Set file upload context. This problem should fail $_FILES['problem_contents']['tmp_name'] = OMEGAUP_RESOURCES_ROOT . 'nostmt.zip'; // Log in as contest director $r['auth_token'] = $this->login($problemData['author']); // Call API. Should fail try { ProblemController::apiUpdate($r); } catch (InvalidParameterException $e) { // Expected } // Verify contents were not erased $targetpath = PROBLEMS_PATH . DIRECTORY_SEPARATOR . $r['problem_alias'] . DIRECTORY_SEPARATOR; $temppath = PROBLEMS_PATH . DIRECTORY_SEPARATOR . $r['problem_alias'] . '_tmp' . DIRECTORY_SEPARATOR; $this->assertFileNotExists($temppath); $this->assertFileExists($targetpath . 'cases'); $this->assertFileExists($targetpath . 'statements' . DIRECTORY_SEPARATOR . 'es.html'); // Check statements still is the original one $statement = file_get_contents($targetpath . 'statements' . DIRECTORY_SEPARATOR . 'es.html'); $this->assertContains('<h1>Entrada</h1>', $statement); }