Added exists() method to ProfileField + tests
This commit is contained in:
parent
18993c5924
commit
774c499d2d
2 changed files with 30 additions and 13 deletions
|
|
@ -104,12 +104,7 @@ sub create {
|
|||
|
||||
### Check data
|
||||
# Check if the field already exists
|
||||
my $fieldNameExists
|
||||
= $session->db->quickScalar(
|
||||
"select count(*) from userProfileField where fieldName=?",
|
||||
[$fieldName]
|
||||
);
|
||||
return undef if $fieldNameExists;
|
||||
return undef if $class->exists($session,$fieldName);
|
||||
return undef if $class->isReservedFieldName($fieldName);
|
||||
|
||||
### Data okay, create the field
|
||||
|
|
@ -155,6 +150,24 @@ sub delete {
|
|||
$db->deleteRow("userProfileField","fieldName",$self->getId);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 exists ( session, fieldName )
|
||||
|
||||
Class method that returns true if a field with the given name already
|
||||
exists. The first argument is a WebGUI::Session object. C<fieldName> is
|
||||
the field name to check
|
||||
|
||||
=cut
|
||||
|
||||
sub exists {
|
||||
my ( $class, $session, $fieldName ) = @_;
|
||||
|
||||
return 1 if $session->db->quickScalar(
|
||||
"SELECT COUNT(*) FROM userProfileField WHERE fieldName=?",
|
||||
[$fieldName]
|
||||
);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
|
@ -717,12 +730,7 @@ sub rename {
|
|||
|
||||
### Check data
|
||||
# Make sure the field doesn't exist
|
||||
my $fieldNameExists
|
||||
= $self->session->db->quickScalar(
|
||||
"SELECT COUNT(*) FROM userProfileField WHERE fieldName=?",
|
||||
[$newName]
|
||||
);
|
||||
return 0 if ($fieldNameExists);
|
||||
return 0 if $self->exists($session, $newName);
|
||||
|
||||
# Rename the userProfileData column
|
||||
my $fieldClass = $self->getFormControlClass;
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ WebGUI::Test->usersToDelete($newUser);
|
|||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
plan tests => 20; # Increment this number for each test you create
|
||||
plan tests => 22; # Increment this number for each test you create
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Test the creation of ProfileField
|
||||
|
|
@ -102,6 +102,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');
|
||||
|
||||
###########################################################
|
||||
#
|
||||
# exists
|
||||
#
|
||||
###########################################################
|
||||
|
||||
ok( WebGUI::ProfileField->exists($session,"firstName"), "firstName field exists" );
|
||||
ok( !WebGUI::ProfileField->exists($session, time), "random field does not exist" );
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Cleanup
|
||||
END {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue