Ejemplo n.º 1
0
 public function testLiftImportMerge_BogusTags_ReportOk()
 {
     $liftFilePath = $this->environ->createTestLiftFile(self::liftTwoEntriesCorrectedBogusTagsV0_13, 'TwoEntriesCorrectedBogusTagsV0_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();
     $entries = $entryList->entries;
     $entriesByGuid = $this->environ->indexItemsBy($entries, 'guid');
     $report = $importer->getReport();
     $reportStr = $report->toString();
     $this->assertEqual(2, $entryList->count);
     $this->assertEqual("chùuchìi mǔu krɔ̀ɔp", $entriesByGuid['dd15cbc4-9085-4d66-af3d-8428f078a7da']['lexeme']['th-fonipa']['value']);
     $this->assertEqual(1, count($entriesByGuid['dd15cbc4-9085-4d66-af3d-8428f078a7da']['senses']));
     $this->assertEqual("A kind of curry fried with crispy pork", $entriesByGuid['dd15cbc4-9085-4d66-af3d-8428f078a7da']['senses'][0]['definition']['en']['value']);
     $this->assertEqual("Noun", $entriesByGuid['dd15cbc4-9085-4d66-af3d-8428f078a7da']['senses'][0]['partOfSpeech']['value']);
     $this->assertEqual("khâaw kài thɔ̂ɔt", $entriesByGuid['05473cb0-4165-4923-8d81-02f8b8ed3f26']['lexeme']['th-fonipa']['value']);
     $this->assertEqual(1, count($report->nodeErrors));
     $this->assertTrue($report->nodeErrors[0]->getSubnodeError(0)->hasError(), 'should have phony and bogus tag entry errors');
     $this->assertPattern("/unhandled element 'bogus'/", $reportStr);
     $this->assertPattern("/processing multitext 'lexical-unit', unhandled element 'phony'/", $reportStr);
     $this->assertNoPattern("/unhandled element 'translation'/", $reportStr);
     $this->assertTrue($report->nodeErrors[0]->getSubnodeError(0)->currentSubnodeError()->currentSubnodeError()->hasError(), 'should have rubbish tag example error');
     $this->assertPattern("/unhandled element 'rubbish'/", $report->nodeErrors[0]->getSubnodeError(0)->currentSubnodeError()->currentSubnodeError()->toString());
     $this->assertPattern("/unhandled element 'rubbish'/", $reportStr);
     $this->assertTrue($report->nodeErrors[0]->getSubnodeError(1)->currentSubnodeError()->currentSubnodeError()->hasError(), 'should have fake tag example error');
     $this->assertPattern("/unhandled element 'fake'/", $report->nodeErrors[0]->getSubnodeError(1)->currentSubnodeError()->currentSubnodeError()->toString());
     $this->assertPattern("/unhandled element 'fake'/", $reportStr);
 }
 public function testLiftImportMerge_ZipFileWithDir_CorrectValues()
 {
     $zipFilePath = $this->environ->copyTestUploadFile(TestPath . 'common/TestLexProjectWithDir.zip');
     $project = $this->environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE);
     $importer = LiftImport::get()->importZip($zipFilePath, $project);
     $entryList = new LexEntryListModel($project);
     $entryList->read();
     $entries = $entryList->entries;
     $this->assertEqual($entryList->count, 2);
     $entriesByGuid = $this->environ->indexItemsBy($entries, 'guid');
     $entry0 = $entriesByGuid['dd15cbc4-9085-4d66-af3d-8428f078a7da'];
     $entry1 = $entriesByGuid['05473cb0-4165-4923-8d81-02f8b8ed3f26'];
     $this->assertEqual($entry0['guid'], "dd15cbc4-9085-4d66-af3d-8428f078a7da");
     $this->assertEqual($entry0['lexeme']['th-fonipa']['value'], "chùuchìi mǔu krɔ̂ɔp");
     $this->assertEqual($entry0['lexeme']['th']['value'], "ฉู่ฉี่หมูกรอบ");
     $this->assertEqual(count($entry0['senses']), 1);
     $this->assertEqual($entry0['senses'][0]['definition']['en']['value'], "incorrect definition");
     $this->assertEqual($entry0['senses'][0]['gloss']['en']['value'], "incorrect gloss");
     $this->assertEqual($entry0['senses'][0]['gloss']['th']['value'], "th incorrect gloss");
     $this->assertEqual($entry0['senses'][0]['partOfSpeech']['value'], "Adjective");
     $this->assertEqual($entry0['senses'][0]['semanticDomain']['values'][0], "5.2 Food");
     $this->assertEqual($entry0['senses'][0]['semanticDomain']['values'][1], "1 Universe, creation");
     $this->assertEqual($entry0['senses'][0]['examples'][0]['sentence']['th-fonipa']['value'], "sentence 1");
     $this->assertEqual($entry0['senses'][0]['examples'][0]['translation']['en']['value'], "translation 1");
     $this->assertEqual($entry0['senses'][0]['examples'][1]['sentence']['th-fonipa']['value'], "sentence 2");
     $this->assertEqual($entry0['senses'][0]['examples'][1]['translation']['en']['value'], "translation 2");
     $this->assertEqual($entry1['guid'], "05473cb0-4165-4923-8d81-02f8b8ed3f26");
     $this->assertEqual($entry1['lexeme']['th-fonipa']['value'], "khâaw kài thɔ̀ɔt");
     $this->assertEqual($entry1['lexeme']['th']['value'], "ข้าวไก่ทอด");
     $this->assertFalse($importer->getReport()->hasError());
 }
 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 testImportProjectZip_7zFile_StatsOkAndCustomFieldsImported()
 {
     $project = $this->environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE);
     $projectId = $project->id->asString();
     $fileName = 'TestLangProj.7z';
     // Ken Zook's test data
     $tmpFilePath = $this->environ->uploadFile(TestPath . "common/{$fileName}", $fileName);
     $userId = $this->environ->createUser('bob', 'bob', '*****@*****.**');
     $project->addUser($userId, LexiconRoles::OBSERVER);
     $project->config->userViews[$userId] = clone $project->config->roleViews[LexiconRoles::OBSERVER];
     $project->write();
     $this->assertFalse($project->config->entry->fieldOrder->array_search('customField_entry_Cust_Single_Line_All'), "custom field entry config doesn't yet exist");
     $this->assertFalse(array_key_exists('customField_entry_Cust_Single_Line_All', $project->config->entry->fields), "custom field entry config doesn't yet exist");
     $this->assertFalse(array_key_exists('customField_entry_Cust_Single_Line_All', $project->config->roleViews[LexiconRoles::OBSERVER]->fields), "custom field roleView config doesn't yet exist");
     $this->assertFalse(array_key_exists('customField_entry_Cust_Single_Line_All', $project->config->roleViews[LexiconRoles::MANAGER]->fields), "custom field roleView config doesn't yet exist");
     $this->assertFalse(array_key_exists('customField_entry_Cust_Single_Line_All', $project->config->userViews[$userId]->fields), "custom field userView config doesn't yet exist");
     $response = LexUploadCommands::importProjectZip($projectId, 'import-zip', $tmpFilePath);
     $project->read($project->id->asString());
     $filePath = $project->getAssetsFolderPath() . '/' . $response->data->fileName;
     $projectSlug = $project->databaseName();
     $entryList = new LexEntryListModel($project);
     $entryList->read();
     $entries = $entryList->entries;
     $entriesByGuid = $this->environ->indexItemsBy($entries, 'guid');
     $entryA = $entriesByGuid['05c54cf0-4e5a-4bf2-99f8-ec787e4113ac'];
     $entryB = $entriesByGuid['1a705846-a814-4289-8594-4b874faca6cc'];
     $entryBSensesByLiftId = $this->environ->indexItemsBy($entryB['senses'], 'liftId');
     $entryBSenseA = $entryBSensesByLiftId['eea9c29f-244f-4891-81db-c8274cd61f0c'];
     $optionListList = new LexOptionListListModel($project);
     $optionListList->read();
     $optionListByCodes = $this->environ->indexItemsBy($optionListList->entries, 'code');
     // stats OK?
     $this->assertTrue($response->result, 'Import should succeed');
     $this->assertPattern("/lexicon\\/{$projectSlug}/", $response->data->path, 'Uploaded zip file path should be in the right location');
     $this->assertEqual($fileName, $response->data->fileName, 'Uploaded zip fileName should have the original fileName');
     $this->assertTrue(file_exists($filePath), 'Uploaded zip file should exist');
     $this->assertEqual($response->data->stats->existingEntries, 0);
     $this->assertEqual($response->data->stats->importEntries, 64);
     $this->assertEqual($response->data->stats->newEntries, 64);
     $this->assertEqual($response->data->stats->entriesMerged, 0);
     $this->assertEqual($response->data->stats->entriesDuplicated, 0);
     $this->assertEqual($response->data->stats->entriesDeleted, 0);
     // custom fields imported?
     $this->assertEqual($entryList->count, 64);
     $this->assertEqual($optionListList->count, 24);
     $this->assertTrue(array_key_exists('grammatical-info', $optionListByCodes));
     $this->assertFalse(array_key_exists('semantic-domain-ddp4', $optionListByCodes));
     $this->assertEqual($entryA['lexeme']['qaa-fonipa-x-kal']['value'], '-kes');
     $this->assertEqual($entryA['customFields']['customField_entry_Cust_Single_Line_All']['en']['value'], '635459584141806142kes.wav');
     $this->assertTrue($project->config->entry->fieldOrder->array_search('customField_entry_Cust_Single_Line_All'), "custom field entry config exists");
     $this->assertTrue(array_key_exists('customField_entry_Cust_Single_Line_All', $project->config->entry->fields), "custom field entry config exists");
     $this->assertEqual($project->config->entry->fields['customField_entry_Cust_Single_Line_All']->label, 'Cust Single Line All');
     $this->assertEqual($project->config->entry->fields['customField_entry_Cust_Single_Line_All']->type, 'multitext');
     $this->assertTrue($project->config->entry->fields['customField_entry_Cust_Single_Line_All']->inputSystems->array_search('en'));
     $this->assertTrue(array_key_exists('customField_entry_Cust_Single_Line_All', $project->config->roleViews[LexiconRoles::OBSERVER]->fields), "custom field roleView config exists");
     $this->assertTrue(array_key_exists('customField_entry_Cust_Single_Line_All', $project->config->roleViews[LexiconRoles::MANAGER]->fields), "custom field roleView config exists");
     $this->assertTrue($project->config->roleViews[LexiconRoles::OBSERVER]->fields['customField_entry_Cust_Single_Line_All']->show);
     $this->assertTrue($project->config->roleViews[LexiconRoles::MANAGER]->fields['customField_entry_Cust_Single_Line_All']->show);
     $this->assertTrue(array_key_exists('customField_entry_Cust_Single_Line_All', $project->config->userViews[$userId]->fields), "custom field userView config doesn't yet exist");
     $this->assertTrue($project->config->userViews[$userId]->fields['customField_entry_Cust_Single_Line_All']->show);
     $this->assertEqual($entryB['lexeme']['qaa-fonipa-x-kal']['value'], 'zitʰɛstmen');
     $this->assertEqual($entryB['customFields']['customField_entry_Cust_Single_ListRef']['value'], 'comparative linguistics');
     $this->assertEqual(count($entryBSenseA['customFields']['customField_senses_Cust_Multi_ListRef']['values']), 2);
     $this->assertEqual($entryBSenseA['customFields']['customField_senses_Cust_Multi_ListRef']['values'][0], 'First Custom Item');
     $this->assertEqual($entryBSenseA['customFields']['customField_senses_Cust_Multi_ListRef']['values'][1], 'Second Custom Item');
     $this->assertEqual($entryBSenseA['examples'][0]['customFields']['customField_examples_Cust_Example']['qaa-x-kal']['value'], 'Custom example');
     /*
     echo '<pre style="height:500px; overflow:auto">';
     echo $response->data->importErrors;
     echo '</pre>';
     */
 }