[Rt-commit] rt branch, 4.4/validate-time-worked, created. rt-4.4.2-240-g89e111f67
? sunnavy
sunnavy at bestpractical.com
Wed May 30 09:25:32 EDT 2018
The branch, 4.4/validate-time-worked has been created
at 89e111f673e818942701db66bff83e8e31e945f5 (commit)
- Log -----------------------------------------------------------------
commit 0d9b7ef9ee6b5ee658d99574101b36461240109c
Author: sunnavy <sunnavy at bestpractical.com>
Date: Wed May 30 20:53:34 2018 +0800
Validate UpdateTimeWorked field on ticket update page
diff --git a/share/html/Ticket/Update.html b/share/html/Ticket/Update.html
index 6e73b50a8..ce81bf6c9 100644
--- a/share/html/Ticket/Update.html
+++ b/share/html/Ticket/Update.html
@@ -333,6 +333,15 @@ if ( $ARGS{'SubmitTicket'} ) {
$checks_failure = 1 unless $status;
}
+if ( $ARGS{UpdateTimeWorked} ) {
+ $ARGS{UpdateTimeWorked} =~ s!^\s+!!;
+ $ARGS{UpdateTimeWorked} =~ s!\s+$!!;
+ if ( $ARGS{UpdateTimeWorked} !~ /^(?:\d+)?(?:\.(?:\d+)?)?$/ ) {
+ push @results, loc('Invalid worked time, should be numeric: "[_1]"', $ARGS{UpdateTimeWorked});
+ $checks_failure = 1;
+ }
+}
+
# check email addresses for RT's
{
foreach my $field ( qw(UpdateCc UpdateBcc) ) {
commit 89e111f673e818942701db66bff83e8e31e945f5
Author: sunnavy <sunnavy at bestpractical.com>
Date: Wed May 30 21:05:04 2018 +0800
Test UpdateTimeWorked validator on ticket update page
diff --git a/t/web/ticket_timeworked.t b/t/web/ticket_timeworked.t
index dc52cebd8..16ad0f03a 100644
--- a/t/web/ticket_timeworked.t
+++ b/t/web/ticket_timeworked.t
@@ -146,4 +146,70 @@ diag "checking child ticket 2 for expected timeworked data"; {
);
}
+diag "checking invalid and edge cased worked time on update";
+{
+ my $ticket = RT::Test->create_ticket( Queue => 'General', Subject => "timeworked", TimeWorked => 30, );
+ my $time = $ticket->TimeWorked;
+ is( $time, 30, "current TimeWorked" );
+
+ $m->goto_ticket( $ticket->id, 'Update' );
+ $m->submit_form_ok(
+ { form_name => 'TicketUpdate', fields => { UpdateTimeWorked => '0,1', }, button => 'SubmitTicket', },
+ 'update TimeWorked with "0,1"' );
+ $m->text_contains( 'Invalid worked time, should be numeric: "0,1"' );
+
+ $ticket->Load( $ticket->id );
+ is( $ticket->TimeWorked, 30, 'TimeWorked is not updated' );
+
+
+ $m->submit_form_ok(
+ {
+ form_name => 'TicketUpdate',
+ fields => { UpdateTimeWorked => '1.5', 'UpdateTimeWorked-TimeUnits' => 'hours' },
+ button => 'SubmitTicket',
+ },
+ 'update TimeWorked with 1.5 hours'
+ );
+ $m->text_lacks( 'Invalid worked time, should be numeric' );
+ $ticket->Load( $ticket->id );
+ is( $ticket->TimeWorked, 120, 'TimeWorked is updated' );
+
+ $m->goto_ticket( $ticket->id, 'Update' );
+ $m->submit_form_ok(
+ {
+ form_name => 'TicketUpdate',
+ fields => { UpdateTimeWorked => '.5', 'UpdateTimeWorked-TimeUnits' => 'hours' },
+ button => 'SubmitTicket',
+ },
+ 'update TimeWorked with .5 hours'
+ );
+ $m->text_lacks( 'Invalid worked time, should be numeric' );
+ $ticket->Load( $ticket->id );
+ is( $ticket->TimeWorked, 150, 'TimeWorked is updated' );
+
+ $m->goto_ticket( $ticket->id, 'Update' );
+ $m->submit_form_ok(
+ { form_name => 'TicketUpdate', fields => { UpdateTimeWorked => '5.' }, button => 'SubmitTicket', },
+ 'update TimeWorked 5. minutes' );
+ $m->text_lacks( 'Invalid worked time, should be numeric' );
+ $ticket->Load( $ticket->id );
+ is( $ticket->TimeWorked, 155, 'TimeWorked is updated' );
+
+ $m->goto_ticket( $ticket->id, 'Update' );
+ $m->submit_form_ok(
+ { form_name => 'TicketUpdate', fields => { UpdateTimeWorked => ' 15 ' }, button => 'SubmitTicket', },
+ 'update TimeWorked with " 15 "' );
+ $m->text_lacks( 'Invalid worked time, should be numeric' );
+ $ticket->Load( $ticket->id );
+ is( $ticket->TimeWorked, 170, 'TimeWorked is updated' );
+
+ $m->goto_ticket( $ticket->id, 'Update' );
+ $m->submit_form_ok(
+ { form_name => 'TicketUpdate', fields => { UpdateTimeWorked => ' ' }, button => 'SubmitTicket', },
+ 'update TimeWorked with just a space' );
+ $m->text_lacks( 'Invalid worked time, should be numeric' );
+ $ticket->Load( $ticket->id );
+ is( $ticket->TimeWorked, 170, 'TimeWorked is not updated' );
+}
+
done_testing();
-----------------------------------------------------------------------
More information about the rt-commit
mailing list