Do not rely on a database default for the profile field formType.
This commit is contained in:
parent
aa65b6ca22
commit
b88d96deb5
3 changed files with 29 additions and 9 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
7.7.15
|
7.7.15
|
||||||
|
- fixed #10629: WebGUI::ProfileField create new field bug
|
||||||
|
|
||||||
7.7.14
|
7.7.14
|
||||||
- fixed #10606: shelf selector
|
- fixed #10606: shelf selector
|
||||||
|
|
|
||||||
|
|
@ -105,17 +105,22 @@ sub create {
|
||||||
|
|
||||||
### Check data
|
### Check data
|
||||||
# Check if the field already exists
|
# Check if the field already exists
|
||||||
|
$properties->{fieldType} ||= "ReadOnly";
|
||||||
return undef if $class->exists($session,$fieldName);
|
return undef if $class->exists($session,$fieldName);
|
||||||
return undef if $class->isReservedFieldName($fieldName);
|
return undef if $class->isReservedFieldName($fieldName);
|
||||||
|
|
||||||
### Data okay, create the field
|
### Data okay, create the field
|
||||||
# Add the record
|
# Add the record
|
||||||
my $id
|
my $id = $session->db->setRow("userProfileField","fieldName",
|
||||||
= $session->db->setRow("userProfileField","fieldName",{fieldName=>"new"},$fieldName);
|
{
|
||||||
|
fieldName=>"new",
|
||||||
|
fieldType => $properties->{fieldType},
|
||||||
|
},
|
||||||
|
$fieldName
|
||||||
|
);
|
||||||
my $self = $class->new($session,$id);
|
my $self = $class->new($session,$id);
|
||||||
|
|
||||||
# Get the field's data type
|
# Get the field's data type
|
||||||
$properties->{fieldType} ||= "ReadOnly";
|
|
||||||
my $formClass = $self->getFormControlClass;
|
my $formClass = $self->getFormControlClass;
|
||||||
eval { WebGUI::Pluggable::load($formClass) };
|
eval { WebGUI::Pluggable::load($formClass) };
|
||||||
my $dbDataType = $formClass->getDatabaseFieldType;
|
my $dbDataType = $formClass->getDatabaseFieldType;
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ WebGUI::Test->usersToDelete($newUser);
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Tests
|
# 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
|
# Test the creation of ProfileField
|
||||||
|
|
@ -79,18 +79,22 @@ ok( $ff = $uilevelField->formField(undef, undef, $newUser), 'formField method re
|
||||||
$ffvalue = $newUser->profileField('uiLevel');
|
$ffvalue = $newUser->profileField('uiLevel');
|
||||||
like( $ff, qr/$ffvalue/, 'html returned contains value, uiLevel field, defaulted user' );
|
like( $ff, qr/$ffvalue/, 'html returned contains value, uiLevel field, defaulted user' );
|
||||||
|
|
||||||
#########################################################
|
###########################################################
|
||||||
#
|
#
|
||||||
# set, changing fieldTypes
|
# create
|
||||||
#
|
#
|
||||||
#########################################################
|
###########################################################
|
||||||
|
|
||||||
my $newProfileField = WebGUI::ProfileField->create($session, 'testField', {
|
my $newProfileField = WebGUI::ProfileField->create($session, 'testField', {
|
||||||
fieldType => 'Text',
|
fieldType => 'Float', ##Note, intentionally choosing a non-Text type of field
|
||||||
label => 'Test 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 $htmlFieldType = lc WebGUI::Form::HTMLArea->getDatabaseFieldType();
|
||||||
|
|
||||||
my $fieldSpec = $session->db->quickHashRef('describe userProfileData testField');
|
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');
|
$fieldSpec = $session->db->quickHashRef('describe userProfileData testField');
|
||||||
is (lc $fieldSpec->{Type}, $htmlFieldType, 'database updated along with profile field object');
|
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
|
# exists
|
||||||
|
|
@ -115,6 +128,7 @@ ok( !WebGUI::ProfileField->exists($session, time), "random field does not exist"
|
||||||
# Cleanup
|
# Cleanup
|
||||||
END {
|
END {
|
||||||
$newProfileField->delete;
|
$newProfileField->delete;
|
||||||
|
$newProfileField2->delete;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue