public function lex_entry_update($model)
 {
     return LexEntryCommands::updateEntry($this->projectId, $model, $this->userId);
 }
 public function testUpdateEntry_ClearedData_DataIsCleared()
 {
     $project = self::$environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE);
     $projectId = $project->id->asString();
     $entry = new LexEntryModel($project);
     $entry->lexeme->form('th', 'apple');
     $entryId = $entry->write();
     $params = json_decode(json_encode(LexEntryCommands::readEntry($projectId, $entryId)), true);
     $params['lexeme']['th']['value'] = '';
     $userId = self::$environ->createUser('john', 'john', 'john');
     LexEntryCommands::updateEntry($projectId, $params, $userId);
     $updatedEntry = LexEntryCommands::readEntry($projectId, $entryId);
     $this->assertEquals('', $updatedEntry['lexeme']['th']['value']);
 }
 public function testUpdateEntry_DataPersists()
 {
     $e = new LexiconMongoTestEnvironment();
     $e->clean();
     $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE);
     $projectId = $project->id->asString();
     $userId = $e->createUser('john', 'john', 'john');
     $entry = new LexEntryModel($project);
     $entry->lexeme->form('th', 'apple');
     $sense = new Sense();
     $sense->definition->form('en', 'red fruit');
     $sense->gloss->form('en', 'rose fruit');
     $sense->partOfSpeech->value = 'noun';
     $example = new Example();
     $example->sentence->form('th', 'example1');
     $example->translation->form('en', 'trans1');
     $sense->examples[] = $example;
     $entry->senses[] = $sense;
     $entryId = $entry->write();
     $params = json_decode(json_encode(LexEntryCommands::readEntry($projectId, $entryId)), true);
     $params['lexeme']['th']['value'] = 'rose apple';
     LexEntryCommands::updateEntry($projectId, $params, $userId);
     $newEntry = LexEntryCommands::readEntry($projectId, $entryId);
     $this->assertEqual($newEntry['lexeme']['th']['value'], 'rose apple');
     $this->assertEqual($newEntry['senses'][0]['definition']['en']['value'], 'red fruit');
     $this->assertEqual($newEntry['senses'][0]['gloss']['en']['value'], 'rose fruit');
     $this->assertEqual($newEntry['senses'][0]['partOfSpeech']['value'], 'noun');
     $this->assertEqual($newEntry['senses'][0]['examples'][0]['sentence']['th']['value'], 'example1');
     $this->assertEqual($newEntry['senses'][0]['examples'][0]['translation']['en']['value'], 'trans1');
 }
 $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'];
 $tmpFilePath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $fileName;
 copy(TestPath . "php/common/{$fileName}", $tmpFilePath);
 // put mock uploaded audio (png file)
 $fileName = $constants['testMockPngUploadFile']['name'];
 $tmpFilePath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $fileName;
 copy(TestPath . "php/common/{$fileName}", $tmpFilePath);
 // put mock uploaded audio (mp3 file)
 $fileName = $constants['testMockMp3UploadFile']['name'];
 $tmpFilePath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $fileName;