function testReturnsNonCompletedProject() { $this->setValidProjectWithAllTranslatedSegments(); // get project chunks $chunksDao = new Chunks_ChunkDao(Database::obtain()); $chunks = $chunksDao->getByProjectID($this->test_data->project->id_project); $this->assertEquals(1, count($chunks)); $chunk = $chunks[0]; // split job in two $splitTest = new CurlTest(); $params = array('action' => 'splitJob', 'exec' => 'apply', 'project_id' => $this->test_data->project->id_project, 'project_pass' => $this->test_data->project->project_pass, 'job_id' => $chunk->id, 'job_pass' => $chunk->password, 'num_split' => 2, 'split_values' => array('5', '1')); $splitTest->params = $params; $splitTest->method = 'POST'; $response = $splitTest->getResponse(); $chunks = $chunksDao->getByProjectID($this->test_data->project->id_project); $this->assertEquals(2, count($chunks)); $first_chunk = $chunks[0]; $second_chunk = $chunks[1]; integrationSetChunkAsComplete(array('params' => array('id_job' => $first_chunk->id, 'password' => $first_chunk->password))); $test = new CurlTest(); $test->path = '/api/v2/project-completion-status/' . $this->test_data->project->id_project; $test->method = 'GET'; $test->headers = $this->test_data->headers; $response = $test->getResponse(); $expected = array('project_status' => array('id' => $this->test_data->project->id_project, 'completed' => false, 'chunks' => array(array('id' => $second_chunk->id, 'password' => $second_chunk->password)))); $this->assertEquals(json_encode($expected), $response['body']); }
function integrationSetTranslation($options) { $default = array('translation' => "simulated translation during tests", 'id_translator' => false, 'version' => time(), 'propagate' => false, 'status' => 'draft'); $test = new CurlTest(); $test->params = array_merge($default, $options); $test->method = 'POST'; $test->path = '?action=setTranslation'; $response = $test->getResponse(); if (!in_array((int) $response['code'], array(200, 201))) { throw new Exception("invalid response code " . $response['code']); } $body = json_decode($response['body'], true); if (!empty($body['errors'])) { throw new Exception("Ajax error detected " . var_export($body['errors'], true)); } return $body; }
function makeRequest() { $curlTest = new CurlTest(array('path' => $this->path, 'headers' => $this->headers, 'method' => $this->method, 'params' => $this->params, 'files' => $this->files)); return $curlTest->getResponse(); }