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');
 }
Exemplo n.º 2
0
 public function lex_configuration_update($config, $optionlists)
 {
     LexProjectCommands::updateConfig($this->projectId, $config);
     foreach ($optionlists as $optionlist) {
         LexOptionListCommands::updateList($this->projectId, $optionlist);
     }
     return;
 }
 /**
  * Create custom field config
  *
  * @param string $fieldType
  * @param string $customFieldNamePrefix
  * @param array $customFieldSpecs
  * @param LexConfigFieldList $levelConfig
  * @return string $customFieldName
  */
 private function createCustomField($fieldType, $customFieldNamePrefix, $customFieldSpecs, $levelConfig)
 {
     $customFieldName = $customFieldNamePrefix . str_replace(' ', '_', $fieldType);
     $levelConfig->fieldOrder->ensureValueExists($customFieldName);
     if (!array_key_exists($customFieldName, $levelConfig->fields)) {
         if ($customFieldSpecs['Type'] == 'ReferenceAtom') {
             $levelConfig->fields[$customFieldName] = new LexConfigOptionList();
             $levelConfig->fields[$customFieldName]->listCode = $customFieldSpecs['range'];
         } elseif ($customFieldSpecs['Type'] == 'ReferenceCollection') {
             $levelConfig->fields[$customFieldName] = new LexConfigMultiOptionList();
             $levelConfig->fields[$customFieldName]->listCode = $customFieldSpecs['range'];
         } elseif ($customFieldSpecs['Type'] == 'OwningAtom') {
             $levelConfig->fields[$customFieldName] = new LexConfigMultiParagraph();
         } else {
             $levelConfig->fields[$customFieldName] = new LexConfigMultiText();
         }
         $levelConfig->fields[$customFieldName]->label = $fieldType;
         $levelConfig->fields[$customFieldName]->hideIfEmpty = false;
     }
     LexProjectCommands::createNewCustomFieldViews($customFieldName, $customFieldSpecs['Type'], $this->project->config);
     return $customFieldName;
 }
 public function testCreateCustomFieldsViews_CreateTwoCustomFieldViews_TwoCreated()
 {
     $environ = new LexiconMongoTestEnvironment();
     $environ->clean();
     // setup: 1 example custom field (existing), 1 in senses (to delete), 1 in entry (to create)
     $project = $environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE);
     $customFieldNameExisting = 'customField_examples_testOptionList';
     $viewFieldConfig = new LexViewFieldConfig();
     $viewFieldConfig->type = 'ReferenceAtom';
     $viewFieldConfig->show = false;
     $project->config->roleViews[LexRoles::MANAGER]->fields[$customFieldNameExisting] = $viewFieldConfig;
     $customFieldNameToCreate = 'customField_entry_testMultiText';
     $customFieldSpecs = array(array('fieldName' => $customFieldNameToCreate, 'fieldType' => 'MultiString'), array('fieldName' => $customFieldNameExisting, 'fieldType' => $viewFieldConfig->type));
     $mangerRoleViewFieldCount = $project->config->roleViews[LexRoles::MANAGER]->fields->count();
     $customFieldNameToDelete = 'customField_senses_testOptionList';
     $viewFieldConfig = new LexViewFieldConfig();
     $viewFieldConfig->type = 'ReferenceAtom';
     $project->config->roleViews[LexRoles::MANAGER]->fields[$customFieldNameToDelete] = $viewFieldConfig;
     $projectId = $project->write();
     $this->assertFalse($project->config->roleViews[LexRoles::MANAGER]->fields[$customFieldNameExisting]->show);
     // execute
     $result = LexProjectCommands::updateCustomFieldViews($project->projectCode, $customFieldSpecs);
     // verify
     $this->assertEquals($projectId, $result);
     $project2 = new LexProjectModel($projectId);
     $this->assertEquals($mangerRoleViewFieldCount + 1, $project2->config->roleViews[LexRoles::MANAGER]->fields->count());
     $this->assertArrayNotHasKey($customFieldNameToDelete, $project2->config->roleViews[LexRoles::MANAGER]->fields);
     $customFieldCreated = $project2->config->roleViews[LexRoles::MANAGER]->fields[$customFieldNameToCreate];
     $this->assertTrue(is_a($customFieldCreated, 'Api\\Model\\Languageforge\\Lexicon\\Config\\LexViewMultiTextFieldConfig'));
     $customFieldExisting = $project2->config->roleViews[LexRoles::MANAGER]->fields[$customFieldNameExisting];
     $this->assertTrue(is_a($customFieldExisting, 'Api\\Model\\Languageforge\\Lexicon\\Config\\LexViewFieldConfig'));
     $this->assertFalse($customFieldExisting->show);
 }
Exemplo n.º 5
0
 /**
  * Create/Update a Project
  *
  * @param array $object
  * @return string Id of written object
  */
 public function lex_project_update($settings)
 {
     return LexProjectCommands::updateProject($this->_projectId, $this->_userId, $settings);
 }