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 testLiftImportMerge_ZipFile2LiftAndOddFolder_Error()
 {
     $zipFilePath = $this->environ->copyTestUploadFile(TestPath . 'common/TestLex2ProjectsOddFolder.zip');
     $project = $this->environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE);
     $importer = LiftImport::get()->importZip($zipFilePath, $project);
     $report = $importer->getReport();
     $reportStr = $report->toString();
     $this->assertTrue($report->hasError(), 'should have NodeError');
     $this->assertPattern("/unhandled LIFT file/", $reportStr);
     $this->assertPattern("/unhandled subfolder 'OddFolder'/", $reportStr);
 }
 public function testLiftImportMerge_FlexAllFields_HasAllFields()
 {
     $liftFilePath = $this->environ->createTestLiftFile(self::liftAllFlexFields, 'LiftAllFlexFields.lift');
     $project = $this->environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE);
     $mergeRule = LiftMergeRule::IMPORT_WINS;
     $skipSameModTime = false;
     LiftImport::get()->merge($liftFilePath, $project, $mergeRule, $skipSameModTime);
     $entryList = new LexEntryListModel($project);
     $entryList->read();
     $entries = $entryList->entries;
     $this->assertEqual($entryList->count, 2);
     $entriesByGuid = $this->environ->indexItemsBy($entries, 'guid');
     $entry0 = new LexEntryModel($project, $entriesByGuid['0a18bb95-0eb2-422e-bf7e-c1fd90274670']['id']);
     $entry1 = new LexEntryModel($project, $entriesByGuid['dc4106ac-13fd-4ae0-a32b-b737f413d515']['id']);
     $this->assertEqual($entry0->guid, '0a18bb95-0eb2-422e-bf7e-c1fd90274670');
     $this->assertEqual($entry0->lexeme['th'], 'คาม');
     $this->assertEqual($entry0->citationForm['th'], 'คาม');
     $this->assertEqual($entry0->etymology['th'], 'คาม');
     $this->assertEqual($entry0->etymology['en'], 'A Etymology');
     $this->assertEqual($entry0->etymologyGloss['en'], 'A Etymology Gloss');
     $this->assertEqual($entry0->etymologyComment['en'], 'A Etymology Comment');
     $this->assertEqual($entry0->pronunciation['th'], 'คาม');
     $this->assertEqual($entry0->morphologyType, 'stem');
     $this->assertEqual($entry0->literalMeaning['en'], 'A Literal Meaning');
     /* @var $sense00 Sense */
     $sense00 = $entry0->senses[0];
     $this->assertEqual($sense00->partOfSpeech->value, 'Noun');
     $this->assertEqual($sense00->gloss['en']->value, 'A Word');
     $this->assertEqual($sense00->definition['en']->value, 'A Word Defn');
     $expected = LexiconMultiValueField::createFromArray(array('9.1.3.1 Physical, non-physical'));
     $this->assertEqual($sense00->semanticDomain, $expected);
     $expected = LexiconMultiValueField::createFromArray(array('901'));
     $this->assertEqual($sense00->anthropologyCategories, $expected);
     $expected = LexiconMultiValueField::createFromArray(array('applied linguistics'));
     $this->assertEqual($sense00->academicDomains, $expected);
     $expected = new LexiconField('primary');
     $this->assertEqual($sense00->senseType, $expected);
     $expected = LexiconMultiValueField::createFromArray(array('Tentative'));
     $this->assertEqual($sense00->status, $expected);
     $expected = LexiconMultiValueField::createFromArray(array('colloquial'));
     $this->assertEqual($sense00->usages, $expected);
     $expected = new Picture();
     $expected->fileName = 'Desert.jpg';
     $expected->caption['th'] = 'รูป';
     $expected->caption['en'] = 'image';
     $expected->caption['fr'] = 'photo';
     $this->assertEqual($sense00->pictures[0], $expected);
     /* @var $example000 Example */
     $example000 = $sense00->examples[0];
     $this->assertEqual($example000->sentence['th'], 'ใหท่ มี');
     $this->assertEqual($example000->translation['en']->value, 'A Translation');
 }
 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_MultiPara_ParagraphMarkerFound()
 {
     $liftFilePath = $this->environ->createTestLiftFile(self::liftOneEntryMultiParaV0_13, 'LiftOneEntryMultiParaV0_13.lift');
     $project = $this->environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE);
     $mergeRule = LiftMergeRule::IMPORT_WINS;
     $skipSameModTime = false;
     $importer = LiftImport::get()->merge($liftFilePath, $project, $mergeRule, $skipSameModTime);
     $entryList = new LexEntryListModel($project);
     $entryList->read();
     $entry0 = $entryList->entries[0];
     $this->assertEqual($entryList->count, 1);
     $this->assertTrue(array_key_exists('customField_entry_Cust_MultiPara', $entry0['customFields']), 'custom field MultiPara exists');
     $this->assertEqual($entry0['customFields']['customField_entry_Cust_MultiPara']['en']['value'], '<p>First paragraph with <span lang="th">ไทย</span></p><p>Second Paragraph</p>', 'custom field MultiPara has paragraph separator character U+2029 replaced by paragraph markup and native language spans removed');
 }
 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');
 }
 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'));
 }
 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');
 }
 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);
 }