public function testEncode_Project_DtoCorrect() { $environ = new LexiconMongoTestEnvironment(); $environ->clean(); $userId = $environ->createUser('User', 'Name', '*****@*****.**'); $user = new UserProfileModel($userId); $user->role = SystemRoles::USER; $project = $environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $projectId = $project->id->asString(); $project->addUser($userId, ProjectRoles::CONTRIBUTOR); $user->addProject($projectId); $user->interfaceLanguageCode = 'th'; $user->write(); $project->write(); $dto = LexBaseViewDto::encode($projectId, $userId); // test for a few default values $this->assertEquals('en', $dto['config']['inputSystems']['en']['tag']); $this->assertTrue($dto['config']['tasks']['dbe']['visible']); $this->assertEquals('fields', $dto['config']['entry']['type'], 'dto config is not valid'); $this->assertEquals('Word', $dto['config']['entry']['fields']['lexeme']['label']); $this->assertEquals('Word', $dto['config']['entry']['fields']['lexeme']['label']); $this->assertEquals('Part of Speech', $dto['config']['entry']['fields']['senses']['fields']['partOfSpeech']['label']); $this->assertTrue($dto['config']['roleViews']['contributor']['fields']['lexeme']['show']); $this->assertTrue($dto['config']['roleViews']['contributor']['showTasks']['dbe']); // todo re-enable this after userLanguageCode feature is mature //$this->assertEquals('th', $dto['interfaceConfig']['userLanguageCode']); $this->assertEquals('English', $dto['interfaceConfig']['selectLanguages']['options']['en']); }
public function testUpdateConfig_ConfigPersists() { $e = new LexiconMongoTestEnvironment(); $e->clean(); $userId = $e->createUser("User", "Name", "*****@*****.**"); $user = new UserModel($userId); $user->role = SystemRoles::USER; $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $projectId = $project->id->asString(); $project->addUser($userId, ProjectRoles::CONTRIBUTOR); $user->addProject($projectId); $user->write(); $project->write(); $config = json_decode(json_encode(LexBaseViewDto::encode($projectId, $userId)['config']), true); $this->assertTrue($config['tasks']['addMeanings']['visible']); $this->assertEqual($config['entry']['fields']['lexeme']['inputSystems'][0], 'th'); $config['tasks']['addMeanings']['visible'] = false; $config['entry']['fields']['lexeme']['inputSystems'] = array('my', 'th'); LexProjectCommands::updateConfig($projectId, $config); $project2 = new LexiconProjectModel($projectId); // test for a few default values $this->assertEqual($project2->inputSystems['en']->tag, 'en'); $this->assertTrue($project2->config->tasks['dbe']->visible); $this->assertEqual($project2->config->entry->fields['lexeme']->label, 'Word'); // test for updated values $this->assertFalse($project2->config->tasks['addMeanings']->visible); $this->assertEqual($project2->config->entry->fields['lexeme']->inputSystems[0], 'my'); $this->assertEqual($project2->config->entry->fields['lexeme']->inputSystems[1], 'th'); }
public function testUpdateList_newList_createsOK() { $e = new LexiconMongoTestEnvironment(); $e->clean(); $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $optionlists = new LexOptionListListModel($project); $optionlists->read(); // Initial project has no optionlists populated $this->assertEqual($optionlists->count, 0); // Initialized project has part of speech optionlist defined $project->initializeNewProject(); $optionlists->read(); $this->assertEqual($optionlists->count, 1); $initialValue = $optionlists->entries[0]['items'][0]['value']; $this->assertEqual($initialValue, 'Adjective (adj)'); // Swap first and last items of parts of speech list $count = count($optionlists->entries[0]['items']); $swap = $optionlists->entries[0]['items'][0]; $optionlists->entries[0]['items'][0] = $optionlists->entries[0]['items'][$count - 1]; $optionlists->entries[0]['items'][$count - 1] = $swap; LexOptionListCommands::updateList($project->id->asString(), $optionlists->entries[0]); $optionlists->read(); $newValue = $optionlists->entries[0]['items'][0]['value']; $this->assertEqual($newValue, 'Verb (v)'); // Create part of speech list for fruits $fruits = array(array('key' => 'a', 'value' => 'apple'), array('key' => 'b', 'value' => 'berry'), array('key' => 'c', 'value' => 'cherry'), array('key' => 'g', 'value' => 'grape'), array('key' => 'm', 'value' => 'mango'), array('key' => 'p', 'value' => 'pineapple')); $data = array('id' => '', 'name' => 'List of Fruits', 'code' => 'fruits', 'items' => $fruits, 'canDelete' => false); LexOptionListCommands::updateList($project->id->asString(), $data); $optionlists->read(); $this->assertEqual($optionlists->count, 2); }
public function testInitializeNewProject_defaultPartOfSpeechOptionListExists() { $e = new LexiconMongoTestEnvironment(); $e->clean(); $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $optionlists = new \Api\Model\Languageforge\Lexicon\LexOptionListListModel($project); $optionlists->read(); $this->assertEqual(count($optionlists->entries), 0); $project = \Api\Model\ProjectModel::getById($project->id->asString()); $project->initializeNewProject(); $optionlists->read(); $this->assertTrue(count($optionlists->entries) > 0); $this->assertEqual($optionlists->entries[0]['items'][0]['key'], 'adj'); }
public function testLiftImportMerge_LargeFile_NoException() { global $testInfo; $testInfo = new TestLiftImportInfo(); $e = new LexiconMongoTestEnvironment(); $e->clean(); $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); // $liftFilePath = '/home/cambell/src/Forge/TestData/Gilaki/Gilaki.lift'; $liftFilePath = '/home/cambell/src/Forge/TestData/Webster/Webster.lift'; $mergeRule = LiftMergeRule::IMPORT_WINS; $skipSameModTime = false; LiftImport::get()->merge($liftFilePath, $project, $mergeRule, $skipSameModTime); $testInfo->add('post merge'); }
public function testLiftImportMerge_LargeFile_NoException() { global $testInfo; $testInfo = new TestLiftImportInfo(); $environ = new LexiconMongoTestEnvironment(); $environ->clean(); $project = $environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); // $liftFilePath = '/home/cambell/src/Forge/TestData/Gilaki/Gilaki.lift'; // $liftFilePath = '/home/cambell/src/Forge/TestData/Webster/Webster.lift'; // $liftFilePath = '/home/ira/TestData/test-langprojih-flex/test-langprojih-flex.lift'; $liftFilePath = '/home/ira/TestData/test-rwr-flex/test-rwr-flex.lift'; $mergeRule = LiftMergeRule::IMPORT_WINS; $skipSameModTime = false; $time1 = new DateTime(); LiftImport::get()->merge($liftFilePath, $project, $mergeRule, $skipSameModTime); $time2 = new DateTime(); $elapsed = $time2->diff($time1); echo $elapsed->format('%I:%S') . '<br/>'; $testInfo->add('post merge'); }
public function testSendJoinRequestAccepted_PropertiesFromToBodyOk() { $e = new LexiconMongoTestEnvironment(); $e->clean(); $userId = $e->createUser('User', 'Name', '*****@*****.**'); $user = new UserModel($userId); $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $delivery = new MockCommunicateDelivery(); Communicate::sendJoinRequestAccepted($user, $project, $e->website, $delivery); // What's in the delivery? $senderEmail = 'no-reply@' . $e->website->domain; $expectedFrom = array($senderEmail => $e->website->name); $expectedTo = array($user->email => $user->name); $this->assertEqual($expectedFrom, $delivery->from); $this->assertEqual($expectedTo, $delivery->to); $this->assertPattern('/' . SF_TESTPROJECT . '/', $delivery->subject); $this->assertPattern('/' . $e->website->name . '/', $delivery->subject); $this->assertPattern('/' . SF_TESTPROJECT . '/', $delivery->content); $this->assertPattern('/has been accepted/', $delivery->content); $this->assertPattern('/' . $e->website->domain . '\\/app\\/semdomtrans/', $delivery->content); }
public function testListEntries_someEntriesWithNoDefinition_Ok() { $e = new LexiconMongoTestEnvironment(); $e->clean(); $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $projectId = $project->id->asString(); for ($i = 0; $i < 10; $i++) { $entry = new LexEntryModel($project); $entry->lexeme->form('th', 'Apfel' . $i); if ($i % 2 == 0) { $sense = new Sense(); $entry->senses[] = $sense; } if ($i % 3 == 0) { $sense = new Sense(); $sense->definition->form('en', 'apple'); $sense->partOfSpeech->value = 'noun'; $entry->senses[] = $sense; } $entry->write(); } $result = LexEntryCommands::listEntries($projectId); $this->assertEqual($result->entries[0]['lexeme']['th']['value'], 'Apfel0'); $this->assertTrue(!array_key_exists('definition', $result->entries[0]['senses'][0])); $this->assertEqual($result->entries[3]['senses'][0]['definition']['en']['value'], 'apple'); }
public function testCreateCustomFieldsViews_CreateTwoCustomFieldViewsViaRunClass_TwoCreated() { $environ = new LexiconMongoTestEnvironment(); $environ->clean(); // setup: 1 custom field to delete (senses), 2 to create (entry and example) $project = $environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $customFieldName = 'customField_senses_testOptionList'; $viewFieldConfig = new LexViewFieldConfig(); $viewFieldConfig->type = 'ReferenceAtom'; $project->config->roleViews[LexRoles::MANAGER]->fields[$customFieldName] = $viewFieldConfig; $projectId = $project->write(); $customFieldSpecs = array(array('fieldName' => 'customField_entry_testMultiText', 'fieldType' => 'MultiString'), array('fieldName' => 'customField_examples_testOptionList', 'fieldType' => 'ReferenceAtom')); // execute $runClassParameters = array('className' => 'Api\\Model\\Languageforge\\Lexicon\\Command\\LexProjectCommands', 'methodName' => 'updateCustomFieldViews', 'parameters' => array($project->projectCode, $customFieldSpecs), 'isTest' => true); $runClassParameterFilePath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'testCustomFieldsViews.json'; file_put_contents($runClassParameterFilePath, json_encode($runClassParameters)); $command = 'php ' . APPPATH . 'Api/Library/Shared/CLI/RunClass.php < ' . $runClassParameterFilePath; $output = shell_exec($command); unlink($runClassParameterFilePath); $result = json_decode($output); // verify $this->assertEquals($projectId, $result); $project2 = new LexProjectModel($projectId); $this->assertArrayNotHasKey($customFieldName, $project2->config->roleViews[LexRoles::MANAGER]->fields); $customFieldName = $customFieldSpecs[0]['fieldName']; $customField0 = $project2->config->roleViews[LexRoles::MANAGER]->fields[$customFieldName]; $this->assertTrue(is_a($customField0, 'Api\\Model\\Languageforge\\Lexicon\\Config\\LexViewMultiTextFieldConfig')); $customFieldName = $customFieldSpecs[1]['fieldName']; $customField1 = $project2->config->roleViews[LexRoles::MANAGER]->fields[$customFieldName]; $this->assertTrue(is_a($customField1, 'Api\\Model\\Languageforge\\Lexicon\\Config\\LexViewFieldConfig')); }
/** * Cleanup test lift files */ public function tearDown() { $this->environ->clean(); $this->environ->cleanupTestFiles($this->environ->project->getAssetsFolderPath()); }
function testReadEntry_NoComments_ReadBackOk() { $e = new LexiconMongoTestEnvironment(); $e->clean(); $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $projectId = $project->id->asString(); $entry = new LexEntryModel($project); $entry->lexeme->form('th', 'apple'); $sense = new Sense(); $sense->definition->form('en', 'red fruit'); $sense->partOfSpeech = new LexiconField('noun'); $example = new Example(); $example->sentence->form('th', 'example1'); $example->translation->form('en', 'trans1'); $sense->examples[] = $example; $entry->senses[] = $sense; $entryId = $entry->write(); $newEntry = LexEntryCommands::readEntry($projectId, $entryId); $this->assertEqual($newEntry['lexeme']['th']['value'], 'apple'); $this->assertEqual($newEntry['senses'][0]['definition']['en']['value'], 'red 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'); }
/** * Cleanup test lift files */ public function tearDown() { $this->environ->cleanupTestUploadFiles(); $this->environ->clean(); }
public function testPlusOneComment_UserAlready_ScoreIsSame() { $environ = new LexiconMongoTestEnvironment(); $environ->clean(); $project = $environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $user1Id = $environ->createUser('joe', 'joe', 'joe'); $regarding = array('field' => 'lexeme', 'fieldValue' => 'Word 1', 'inputSystem' => 'th', 'word' => '', 'meaning' => ''); $data = array('id' => '', 'content' => 'hi there!', 'regarding' => $regarding); $commentId = LexCommentCommands::updateComment($project->id->asString(), $user1Id, $environ->website, $data); $comment = new LexCommentModel($project, $commentId); $this->assertEquals(0, $comment->score); LexCommentCommands::plusOneComment($project->id->asString(), $user1Id, $commentId); LexCommentCommands::plusOneComment($project->id->asString(), $user1Id, $commentId); $comment->read($commentId); $this->assertEquals(1, $comment->score); }