diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index ec577310a..7814c9683 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,4 +1,5 @@ 7.7.15 + - fixed #10629: WebGUI::ProfileField create new field bug 7.7.14 - fixed #10606: shelf selector diff --git a/lib/WebGUI/ProfileField.pm b/lib/WebGUI/ProfileField.pm index 364783d91..e836b2d83 100644 --- a/lib/WebGUI/ProfileField.pm +++ b/lib/WebGUI/ProfileField.pm @@ -105,17 +105,22 @@ sub create { ### Check data # Check if the field already exists + $properties->{fieldType} ||= "ReadOnly"; return undef if $class->exists($session,$fieldName); return undef if $class->isReservedFieldName($fieldName); ### Data okay, create the field # Add the record - my $id - = $session->db->setRow("userProfileField","fieldName",{fieldName=>"new"},$fieldName); + my $id = $session->db->setRow("userProfileField","fieldName", + { + fieldName=>"new", + fieldType => $properties->{fieldType}, + }, + $fieldName + ); my $self = $class->new($session,$id); # Get the field's data type - $properties->{fieldType} ||= "ReadOnly"; my $formClass = $self->getFormControlClass; eval { WebGUI::Pluggable::load($formClass) }; my $dbDataType = $formClass->getDatabaseFieldType; diff --git a/t/ProfileField.t b/t/ProfileField.t index f1b0e0f77..5836c4313 100644 --- a/t/ProfileField.t +++ b/t/ProfileField.t @@ -33,7 +33,7 @@ WebGUI::Test->usersToDelete($newUser); #---------------------------------------------------------------------------- # Tests -plan tests => 22; # Increment this number for each test you create +plan tests => 28; # Increment this number for each test you create #---------------------------------------------------------------------------- # Test the creation of ProfileField @@ -79,18 +79,22 @@ ok( $ff = $uilevelField->formField(undef, undef, $newUser), 'formField method re $ffvalue = $newUser->profileField('uiLevel'); like( $ff, qr/$ffvalue/, 'html returned contains value, uiLevel field, defaulted user' ); -######################################################### +########################################################### # -# set, changing fieldTypes +# create # -######################################################### +########################################################### my $newProfileField = WebGUI::ProfileField->create($session, 'testField', { - fieldType => 'Text', + fieldType => 'Float', ##Note, intentionally choosing a non-Text type of field label => 'Test Field', }); -my $textFieldType = lc WebGUI::Form::Text->getDatabaseFieldType(); +is($newProfileField->get('fieldType'), 'Float', 'create: makes field with correct type'); +is($newProfileField->get('label'), 'Test Field', 'correct label'); +is($newProfileField->getLabel, 'Test Field', 'getLabel works, too'); + +my $textFieldType = lc WebGUI::Form::Float->getDatabaseFieldType(); my $htmlFieldType = lc WebGUI::Form::HTMLArea->getDatabaseFieldType(); my $fieldSpec = $session->db->quickHashRef('describe userProfileData testField'); @@ -102,6 +106,15 @@ is($newProfileField->get('fieldType'), 'HTMLArea', 'test field updated to HTMLAr $fieldSpec = $session->db->quickHashRef('describe userProfileData testField'); is (lc $fieldSpec->{Type}, $htmlFieldType, 'database updated along with profile field object'); +my $newProfileField2 = WebGUI::ProfileField->create($session, 'testField2', { + label => q|WebGUI::International::get('webgui','WebGUI')|, + fieldName => 'Text', +}); + +is($newProfileField2->get('fieldType'), 'ReadOnly', 'create: default fieldType is ReadOnly'); +is($newProfileField2->get('label'), q|WebGUI::International::get('webgui','WebGUI')|, 'getting raw label'); +is($newProfileField2->getLabel, 'WebGUI', 'getLabel will process safeEval calls for i18n'); + ########################################################### # # exists @@ -115,6 +128,7 @@ ok( !WebGUI::ProfileField->exists($session, time), "random field does not exist" # Cleanup END { $newProfileField->delete; + $newProfileField2->delete; }