$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); // cleanup tmp file if it still exists if (file_exists($tmpFilePath) and !is_dir($tmpFilePath)) { @unlink($tmpFilePath); } // put uploaded file into entry1 $constants['testEntry1']['senses'][0]['pictures'][0]['fileName'] = $response->data->fileName; $entry1 = LexEntryCommands::updateEntry($testProjectId, array('id' => '', 'lexeme' => $constants['testEntry1']['lexeme'], 'senses' => $constants['testEntry1']['senses']), $managerUserId); $entry2 = LexEntryCommands::updateEntry($testProjectId, array('id' => '', 'lexeme' => $constants['testEntry2']['lexeme'], 'senses' => $constants['testEntry2']['senses']), $managerUserId); $multipleMeaningEntry1 = LexEntryCommands::updateEntry($testProjectId, array('id' => '', 'lexeme' => $constants['testMultipleMeaningEntry1']['lexeme'], 'senses' => $constants['testMultipleMeaningEntry1']['senses']), $managerUserId); // put mock uploaded zip import (jpg file) $fileName = $constants['testMockJpgImportFile']['name']; $tmpFilePath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $fileName; copy(TestPath . "php/common/{$fileName}", $tmpFilePath); // put mock uploaded zip import (zip file) $fileName = $constants['testMockZipImportFile']['name'];
public function lex_upload_importLift($mediaType, $tmpFilePath) { $response = LexUploadCommands::importLiftFile($this->projectId, $mediaType, $tmpFilePath); return JsonEncoder::encode($response); }
public function testImportLift_JpgFile_UploadDisallowed() { $project = $this->environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $projectId = $project->id->asString(); $tmpFilePath = $this->environ->uploadLiftFile(self::liftOneEntryV0_13, 'OneEntryV0_13.jpg', LiftMergeRule::IMPORT_LOSES); $response = LexUploadCommands::importLiftFile($projectId, 'import-lift', $tmpFilePath); $this->assertFalse($response->result, 'Import should fail'); $this->assertEqual('UserMessage', $response->data->errorType, 'Error response should be a user message'); $this->assertPattern('/not an allowed LIFT file/', $response->data->errorMessage, 'Error message should match the error'); $tmpFilePath = $this->environ->uploadFile(TestPath . 'common/TestImage.jpg', 'TestImage.lift'); $response = LexUploadCommands::importLiftFile($projectId, 'import-lift', $tmpFilePath); $this->assertFalse($response->result, 'Import should fail'); $this->assertEqual('UserMessage', $response->data->errorType, 'Error response should be a user message'); $this->assertPattern('/not an allowed LIFT file/', $response->data->errorMessage, 'Error message should match the error'); }