ProjectCommands::updateUserRole($testProjectId, $observerUserId, LexRoles::OBSERVER); $testProjectModel = new LexProjectModel($testProjectId); $testProjectModel->addInputSystem('th-fonipa', 'tipa', 'Thai'); $testProjectModel->config->entry->fields[LexConfig::LEXEME]->inputSystems[] = 'th-fonipa'; $testProjectModel->addInputSystem('th-Zxxx-x-audio', 'taud', 'Thai Voice'); $testProjectModel->config->entry->fields[LexConfig::LEXEME]->inputSystems[] = 'th-Zxxx-x-audio'; $testProjectId = $testProjectModel->write(); // setup to mimic file upload $fileName = $constants['testEntry1']['lexeme']['th-Zxxx-x-audio']['value']; $file = array(); $file['name'] = $fileName; $_FILES['file'] = $file; // put a copy of the test file in tmp $tmpFilePath = sys_get_temp_dir() . "/CopyOf{$fileName}"; copy(TestPath . "php/common/{$fileName}", $tmpFilePath); $response = LexUploadCommands::uploadAudioFile($testProjectId, 'audio', $tmpFilePath); // cleanup tmp file if it still exists if (file_exists($tmpFilePath) and !is_dir($tmpFilePath)) { @unlink($tmpFilePath); } // put uploaded file into entry1 $constants['testEntry1']['lexeme']['th-Zxxx-x-audio']['value'] = $response->data->fileName; // setup to mimic file upload $fileName = $constants['testEntry1']['senses'][0]['pictures'][0]['fileName']; $file = array(); $file['name'] = $fileName; $_FILES['file'] = $file; // put a copy of the test file in tmp $tmpFilePath = sys_get_temp_dir() . "/CopyOf{$fileName}"; copy(TestPath . "php/common/{$fileName}", $tmpFilePath); $response = LexUploadCommands::uploadImageFile($testProjectId, 'sense-image', $tmpFilePath);
public function lex_uploadAudioFile($mediaType, $tmpFilePath) { $response = LexUploadCommands::uploadAudioFile($this->projectId, $mediaType, $tmpFilePath); return JsonEncoder::encode($response); }
public function testDeleteMediaFile_Mp3File_FileDeleted() { $project = self::$environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $projectId = $project->id->asString(); $fileName = 'TestAudio.mp3'; $tmpFilePath = self::$environ->uploadFile(TestPhpPath . "common/{$fileName}", $fileName); $response = LexUploadCommands::uploadAudioFile($projectId, 'audio', $tmpFilePath); $this->assertTrue($response->result, 'Upload should succeed'); $folderPath = $project->getAudioFolderPath(); $fileName = $response->data->fileName; $filePath = $folderPath . '/' . $fileName; $this->assertTrue(file_exists($filePath), 'Uploaded audio file should exist'); $response = LexUploadCommands::deleteMediaFile($projectId, 'audio', $fileName); $this->assertTrue($response->result, 'Delete should succeed'); $this->assertFalse(file_exists($filePath), 'Audio file should be deleted'); }