public function testImportFromFile_nonEnglishProject_importsOk()
 {
     $environ = new SemDomMongoTestEnvironment();
     $environ->cleanPreviousProject('es');
     $user1Id = $environ->createUser('u', 'u', 'u');
     $environ->getEnglishProjectAndCreateIfNecessary();
     $project = $environ->createSemDomProject('es', 'Spanish', $user1Id);
     $listModel = new SemDomTransItemListModel($project);
     $listModel->read();
     $xmlFilePath = __DIR__ . '/testFiles/LocalizedLists-es.xml';
     $project->importFromFile($xmlFilePath);
     $listModel->read();
     $this->assertEquals(1792, $listModel->count);
 }
 public function testImportFromFile_nonEnglishProject_importsOk()
 {
     $e = new SemDomMongoTestEnvironment();
     $e->cleanPreviousProject('es');
     $user1Id = $e->createUser('u', 'u', 'u');
     $e->getEnglishProjectAndCreateIfNecessary();
     $project = $e->createSemDomProject('es', "Spanish", $user1Id);
     $listModel = new SemDomTransItemListModel($project);
     $listModel->read();
     $xmlFilePath = TestPath . "languageforge/semdomtrans/testFiles/LocalizedLists-es.xml";
     $project->importFromFile($xmlFilePath);
     $listModel->read();
     $this->assertEqual($listModel->count, 1792);
 }
 public function testSemDomItemCommand_UpdateSemDomItem_AddItemUpdateItem()
 {
     $environ = new SemDomMongoTestEnvironment();
     $lang = 'en2';
     $languageName = 'English';
     $environ->cleanPreviousProject($lang);
     $environ->getEnglishProjectAndCreateIfNecessary();
     $user1Id = $environ->createUser('u', 'u', 'u');
     $targetProject = $environ->createSemDomProject($lang, $languageName, $user1Id);
     // insert dummy models
     $targetItemModel = new SemDomTransItemModel($targetProject);
     $targetItemModel->xmlGuid = 'asdf123';
     $targetItemModel->key = '1';
     $targetItemModel->name = new SemDomTransTranslatedForm('universe');
     $targetItemModel->description = new SemDomTransTranslatedForm('Universe description');
     $sq = new SemDomTransQuestion('A universe question', 'A universe question term');
     $targetItemModel->questions[] = $sq;
     $data = JsonEncoder::encode($targetItemModel);
     $itemId = SemDomTransItemCommands::update($data, $targetProject->id->asString());
     $readItem = new SemDomTransItemModel($targetProject, $itemId);
     $this->assertNotNull($readItem->key);
     $this->assertEquals('1', $readItem->key);
     $this->assertNotNull($readItem->name);
     $this->assertEquals('universe', $readItem->name->translation);
     $this->assertEquals(SemDomTransStatus::Draft, $readItem->name->status);
     $this->assertNotNull($readItem->description->translation);
     $this->assertEquals('Universe description', $readItem->description->translation);
     $this->assertEquals(SemDomTransStatus::Draft, $readItem->description->status);
     $readItem->name = new SemDomTransTranslatedForm('universe-edited');
     $data = JsonEncoder::encode($readItem);
     SemDomTransItemCommands::update($data, $targetProject->id->asString());
     $readItemAgain = new SemDomTransItemModel($targetProject, $itemId);
     $this->assertNotNull($readItemAgain->key);
     $this->assertEquals('1', $readItemAgain->key);
     $this->assertNotNull($readItemAgain->name);
     $this->assertEquals('universe-edited', $readItemAgain->name->translation);
     $this->assertEquals(SemDomTransStatus::Draft, $readItemAgain->name->status);
     $this->assertNotNull($readItemAgain->description->translation);
     $this->assertEquals('Universe description', $readItemAgain->description->translation);
     $this->assertEquals(SemDomTransStatus::Draft, $readItemAgain->description->status);
 }
 public function testSemdomItemCommand_UpdateSemDomItem_AddItemUpdateItem()
 {
     $e = new SemDomMongoTestEnvironment();
     $lang = 'en2';
     $languageName = "English";
     $e->cleanPreviousProject($lang);
     $e->getEnglishProjectAndCreateIfNecessary();
     $user1Id = $e->createUser('u', 'u', 'u');
     $targetProject = $e->createSemDomProject($lang, $languageName, $user1Id);
     // insert dummy models
     $targetItemModel = new SemDomTransItemModel($targetProject);
     $targetItemModel->xmlGuid = "asdf123";
     $targetItemModel->key = "1";
     $targetItemModel->name = new SemDomTransTranslatedForm("universe");
     $targetItemModel->description = new SemDomTransTranslatedForm("Universe description");
     $sq = new SemDomTransQuestion("A universe question", "A universe question term");
     $targetItemModel->questions[] = $sq;
     $data = JsonEncoder::encode($targetItemModel);
     $itemId = SemDomTransItemCommands::update($data, $targetProject->id->asString());
     $readItem = new SemDomTransItemModel($targetProject, $itemId);
     $this->assertNotEqual($readItem->key, null);
     $this->assertEqual($readItem->key, "1");
     $this->assertNotEqual($readItem->name, null);
     $this->assertEqual($readItem->name->translation, "universe");
     $this->assertEqual($readItem->name->status, SemDomTransStatus::Draft);
     $this->assertNotEqual($readItem->description->translation, null);
     $this->assertEqual($readItem->description->translation, "Universe description");
     $this->assertEqual($readItem->description->status, SemDomTransStatus::Draft);
     $readItem->name = new SemDomTransTranslatedForm("universe-edited");
     $data = JsonEncoder::encode($readItem);
     SemDomTransItemCommands::update($data, $targetProject->id->asString());
     $readItemAgain = new SemDomTransItemModel($targetProject, $itemId);
     $this->assertNotEqual($readItemAgain->key, null);
     $this->assertEqual($readItemAgain->key, "1");
     $this->assertNotEqual($readItemAgain->name, null);
     $this->assertEqual($readItemAgain->name->translation, "universe-edited");
     $this->assertEqual($readItemAgain->name->status, SemDomTransStatus::Draft);
     $this->assertNotEqual($readItemAgain->description->translation, null);
     $this->assertEqual($readItemAgain->description->translation, "Universe description");
     $this->assertEqual($readItemAgain->description->status, SemDomTransStatus::Draft);
 }
 public function testSemDomImportExport_ImportExportPreserveXMLFile()
 {
     $environ = new SemDomMongoTestEnvironment();
     $environ->clean();
     $englishProject = $environ->getEnglishProjectAndCreateIfNecessary();
     $exporter = new SemDomXMLExporter($englishProject, false, true, false);
     $exporter->run();
     $sourcePath = $englishProject->xmlFilePath;
     $destinationPath = $englishProject->getAssetsFolderPath() . DIRECTORY_SEPARATOR . $englishProject->projectCode . 'Export.xml';
     $sourceStr = trim(file_get_contents($sourcePath), "\n");
     $sourceArr = explode("\n", $sourceStr);
     $destStr = trim(file_get_contents($destinationPath), "\n");
     $destArr = explode("\n", $destStr);
     for ($i = 0; $i < count($destArr); $i++) {
         if ($i % 500 == 0) {
             $this->assertEquals($sourceArr[$i], $destArr[$i]);
             //$this->assertEqual(substr($sourceArr[$i], 0, -1), $destArr[$i]);
         }
     }
     $environ->clean();
 }
 public function testEncode_SourceProjectAndTargetProjectHaveItems_DtoAsExpected()
 {
     $e = new SemDomMongoTestEnvironment();
     $e->cleanPreviousProject('es');
     $sourceProject = $e->getEnglishProjectAndCreateIfNecessary();
     $user1Id = $e->createUser('u', 'u', 'u');
     $targetProject = $e->createSemDomProject('es', "Spanish", $user1Id);
     /*
     // insert dummy models
     $sourceItemModel = new SemDomTransItemModel($sourceProject);
     $sourceItemModel->key = "1";
     $sourceItemModel->name = new SemDomTransTranslatedForm("universe");
     $sourceItemModel->description = new SemDomTransTranslatedForm("Universe description");
     $sq = new SemDomTransQuestion("A universe question", "A universe question term");
     $sourceItemModel->questions = new ArrayOf(function ($data) {
         return new SemDomTransQuestion();
     });
     $sourceItemModel->questions[] = $sq;
     $sourceItemModel->write();
     */
     $targetItemsModel = new SemDomTransItemListModel($targetProject);
     $targetItemsModel->read();
     $targetItems = $targetItemsModel->entries;
     $targetItemModel = new SemDomTransItemModel($targetProject);
     $targetItemModel->readByProperty('xmlGuid', $targetItems[0]['xmlGuid']);
     $targetItemModel->key = "1";
     $targetItemModel->name = new SemDomTransTranslatedForm("wszechswiat");
     $targetItemModel->description = new SemDomTransTranslatedForm("Opis wszechswiata");
     $tq = new SemDomTransQuestion("Pytanie wszechswiata", "Termin zwiazany z wszechswiatem");
     $targetItemModel->questions = new ArrayOf(function ($data) {
         return new SemDomTransQuestion();
     });
     $targetItemModel->questions[] = $tq;
     $targetItemModel->write();
     // call dto
     //$loadTargetProject = new SemDomTransProjectModel($prId->asString());
     //$loadSourceProject = new SemDomTransProjectModel($loadTargetProject->sourceLanguageProjectId);
     $prId = $targetProject->id;
     $result = SemDomTransEditDto::encode($prId->asString(), null);
     // print_r($result);
     // check dto returns expected results
     $entries = $result["entries"];
     $this->assertTrue($entries != null);
     $this->assertTrue(count($entries) > 0);
     $firstObject = $entries[0];
     $this->assertNotEqual($firstObject["key"], null);
     $this->assertEqual($firstObject["key"], "1");
     $this->assertNotEqual($firstObject["name"], null);
     $this->assertEqual($firstObject["name"]["source"], "Universe, creation");
     $this->assertEqual($firstObject["name"]["translation"], "wszechswiat");
     $this->assertEqual($firstObject["name"]["status"], SemDomTransStatus::Draft);
     $this->assertNotEqual($firstObject["description"], null);
     $this->assertEqual($firstObject["description"]["translation"], "Opis wszechswiata");
     $this->assertEqual($firstObject["description"]["status"], SemDomTransStatus::Draft);
     $this->assertNotEqual($firstObject["questions"], null);
     $this->assertNotEqual($firstObject["questions"][0], null);
     $this->assertNotEqual($firstObject["questions"][0]["question"], null);
     $this->assertNotEqual($firstObject["questions"][0]["terms"], null);
     $this->assertEqual($firstObject["questions"][0]["question"]["source"], "(1) What words refer to everything we can see?");
     $this->assertEqual($firstObject["questions"][0]["question"]["translation"], "Pytanie wszechswiata");
     $this->assertEqual($firstObject["questions"][0]["terms"]["source"], "universe, creation, cosmos, heaven and earth, macrocosm, everything that exists");
     $this->assertEqual($firstObject["questions"][0]["terms"]["translation"], "Termin zwiazany z wszechswiatem");
     // this test messes with the English source project
     $e->clean();
     $e->cleanPreviousProject('en');
 }