Fix a bug where changing fieldTypes in the userProfileField did not update the database field types.

This commit is contained in:
Colin Kuskie 2009-04-26 04:02:38 +00:00
parent 70845fd9e8
commit 86621e255b
3 changed files with 44 additions and 10 deletions

View file

@ -3,6 +3,7 @@
- fixed #10223: Calendar List View Ignores Event Permissions (dhelsten)
- fixed #10226: html2text dropping text
- fixed #10210: Generated Message-Id invalid (patch basis from tektek)
- fixed #10209: Changing existing user profile field type doesn't change underlying database column type
7.7.4
- rfe: Extend DateTime for Week-Nrs (#9151)

View file

@ -828,8 +828,19 @@ sub set {
}
$properties->{fieldName} = $self->getId;
##Save the fieldType now. It can't be chacked against getFormControlClass now
##because it will return the OLD formControlClass, not the new one that we need
##to check against.
my $originalFieldType = $self->get('fieldType');
# Update the record
$db->setRow("userProfileField","fieldName",$properties);
foreach my $key (keys %{$properties}) {
$self->{_properties}{$key} = $properties->{$key};
}
# If the fieldType has changed, modify the userProfileData column
if ($properties->{fieldType} ne $self->get("fieldType")) {
if ($properties->{fieldType} ne $originalFieldType) {
# Create a copy of the new properties so we don't mess them up
my $fieldClass = $self->getFormControlClass;
eval "use $fieldClass;";
@ -845,11 +856,6 @@ sub set {
$db->write($sql);
}
# Update the record
$db->setRow("userProfileField","fieldName",$properties);
foreach my $key (keys %{$properties}) {
$self->{_properties}{$key} = $properties->{$key};
}
}
#-------------------------------------------------------------------

View file

@ -17,19 +17,23 @@ use FindBin;
use strict;
use lib "$FindBin::Bin/lib";
use Test::More;
use Data::Dumper;
use WebGUI::Test; # Must use this before any other WebGUI modules
use WebGUI::Session;
use WebGUI::Form::Text;
use WebGUI::Form::HTMLArea;
#----------------------------------------------------------------------------
# Init
my $session = WebGUI::Test->session;
my $newUser = WebGUI::User->create( $session );
WebGUI::Test->usersToDelete($newUser);
#----------------------------------------------------------------------------
# Tests
plan tests => 17; # Increment this number for each test you create
plan tests => 20; # Increment this number for each test you create
#----------------------------------------------------------------------------
# Test the creation of ProfileField
@ -66,19 +70,42 @@ like( $ff, qr/value="$ffvalue"[^>]+selected/, 'html returned contains value, uiL
$ff = undef;
$ffvalue = undef;
ok( $ff = $aliasField->formField(undef, undef, $newUser), 'formField method returns something, alias field, defaulted user' );
my $ffvalue = $newUser->profileField('alias');
$ffvalue = $newUser->profileField('alias');
like( $ff, qr/$ffvalue/, 'html returned contains value, alias field, defaulted user' );
$ff = undef;
$ffvalue = undef;
ok( $ff = $uilevelField->formField(undef, undef, $newUser), 'formField method returns something, uiLevel field, defaulted user' );
my $ffvalue = $newUser->profileField('uiLevel');
$ffvalue = $newUser->profileField('uiLevel');
like( $ff, qr/$ffvalue/, 'html returned contains value, uiLevel field, defaulted user' );
#########################################################
#
# set, changing fieldTypes
#
#########################################################
my $newProfileField = WebGUI::ProfileField->create($session, 'testField', {
fieldType => 'Text',
label => 'Test Field',
});
my $textFieldType = lc WebGUI::Form::Text->getDatabaseFieldType();
my $htmlFieldType = lc WebGUI::Form::HTMLArea->getDatabaseFieldType();
my $fieldSpec = $session->db->quickHashRef('describe userProfileData testField');
is (lc $fieldSpec->{Type}, $textFieldType, 'test field created with correct type for text field');
$newProfileField->set({ fieldType => 'HTMLArea' });
is($newProfileField->get('fieldType'), 'HTMLArea', 'test field updated to HTMLArea');
$fieldSpec = $session->db->quickHashRef('describe userProfileData testField');
is (lc $fieldSpec->{Type}, $htmlFieldType, 'database updated along with profile field object');
#----------------------------------------------------------------------------
# Cleanup
END {
$newUser->delete;
$newProfileField->delete;
}