migrate Subscription create batch form to FormBuilder
This commit is contained in:
parent
3b4b729518
commit
affafb0038
2 changed files with 105 additions and 40 deletions
|
|
@ -582,45 +582,45 @@ sub www_createSubscriptionCodeBatch {
|
||||||
my $errorMessage = $i18n->get('create batch error').'<ul><li>'.join('</li><li>', @{$error}).'</li></ul>' if ($error);
|
my $errorMessage = $i18n->get('create batch error').'<ul><li>'.join('</li><li>', @{$error}).'</li></ul>' if ($error);
|
||||||
|
|
||||||
# Generate the properties form for this subscription code batch
|
# Generate the properties form for this subscription code batch
|
||||||
my $f = WebGUI::HTMLForm->new( $session );
|
my $f = WebGUI::FormBuilder->new( $session, action => $self->getUrl );
|
||||||
$f->submit;
|
$f->addField( "submit", name => "submit" );
|
||||||
$f->hidden(
|
$f->addField( "hidden",
|
||||||
-name => 'func',
|
name => 'func',
|
||||||
-value => 'createSubscriptionCodeBatchSave'
|
value => 'createSubscriptionCodeBatchSave'
|
||||||
);
|
);
|
||||||
$f->integer(
|
$f->addField( "integer",
|
||||||
-name => 'noc',
|
name => 'noc',
|
||||||
-label => $i18n->get('noc'),
|
label => $i18n->get('noc'),
|
||||||
-hoverHelp => $i18n->get('noc description'),
|
hoverHelp => $i18n->get('noc description'),
|
||||||
-value => $session->form->process("noc") || 1
|
value => $session->form->process("noc") || 1
|
||||||
);
|
);
|
||||||
$f->integer(
|
$f->addField( "integer",
|
||||||
-name => 'codeLength',
|
name => 'codeLength',
|
||||||
-label => $i18n->get('code length'),
|
label => $i18n->get('code length'),
|
||||||
-hoverHelp => $i18n->get('code length description'),
|
hoverHelp => $i18n->get('code length description'),
|
||||||
-value => $session->form->process("codeLength") || 64
|
value => $session->form->process("codeLength") || 64
|
||||||
);
|
);
|
||||||
$f->interval(
|
$f->addField( "interval",
|
||||||
-name => 'expires',
|
name => 'expires',
|
||||||
-label => $i18n->get('codes expire'),
|
label => $i18n->get('codes expire'),
|
||||||
-hoverHelp => $i18n->get('codes expire description'),
|
hoverHelp => $i18n->get('codes expire description'),
|
||||||
-value => $session->form->process("expires") || $session->datetime->intervalToSeconds(1, 'months')
|
value => $session->form->process("expires") || $session->datetime->intervalToSeconds(1, 'months')
|
||||||
);
|
);
|
||||||
$f->text(
|
$f->addField( "text",
|
||||||
-name => 'name',
|
name => 'name',
|
||||||
-label => $i18n->get('batch name'),
|
label => $i18n->get('batch name'),
|
||||||
-hoverHelp => $i18n->get('batch name description'),
|
hoverHelp => $i18n->get('batch name description'),
|
||||||
-value => $session->form->process('name'),
|
value => $session->form->process('name'),
|
||||||
);
|
);
|
||||||
$f->textarea(
|
$f->addField( "textarea",
|
||||||
-name => 'description',
|
name => 'description',
|
||||||
-label => $i18n->get('batch description'),
|
label => $i18n->get('batch description'),
|
||||||
-hoverHelp => $i18n->get('batch description description'),
|
hoverHelp => $i18n->get('batch description description'),
|
||||||
-value => $session->form->process("description"),
|
value => $session->form->process("description"),
|
||||||
);
|
);
|
||||||
$f->submit;
|
$f->addField( "submit", name => "submit" );
|
||||||
|
|
||||||
return $self->getAdminConsoleWithSubmenu->render( $errorMessage.$f->print, $i18n->get('create batch menu') );
|
return $errorMessage.$f->toHtml;
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ use strict;
|
||||||
use Test::More;
|
use Test::More;
|
||||||
use Test::Deep;
|
use Test::Deep;
|
||||||
use WebGUI::Test; # Must use this before any other WebGUI modules
|
use WebGUI::Test; # Must use this before any other WebGUI modules
|
||||||
|
use WebGUI::Test::Mechanize;
|
||||||
use WebGUI::Session;
|
use WebGUI::Session;
|
||||||
use WebGUI::Asset;
|
use WebGUI::Asset;
|
||||||
use WebGUI::Asset::Sku::Subscription;
|
use WebGUI::Asset::Sku::Subscription;
|
||||||
|
|
@ -25,19 +26,19 @@ use WebGUI::Asset::Sku::Subscription;
|
||||||
# Init
|
# Init
|
||||||
my $session = WebGUI::Test->session;
|
my $session = WebGUI::Test->session;
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
|
||||||
# Tests
|
|
||||||
|
|
||||||
plan tests => 4; # Increment this number for each test you create
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
|
||||||
# put your tests here
|
|
||||||
my $group = WebGUI::Group->new($session, 'new');
|
my $group = WebGUI::Group->new($session, 'new');
|
||||||
WebGUI::Test->addToCleanup($group);
|
WebGUI::Test->addToCleanup($group);
|
||||||
my $user = WebGUI::User->create($session);
|
my $user = WebGUI::User->create($session);
|
||||||
WebGUI::Test->addToCleanup($user);
|
WebGUI::Test->addToCleanup($user);
|
||||||
|
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# Tests
|
||||||
|
|
||||||
|
plan tests => 9; # Increment this number for each test you create
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# put your tests here
|
||||||
my $sku = WebGUI::Test->asset(
|
my $sku = WebGUI::Test->asset(
|
||||||
className => "WebGUI::Asset::Sku::Subscription",
|
className => "WebGUI::Asset::Sku::Subscription",
|
||||||
title => "Test Subscription",
|
title => "Test Subscription",
|
||||||
|
|
@ -65,3 +66,67 @@ cmp_deeply(
|
||||||
num(2*$sku->getExpirationOffset, 10),
|
num(2*$sku->getExpirationOffset, 10),
|
||||||
"... increments user's expiration offset when the subscription is non-recurring and they are already a group member"
|
"... increments user's expiration offset when the subscription is non-recurring and they are already a group member"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# www_createSubscriptionBatch
|
||||||
|
my $mech = WebGUI::Test::Mechanize->new( config => WebGUI::Test->file );
|
||||||
|
$mech->get_ok( '/' );
|
||||||
|
$mech->session->user({ userId => 3 });
|
||||||
|
$mech->get_ok( $sku->getUrl( 'func=createSubscriptionCodeBatch' ) );
|
||||||
|
$mech->submit_form_ok( {
|
||||||
|
fields => {
|
||||||
|
noc => 2,
|
||||||
|
codeLength => 20,
|
||||||
|
expires => 60 * 60 * 24 * 14, # 14 days
|
||||||
|
name => "Paycheck",
|
||||||
|
description => "Sign up to get your paycheck!",
|
||||||
|
},
|
||||||
|
}, 'generate subscription codes' );
|
||||||
|
|
||||||
|
my $batches = $session->db->buildArrayRefOfHashRefs(
|
||||||
|
"SELECT * FROM Subscription_codeBatch WHERE subscriptionId=?",
|
||||||
|
[ $sku->getId ],
|
||||||
|
);
|
||||||
|
cmp_deeply( $batches,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
name => "Paycheck",
|
||||||
|
description => "Sign up to get your paycheck!",
|
||||||
|
expirationDate => ignore(),
|
||||||
|
dateCreated => ignore(),
|
||||||
|
subscriptionId => $sku->getId,
|
||||||
|
batchId => ignore(),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"code batch got created",
|
||||||
|
);
|
||||||
|
|
||||||
|
my $codes = $session->db->buildArrayRefOfHashRefs(
|
||||||
|
"SELECT * FROM Subscription_code WHERE batchId=?",
|
||||||
|
[ $batches->[0]->{batchId} ],
|
||||||
|
);
|
||||||
|
cmp_deeply( $codes,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
code => ignore(),
|
||||||
|
batchId => $batches->[0]->{batchId},
|
||||||
|
status => 'Unused',
|
||||||
|
dateUsed => 0,
|
||||||
|
usedBy => 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
code => ignore(),
|
||||||
|
batchId => $batches->[0]->{batchId},
|
||||||
|
status => 'Unused',
|
||||||
|
dateUsed => 0,
|
||||||
|
usedBy => 0,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"codes got created",
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue