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 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']); }
function testEncode_EntriesAndLoadPartial_PartialOk() { $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(); $sense = new Sense(); $sense->definition->form('en', 'apple'); for ($i = 9; $i >= 0; $i--) { $entry = new LexEntryModel($project); $entry->lexeme->form('th', 'Apfel' . $i); $entry->senses[] = $sense; $entry->write(); } $result = LexDbeDto::encode($projectId, $userId, null, 5); $this->assertEqual(count($result['entries']), 5); $this->assertEqual($result['itemCount'], 5); $this->assertEqual($result['itemTotalCount'], 10); $this->assertEqual($result['entries'][0]['lexeme']['th']['value'], 'Apfel0', 'Apfel0 should sort first'); $this->assertEqual($result['entries'][4]['lexeme']['th']['value'], 'Apfel4', 'Apfel4 should sort first'); $result = LexDbeDto::encode($projectId, $userId, null, 9); $this->assertEqual(count($result['entries']), 1); $this->assertEqual($result['itemCount'], 1); $this->assertEqual($result['itemTotalCount'], 10); $this->assertEqual($result['entries'][0]['lexeme']['th']['value'], 'Apfel0', 'Apfel0 should sort first'); }
public function testUpdateProject_ReadOnlyProperties_PropertiesNotChanged() { $environ = new LexiconMongoTestEnvironment(); $environ->clean(); $userId = $environ->createUser('User', 'Name', '*****@*****.**'); $user = new UserModel($userId); $user->role = SystemRoles::USER; $hackerId = $environ->createUser('Hacker', 'Hacker', '*****@*****.**'); $hacker = new UserModel($hackerId); $hacker->role = SystemRoles::USER; $hacker->write(); $project = $environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $projectId = $project->id->asString(); $project->addUser($userId, ProjectRoles::MANAGER); $project->ownerRef = $user->id->asString(); $user->addProject($projectId); $user->write(); $project->write(); $hackedData = 'hacked'; $params = ProjectCommands::readProject($projectId); $params['projectName'] = 'new project name'; $params['id'] = $hackedData; $params['ownerRef'] = $hacker->id->asString(); $params['users'][$hacker->id->asString()]['role'] = ProjectRoles::MANAGER; $params['projectCode'] = $hackedData; $params['siteName'] = $hackedData; $params['appName'] = $hackedData; $params['userProperties']['userProfilePickLists']['city']['name'] = $hackedData; LexProjectCommands::updateProject($projectId, $userId, $params); $updatedProject = ProjectCommands::readProject($projectId); $this->assertEquals('new project name', $updatedProject['projectName']); $this->assertNotEquals($hackedData, $updatedProject['id']); $this->assertNotEquals($hacker->id->asString(), $updatedProject['ownerRef']); $this->assertFalse(isset($updatedProject['users'][$hacker->id->asString()])); $this->assertNotEquals($hackedData, $updatedProject['projectCode']); $this->assertNotEquals($hackedData, $updatedProject['siteName']); $this->assertNotEquals($hackedData, $updatedProject['appName']); $this->assertNotEquals($hackedData, $updatedProject['userProperties']['userProfilePickLists']['city']['name']); }
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 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'); }
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>'; */ }
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); }