From d35e1285281d2d1179ce9bac8e4fe53a8e6204bd Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Tue, 25 Jan 2011 17:18:19 -0600 Subject: [PATCH] migrate listSubscriptionCodes to FormBuilder --- lib/WebGUI/Asset/Sku/Subscription.pm | 25 +++++------ t/Asset/Sku/Subscription.t | 62 +++++++++++++++++++++++++++- 2 files changed, 73 insertions(+), 14 deletions(-) diff --git a/lib/WebGUI/Asset/Sku/Subscription.pm b/lib/WebGUI/Asset/Sku/Subscription.pm index 9b4b94c88..ed392d2de 100644 --- a/lib/WebGUI/Asset/Sku/Subscription.pm +++ b/lib/WebGUI/Asset/Sku/Subscription.pm @@ -858,13 +858,13 @@ sub www_listSubscriptionCodes { # Build a subscription code selection form - my $f = WebGUI::HTMLForm->new( $session ); - $f->hidden( + my $f = WebGUI::FormBuilder->new( $session, action => $self->getUrl ); + $f->addField( "hidden", name => 'func', value => 'listSubscriptionCodes', ); - #--- Selection by date created - $f->readOnly( + #--- Selection by date used + $f->addField( "readOnly", label => WebGUI::Form::radio( $session, { name => 'selection', value => 'du', checked => ($selection eq 'du') } ) . $i18n->get('selection used'), @@ -873,8 +873,8 @@ sub www_listSubscriptionCodes { . ' ' . $i18n->get( 'and' ) . ' ' . WebGUI::Form::date( $session, { name => 'duStop', value=> $duStop } ), ); - #--- Selection by date used - $f->readOnly( + #--- Selection by date created + $f->addField( "readOnly", label => WebGUI::Form::radio( $session, { name => 'selection', value => 'dc', checked => ($selection eq 'dc') } ) . $i18n->get('selection created'), @@ -884,7 +884,7 @@ sub www_listSubscriptionCodes { . WebGUI::Form::date( $session, { name => 'dcStop', value=> $dcStop } ), ); #--- Selection by batch - $f->readOnly( + $f->addField( "readOnly", label => WebGUI::Form::radio( $session, { name => 'selection', value => 'b', checked => ($selection eq 'b') } ) . $i18n->get('selection batch name'), @@ -892,10 +892,13 @@ sub www_listSubscriptionCodes { WebGUI::Form::selectBox( $session, { name => 'bid', value => $batchId, options => $batches } ), ); #--- Submit button - $f->submit( + $f->addField( "submit", value => $i18n->get('select'), ); + $output = $i18n->get('selection message'); + $output .= $f->toHtml; + if ($session->form->process("selection") eq 'du') { $where = " and dateUsed >= ".$session->db->quote($duStart)." and dateUsed <= ".$session->db->quote($duStop); $ops = ';duStart='.$session->form->process('duStart').';duStop='.$session->form->process('duStop').';selection=du'; @@ -909,7 +912,7 @@ sub www_listSubscriptionCodes { $ops = ';bid='.$session->form->process("bid").';selection=b'; $delete = ''.$i18n->get('delete codes').''; } else { - return $self->getAdminConsoleWithSubmenu->render( $output, $i18n->get('listSubscriptionCodes title') ); + return $output; } $p = WebGUI::Paginator->new( $session, $self->getUrl('func=listSubscriptionCodes'.$ops) ); @@ -924,8 +927,6 @@ sub www_listSubscriptionCodes { $codes = $p->getPageData; - $output = $i18n->get('selection message'); - $output .= $f->print; $output .= '
'.$delete.'
' if ($delete) and $p->getRowCount; $output .= $p->getBarTraditional($session->form->process("pn")); $output .= '
'; @@ -947,7 +948,7 @@ sub www_listSubscriptionCodes { $output .= ''; $output .= $p->getBarTraditional($session->form->process("pn")); - return $self->getAdminConsoleWithSubmenu->render( $output, $i18n->get('listSubscriptionCodes title') ); + return $output; } diff --git a/t/Asset/Sku/Subscription.t b/t/Asset/Sku/Subscription.t index a19420f24..2ae6c1cfa 100644 --- a/t/Asset/Sku/Subscription.t +++ b/t/Asset/Sku/Subscription.t @@ -35,7 +35,7 @@ WebGUI::Test->addToCleanup($user); #---------------------------------------------------------------------------- # Tests -plan tests => 16; # Increment this number for each test you create +plan tests => 32; # Increment this number for each test you create #---------------------------------------------------------------------------- # put your tests here @@ -133,7 +133,7 @@ $mech->get_ok( '/' ); $mech->session->user({ userId => 3 }); # Add another code for the selection -$session->db->setRow( 'Subscription_codeBatch', 'batchId', { +my $batchId = $session->db->setRow( 'Subscription_codeBatch', 'batchId', { batchId => 'new', name => "Fired!", description => "Sign up to get fired!", @@ -156,4 +156,62 @@ $mech->content_lacks( "Sign up to get your paycheck!" ); $mech->text_contains( "Sign up to get fired!" ); +#---------------------------------------------------------------------------- +# www_listSubscriptionCodes +my $mech = WebGUI::Test::Mechanize->new( config => WebGUI::Test->file ); +$mech->get_ok( '/' ); +$mech->session->user({ userId => 3 }); + +# Add more codes for the selection +my $codeId = $session->db->setRow( 'Subscription_code', 'code', { + batchId => $batchId, + usedBy => 3, + dateUsed => time+150, +}, "1234567890qwertyuiopasdfghjklzxcvbnm" ); + +# Limit by dateCreated +$mech->get_ok( $sku->getUrl( 'func=listSubscriptionCodes' ) ); +$mech->submit_form_ok( { + fields => { + selection => "dc", + dcStart => time+1000, + dcStop => time+2000, + }, +}, 'limit subscription code batches by date created' ); + +# The codes are there +$mech->content_lacks( $codes->[0]{code} ); +$mech->content_lacks( $codes->[1]{code} ); +$mech->content_contains( $codeId ); + +# Limit by dateUsed +$mech->get_ok( $sku->getUrl( 'func=listSubscriptionCodes' ) ); +$mech->submit_form_ok( { + fields => { + selection => "du", + duStart => time+100, + duStop => time+200, + }, +}, 'limit subscription code batches by date used' ); + +# The codes are there +$mech->content_lacks( $codes->[0]{code} ); +$mech->content_lacks( $codes->[1]{code} ); +$mech->content_contains( $codeId ); + +# Limit by batchId +$mech->get_ok( $sku->getUrl( 'func=listSubscriptionCodes' ) ); +$mech->submit_form_ok( { + fields => { + selection => "b", + bid => $batches->[0]{batchId}, + }, +}, 'limit subscription code batches by batchId' ); + +# The codes are there +$mech->content_contains( $codes->[0]{code} ); +$mech->content_contains( $codes->[1]{code} ); +$mech->content_lacks( $codeId ); + +