[Rt-commit] r3421 - in rt/branches/CHALDEA-EXPERIMENTAL/lib: RT t/regression

autrijus at bestpractical.com autrijus at bestpractical.com
Thu Jul 7 21:37:26 EDT 2005


Author: autrijus
Date: Thu Jul  7 21:37:26 2005
New Revision: 3421

Modified:
   rt/branches/CHALDEA-EXPERIMENTAL/lib/RT/CustomField_Overlay.pm
   rt/branches/CHALDEA-EXPERIMENTAL/lib/t/regression/15cf_pattern.t
Log:
* When deleting the value of a single-value field, we need to validate that
  empty string is a valid value for it.
* Also adds regression tests for this.

Modified: rt/branches/CHALDEA-EXPERIMENTAL/lib/RT/CustomField_Overlay.pm
==============================================================================
--- rt/branches/CHALDEA-EXPERIMENTAL/lib/RT/CustomField_Overlay.pm	(original)
+++ rt/branches/CHALDEA-EXPERIMENTAL/lib/RT/CustomField_Overlay.pm	Thu Jul  7 21:37:26 2005
@@ -1139,10 +1139,16 @@
     }
 
 
-    # check ot make sure we found it
+    # check to make sure we found it
     unless ($oldval->Id) {
         return(0, $self->loc("Custom field value [_1] could not be found for custom field [_2]", $args{'Content'}, $self->Name));
     }
+
+    # for single-value fields, we need to validate that empty string is a valid value for it
+    if ( $self->SingleValue and not $self->MatchPattern( '' ) ) {
+        return ( 0, $self->loc('Input must match [_1]', $self->FriendlyPattern) );
+    }
+
     # delete it
 
     my $ret = $oldval->Delete();

Modified: rt/branches/CHALDEA-EXPERIMENTAL/lib/t/regression/15cf_pattern.t
==============================================================================
--- rt/branches/CHALDEA-EXPERIMENTAL/lib/t/regression/15cf_pattern.t	(original)
+++ rt/branches/CHALDEA-EXPERIMENTAL/lib/t/regression/15cf_pattern.t	Thu Jul  7 21:37:26 2005
@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 use warnings;
 use strict;
-use Test::More tests => 13;
+use Test::More tests => 17;
 
 use RT;
 RT::LoadConfig();
@@ -19,7 +19,7 @@
 works($q->Create(Name => "CF-Pattern-".$$));
 
 my $cf = new(RT::CustomField);
-my @cf_args = (Name => $q->Name, Type => 'Freeform', Queue => $q->id);
+my @cf_args = (Name => $q->Name, Type => 'Freeform', Queue => $q->id, MaxValues => 1);
 
 fails($cf->Create(@cf_args, Pattern => ')))bad!regex((('));
 works($cf->Create(@cf_args, Pattern => 'good regex'));
@@ -31,12 +31,20 @@
 # OK, I'm thoroughly brain washed by HOP at this point now...
 sub cnt { $t->CustomFieldValues($cf->id)->Count };
 sub add { $t->AddCustomFieldValue(Field => $cf->id, Value => $_[0]) };
+sub del { $t->DeleteCustomFieldValue(Field => $cf->id, Value => $_[0]) };
 
 is(cnt(), 0, "No values yet");
 fails(add('not going to match'));
 is(cnt(), 0, "No values yet");
 works(add('here is a good regex'));
 is(cnt(), 1, "Value filled");
+fails(del('here is a good regex'));
+is(cnt(), 1, "Single CF - Value _not_ deleted");
+
+$cf->SetMaxValues(0);   # Unlimited MaxValues
+
+works(del('here is a good regex'));
+is(cnt(), 0, "Multiple CF - Value deleted");
 
 fails($cf->SetPattern('(?{ "insert evil code here" })'));
 works($cf->SetPattern('(?!)')); # reject everything


More information about the Rt-commit mailing list