finally got shipping driver management working
This commit is contained in:
parent
1658f3957d
commit
819552ce06
9 changed files with 153 additions and 137 deletions
|
|
@ -18,7 +18,7 @@ use strict;
|
||||||
use WebGUI::AdminConsole;
|
use WebGUI::AdminConsole;
|
||||||
use WebGUI::Shop::AddressBook;
|
use WebGUI::Shop::AddressBook;
|
||||||
use WebGUI::Shop::Cart;
|
use WebGUI::Shop::Cart;
|
||||||
#use WebGUI::Shop::Pay;
|
use WebGUI::Shop::Pay;
|
||||||
use WebGUI::Shop::Ship;
|
use WebGUI::Shop::Ship;
|
||||||
use WebGUI::Shop::Tax;
|
use WebGUI::Shop::Tax;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -136,9 +136,9 @@ sub formHeader {
|
||||||
croak "Second parameter must be hash reference"
|
croak "Second parameter must be hash reference"
|
||||||
if ref $params ne "HASH";
|
if ref $params ne "HASH";
|
||||||
|
|
||||||
my $action = exists $params->{ action } ? $params->{ action } : $session->url->page();
|
my $action = (exists $params->{action} && $params->{action} ne "") ? $params->{action} : $session->url->page();
|
||||||
my $method = exists $params->{ method } ? $params->{ method } : "post";
|
my $method = (exists $params->{method} && $params->{method} ne "") ? $params->{method} : "post";
|
||||||
my $enctype = exists $params->{ enctype } ? $params->{ enctype } : "multipart/form-data";
|
my $enctype = (exists $params->{enctype} && $params->{enctype} ne "") ? $params->{enctype} : "multipart/form-data";
|
||||||
|
|
||||||
# Fix a query string in the action URL
|
# Fix a query string in the action URL
|
||||||
my $hidden;
|
my $hidden;
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,7 @@ sub www_editSettings {
|
||||||
my $ac = $self->getAdminConsole;
|
my $ac = $self->getAdminConsole;
|
||||||
my $setting = $self->session->setting;
|
my $setting = $self->session->setting;
|
||||||
my $form = WebGUI::HTMLForm->new($self->session);
|
my $form = WebGUI::HTMLForm->new($self->session);
|
||||||
|
$form->submit;
|
||||||
$form->hidden(name=>"shop", value=>"admin");
|
$form->hidden(name=>"shop", value=>"admin");
|
||||||
$form->hidden(name=>"method", value=>"editSettingsSave");
|
$form->hidden(name=>"method", value=>"editSettingsSave");
|
||||||
$form->template(
|
$form->template(
|
||||||
|
|
|
||||||
|
|
@ -190,6 +190,8 @@ Returns a reference to the current session.
|
||||||
|
|
||||||
=head2 www_addDriver ()
|
=head2 www_addDriver ()
|
||||||
|
|
||||||
|
Adds a ship driver to the shop, then displays it's edit screen.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub www_addDriver {
|
sub www_addDriver {
|
||||||
|
|
@ -202,18 +204,34 @@ sub www_addDriver {
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 www_deleteDriver ()
|
||||||
|
|
||||||
|
Deletes a ship driver from the shop.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub www_deleteDriver {
|
||||||
|
my $self = shift;
|
||||||
|
my $form = $self->session->form;
|
||||||
|
WebGUI::Error::InvalidParam->throw(error => q{must have a form var called driverId with guid }) if ($form->get("driverId") eq "");
|
||||||
|
$self->getShipper($form->get("driverId"))->delete;
|
||||||
|
return $self->www_manage;
|
||||||
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 www_do ( )
|
=head2 www_do ( )
|
||||||
|
|
||||||
Let's ship drivers do method calls. Requires a driver param in the post form vars which contains the id of the driver to load.
|
Let's ship drivers do method calls. Requires a driverId param in the post form vars which contains the id of the driver to load.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub www_do {
|
sub www_do {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
my $form = $self->session->form;
|
my $form = $self->session->form;
|
||||||
WebGUI::Error::InvalidParam->throw(error => q{must have a form var called driver with a driver id }) if ($form->get("driver") eq "");
|
WebGUI::Error::InvalidParam->throw(error => q{must have a form var called driverId with a driver id }) if ($form->get("driverId") eq "");
|
||||||
WebGUI::Error::InvalidParam->throw(error => q{must have a form var called do with a method name in the driver }) if ($form->get("do") eq "");
|
WebGUI::Error::InvalidParam->throw(error => q{must have a form var called do with a method name in the driver }) if ($form->get("do") eq "");
|
||||||
my $driver = $self->getShipper($form->get("driver"));
|
my $driver = $self->getShipper($form->get("driverId"));
|
||||||
my $output = undef;
|
my $output = undef;
|
||||||
my $method = "www_". ( $form->get("do"));
|
my $method = "www_". ( $form->get("do"));
|
||||||
if ($driver->can($method)) {
|
if ($driver->can($method)) {
|
||||||
|
|
@ -243,7 +261,23 @@ sub www_manage {
|
||||||
.WebGUI::Form::submit($session, {value=>$i18n->get("add shipper")})
|
.WebGUI::Form::submit($session, {value=>$i18n->get("add shipper")})
|
||||||
.WebGUI::Form::formFooter($session);
|
.WebGUI::Form::formFooter($session);
|
||||||
foreach my $shipper (@{$self->getShippers}) {
|
foreach my $shipper (@{$self->getShippers}) {
|
||||||
|
$output .= '<div style="clear: both;">'
|
||||||
|
.WebGUI::Form::formHeader($session, {extras=>'style="float: left;"'})
|
||||||
|
.WebGUI::Form::hidden($session, {name=>"shop", value=>"ship"})
|
||||||
|
.WebGUI::Form::hidden($session, {name=>"method", value=>"deleteDriver"})
|
||||||
|
.WebGUI::Form::hidden($session, {name=>"driverId", value=>$shipper->getId})
|
||||||
|
.WebGUI::Form::submit($session, {value=>$i18n->get("delete"), extras=>'class="backwardButton"'})
|
||||||
|
.WebGUI::Form::formFooter($session)
|
||||||
|
.WebGUI::Form::formHeader($session, {extras=>'style="float: left;"'})
|
||||||
|
.WebGUI::Form::hidden($session, {name=>"shop", value=>"ship"})
|
||||||
|
.WebGUI::Form::hidden($session, {name=>"method", value=>"do"})
|
||||||
|
.WebGUI::Form::hidden($session, {name=>"do", value=>"edit"})
|
||||||
|
.WebGUI::Form::hidden($session, {name=>"driverId", value=>$shipper->getId})
|
||||||
|
.WebGUI::Form::submit($session, {value=>$i18n->get("edit"), extras=>'class="normalButton"'})
|
||||||
|
.WebGUI::Form::formFooter($session)
|
||||||
|
.' '
|
||||||
|
.$shipper->get("label")
|
||||||
|
.'</div>';
|
||||||
}
|
}
|
||||||
my $console = $admin->getAdminConsole;
|
my $console = $admin->getAdminConsole;
|
||||||
return $console->render($output, $i18n->get("shipping methods"));
|
return $console->render($output, $i18n->get("shipping methods"));
|
||||||
|
|
|
||||||
|
|
@ -32,34 +32,8 @@ These subroutines are available from this package:
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
readonly session => my %session;
|
readonly session => my %session;
|
||||||
readonly className => my %className;
|
private options => my %options;
|
||||||
readonly shipperId => my %shipperId;
|
private shipperId => my %shipperId;
|
||||||
readonly options => my %options;
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
|
||||||
|
|
||||||
=head2 _buildObj ( )
|
|
||||||
|
|
||||||
Private method used to build objects, shared by new and create.
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
sub _buildObj {
|
|
||||||
my ($class, $session, $requestedClass, $shipperId, $options) = @_;
|
|
||||||
my $self = {};
|
|
||||||
bless $self, $requestedClass;
|
|
||||||
register $self;
|
|
||||||
|
|
||||||
my $id = id $self;
|
|
||||||
|
|
||||||
$session{ $id } = $session;
|
|
||||||
$shipperId{ $id } = $shipperId;
|
|
||||||
$options{ $id } = $options;
|
|
||||||
$className{ $id } = $requestedClass;
|
|
||||||
|
|
||||||
return $self;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -76,15 +50,6 @@ sub calculate {
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 className ( )
|
|
||||||
|
|
||||||
Accessor for the className of the object. This is the name of the driver that is used
|
|
||||||
to do calculations.
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
|
||||||
|
|
||||||
=head2 create ( $session, $options )
|
=head2 create ( $session, $options )
|
||||||
|
|
||||||
Constructor for new WebGUI::Shop::ShipperDriver objects. Returns a WebGUI::Shop::ShipperDriver object.
|
Constructor for new WebGUI::Shop::ShipperDriver objects. Returns a WebGUI::Shop::ShipperDriver object.
|
||||||
|
|
@ -109,11 +74,9 @@ sub create {
|
||||||
WebGUI::Error::InvalidParam->throw(error => q{Must provide a hashref of options})
|
WebGUI::Error::InvalidParam->throw(error => q{Must provide a hashref of options})
|
||||||
unless ref $options eq 'HASH' and scalar keys %{ $options };
|
unless ref $options eq 'HASH' and scalar keys %{ $options };
|
||||||
my $shipperId = $session->id->generate;
|
my $shipperId = $session->id->generate;
|
||||||
my $self = WebGUI::Shop::ShipDriver->_buildObj($session, $class, $shipperId, $options);
|
|
||||||
|
|
||||||
$session->db->write('insert into shipper (shipperId,className) VALUES (?,?)', [$shipperId, $class]);
|
$session->db->write('insert into shipper (shipperId,className) VALUES (?,?)', [$shipperId, $class]);
|
||||||
$self->set($options);
|
my $self = $class->new($session, $shipperId);
|
||||||
|
$self->update($options);
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -167,7 +130,7 @@ Removes this ShipDriver object from the db.
|
||||||
|
|
||||||
sub delete {
|
sub delete {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
$self->session->db->write('delete from shipper');
|
$self->session->db->write('delete from shipper where shipperId=?',[$self->getId]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -190,13 +153,18 @@ return the value from the options hash.
|
||||||
sub get {
|
sub get {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $param = shift;
|
my $param = shift;
|
||||||
my $options = $self->options;
|
my $opts = $options{id $self};
|
||||||
if (defined $param) {
|
if ($opts eq "") {
|
||||||
return $options->{$param};
|
$opts = {};
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return $options;
|
$opts = JSON::from_json($opts);
|
||||||
}
|
}
|
||||||
|
if (defined $param) {
|
||||||
|
return $opts->{$param};
|
||||||
|
}
|
||||||
|
my %copy = %{$opts};
|
||||||
|
return \%copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
@ -214,13 +182,12 @@ sub getEditForm {
|
||||||
my $form = WebGUI::HTMLForm->new($self->session);
|
my $form = WebGUI::HTMLForm->new($self->session);
|
||||||
$form->submit;
|
$form->submit;
|
||||||
$form->hidden(
|
$form->hidden(
|
||||||
name => 'shipperId',
|
name => 'driverId',
|
||||||
value => $self->getId,
|
value => $self->getId,
|
||||||
);
|
);
|
||||||
$form->hidden(
|
$form->hidden(name => 'shop',value => "ship");
|
||||||
name => 'className',
|
$form->hidden(name => 'method',value => "do");
|
||||||
value => $self->className,
|
$form->hidden(name => 'do',value => "editSave");
|
||||||
);
|
|
||||||
$form->dynamicForm($definition, 'properties', $self);
|
$form->dynamicForm($definition, 'properties', $self);
|
||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
|
|
@ -235,7 +202,8 @@ since a lot of WebGUI classes have a getId method.
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub getId {
|
sub getId {
|
||||||
return shift->shipperId;
|
my $self = shift;
|
||||||
|
return $shipperId{id $self};
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
@ -275,26 +243,40 @@ sub new {
|
||||||
my $properties = $session->db->quickHashRef('select * from shipper where shipperId=?',[$shipperId]);
|
my $properties = $session->db->quickHashRef('select * from shipper where shipperId=?',[$shipperId]);
|
||||||
WebGUI::Error::ObjectNotFound->throw(error => q{shipperId not found in db}, id => $shipperId)
|
WebGUI::Error::ObjectNotFound->throw(error => q{shipperId not found in db}, id => $shipperId)
|
||||||
unless scalar keys %{ $properties };
|
unless scalar keys %{ $properties };
|
||||||
##This check is just to guardband the from_json call below.
|
my $self = register $class;
|
||||||
WebGUI::Error::InvalidParam->throw(
|
my $id = id $self;
|
||||||
error => qq{Options property for $shipperId was broken in the db},
|
$session{ $id } = $session;
|
||||||
param => $properties->{options},
|
$options{ $id } = $properties->{options};
|
||||||
) unless $properties->{options}; ##Note, existence is controlled by the columns in the db
|
$shipperId{ $id } = $shipperId;
|
||||||
my $options = from_json($properties->{options});
|
|
||||||
my $self = WebGUI::Shop::ShipDriver->_buildObj($session, $class, $shipperId, $options);
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 options ( )
|
=head2 processPropertiesFromFormPost ( )
|
||||||
|
|
||||||
Accessor for the driver properties. This returns a hashref
|
Updates ship driver with data from Form.
|
||||||
any driver specific properties. To set the properties, use
|
|
||||||
the C<set> method.
|
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
|
sub processPropertiesFromFormPost {
|
||||||
|
my $self = shift;
|
||||||
|
my %properties;
|
||||||
|
my $fullDefinition = $self->definition($self->session);
|
||||||
|
foreach my $definition (@{$fullDefinition}) {
|
||||||
|
foreach my $property (keys %{$definition->{properties}}) {
|
||||||
|
$properties{$property} = $self->session->form->process(
|
||||||
|
$property,
|
||||||
|
$definition->{properties}{$property}{fieldType},
|
||||||
|
$definition->{properties}{$property}{defaultValue}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$properties{title} = $fullDefinition->[0]{name} if ($properties{title} eq "" || lc($properties{title}) eq "untitled");
|
||||||
|
$self->update(\%properties);
|
||||||
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 session ( )
|
=head2 session ( )
|
||||||
|
|
@ -305,7 +287,7 @@ Accessor for the session object. Returns the session object.
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 set ( $options )
|
=head2 update ( $options )
|
||||||
|
|
||||||
Setter for user configurable options in the ship objects.
|
Setter for user configurable options in the ship objects.
|
||||||
|
|
||||||
|
|
@ -316,40 +298,52 @@ flattened into JSON and stored in the database as text. There is no content che
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub set {
|
sub update {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $options = shift;
|
my $options = shift || {};
|
||||||
WebGUI::Error::InvalidParam->throw(error => 'set was not sent a hashref of options to store in the database')
|
WebGUI::Error::InvalidParam->throw(error => 'update was not sent a hashref of options to store in the database')
|
||||||
unless ref $options eq 'HASH' and scalar keys %{ $options };
|
unless ref $options eq 'HASH' and scalar keys %{ $options };
|
||||||
my $jsonOptions = to_json($options);
|
my $jsonOptions = to_json($options);
|
||||||
$self->session->db->write('update shipper set options=? where shipperId=?', [$jsonOptions, $self->shipperId]);
|
$options{id $self} = $jsonOptions;
|
||||||
return;
|
$self->session->db->write('update shipper set options=? where shipperId=?', [$jsonOptions, $self->getId]);
|
||||||
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
|
||||||
|
|
||||||
=head2 shipperId ( )
|
|
||||||
|
|
||||||
Accessor for the unique identifier for this shipperDriver. The shipperId is
|
|
||||||
a GUID.
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 www_edit ( )
|
=head2 www_edit ( )
|
||||||
|
|
||||||
Generates an edito form.
|
Generates an edit form.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub www_edit {
|
sub www_edit {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $admin = WebGUI::Shop::Admin->new($self->session);
|
my $session = $self->session;
|
||||||
my $i18n = WebGUI::International->new($self->session, "Shop");
|
return $session->privilege->insufficient() unless $session->user->isInGroup(3);
|
||||||
return $admin->getAdminConsole->render($self->getEditForm->print, $i18n->get("shipping methods"));
|
my $admin = WebGUI::Shop::Admin->new($session);
|
||||||
|
my $i18n = WebGUI::International->new($session, "Shop");
|
||||||
|
my $form = $self->getEditForm;
|
||||||
|
$form->submit;
|
||||||
|
return $admin->getAdminConsole->render($form->print, $i18n->get("shipping methods"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 www_editSave ( )
|
||||||
|
|
||||||
|
Saves the data from the post.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub www_editSave {
|
||||||
|
my $self = shift;
|
||||||
|
my $session = $self->session;
|
||||||
|
return $session->privilege->insufficient() unless $session->user->isInGroup(3);
|
||||||
|
$self->processPropertiesFromFormPost;
|
||||||
|
$session->http->setRedirect("/?shop=ship;method=manage");
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
||||||
|
|
@ -79,8 +79,8 @@ sub definition {
|
||||||
},
|
},
|
||||||
pricePerWeight => {
|
pricePerWeight => {
|
||||||
fieldType => 'float',
|
fieldType => 'float',
|
||||||
label => $i18n->get('pricePerWeight'),
|
label => $i18n->get('percentageOfWeight'),
|
||||||
hoverHelp => $i18n->get('pricePerWeight help'),
|
hoverHelp => $i18n->get('percentageOfWeight help'),
|
||||||
defaultValue => 0,
|
defaultValue => 0,
|
||||||
},
|
},
|
||||||
pricePerItem => {
|
pricePerItem => {
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,9 @@ sub handler {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ($output eq "chunked") {
|
if ($output eq "chunked") {
|
||||||
|
if ($session->errorHandler->canShowDebug()) {
|
||||||
|
$session->output->print($session->errorHandler->showDebug(),1);
|
||||||
|
}
|
||||||
last;
|
last;
|
||||||
}
|
}
|
||||||
elsif (defined $output && $output ne "") {
|
elsif (defined $output && $output ne "") {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,12 @@ package WebGUI::i18n::English::Shop;
|
||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
our $I18N = {
|
our $I18N = {
|
||||||
|
'add shipper' => {
|
||||||
|
message => q|Add Shipping Method|,
|
||||||
|
lastUpdated => 0,
|
||||||
|
context => q|button in shipping manager|
|
||||||
|
},
|
||||||
|
|
||||||
'shopping cart template' => {
|
'shopping cart template' => {
|
||||||
message => q|Cart Template|,
|
message => q|Cart Template|,
|
||||||
lastUpdated => 0,
|
lastUpdated => 0,
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ my $session = WebGUI::Test->session;
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Tests
|
# Tests
|
||||||
|
|
||||||
my $tests = 42;
|
my $tests = 35;
|
||||||
plan tests => 1 + $tests;
|
plan tests => 1 + $tests;
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
@ -154,6 +154,7 @@ my $options = {
|
||||||
label => 'Slow and dangerous',
|
label => 'Slow and dangerous',
|
||||||
enabled => 1,
|
enabled => 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
$driver = WebGUI::Shop::ShipDriver->create( $session, $options );
|
$driver = WebGUI::Shop::ShipDriver->create( $session, $options );
|
||||||
|
|
||||||
isa_ok($driver, 'WebGUI::Shop::ShipDriver');
|
isa_ok($driver, 'WebGUI::Shop::ShipDriver');
|
||||||
|
|
@ -162,18 +163,16 @@ isa_ok($driver->session, 'WebGUI::Session', 'session method returns a session ob
|
||||||
|
|
||||||
is($session->getId, $driver->session->getId, 'session method returns OUR session object');
|
is($session->getId, $driver->session->getId, 'session method returns OUR session object');
|
||||||
|
|
||||||
like($driver->shipperId, $session->id->getValidator, 'got a valid GUID for shipperId');
|
like($driver->getId, $session->id->getValidator, 'got a valid GUID for shipperId');
|
||||||
is($driver->getId, $driver->shipperId, 'getId returns the same thing as shipperId');
|
|
||||||
|
|
||||||
is($driver->className, ref $driver, 'className property set correctly');
|
|
||||||
|
|
||||||
cmp_deeply($driver->options, $options, 'options accessor works');
|
cmp_deeply($driver->get, $options, 'options accessor works');
|
||||||
|
|
||||||
my $dbData = $session->db->quickHashRef('select * from shipper where shipperId=?',[$driver->shipperId]);
|
my $dbData = $session->db->quickHashRef('select * from shipper where shipperId=?',[$driver->getId]);
|
||||||
cmp_deeply(
|
cmp_deeply(
|
||||||
$dbData,
|
$dbData,
|
||||||
{
|
{
|
||||||
shipperId => $driver->shipperId,
|
shipperId => $driver->getId,
|
||||||
className => ref($driver),
|
className => ref($driver),
|
||||||
options => q|{"label":"Slow and dangerous","enabled":1}|,
|
options => q|{"label":"Slow and dangerous","enabled":1}|,
|
||||||
},
|
},
|
||||||
|
|
@ -194,7 +193,6 @@ is (WebGUI::Shop::ShipDriver->getName($session), 'Shipper Driver', 'getName retu
|
||||||
#
|
#
|
||||||
#######################################################################
|
#######################################################################
|
||||||
|
|
||||||
cmp_deeply($driver->get, $driver->options, 'get works like the options method with no param passed');
|
|
||||||
is($driver->get('enabled'), 1, 'get the enabled entry from the options');
|
is($driver->get('enabled'), 1, 'get the enabled entry from the options');
|
||||||
is($driver->get('label'), 'Slow and dangerous', 'get the label entry from the options');
|
is($driver->get('label'), 'Slow and dangerous', 'get the label entry from the options');
|
||||||
|
|
||||||
|
|
@ -215,7 +213,7 @@ my @forms = HTML::Form->parse($html, 'http://www.webgui.org');
|
||||||
is (scalar @forms, 1, 'getEditForm generates just 1 form');
|
is (scalar @forms, 1, 'getEditForm generates just 1 form');
|
||||||
|
|
||||||
my @inputs = $forms[0]->inputs;
|
my @inputs = $forms[0]->inputs;
|
||||||
is (scalar @inputs, 5, 'getEditForm: the form has 5 controls');
|
is (scalar @inputs, 7, 'getEditForm: the form has 7 controls');
|
||||||
|
|
||||||
my @interestingFeatures;
|
my @interestingFeatures;
|
||||||
foreach my $input (@inputs) {
|
foreach my $input (@inputs) {
|
||||||
|
|
@ -232,11 +230,19 @@ cmp_deeply(
|
||||||
type => 'submit',
|
type => 'submit',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name => 'shipperId',
|
name => 'driverId',
|
||||||
type => 'hidden',
|
type => 'hidden',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name => 'className',
|
name => 'shop',
|
||||||
|
type => 'hidden',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name => 'method',
|
||||||
|
type => 'hidden',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name => 'do',
|
||||||
type => 'hidden',
|
type => 'hidden',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -295,40 +301,12 @@ cmp_deeply(
|
||||||
'new croaks unless the requested shipperId object exists in the db',
|
'new croaks unless the requested shipperId object exists in the db',
|
||||||
);
|
);
|
||||||
|
|
||||||
my $driverCopy = WebGUI::Shop::ShipDriver->new($session, $driver->shipperId);
|
my $driverCopy = WebGUI::Shop::ShipDriver->new($session, $driver->getId);
|
||||||
|
|
||||||
is($driver->getId, $driverCopy->getId, 'same id');
|
is($driver->getId, $driverCopy->getId, 'same id');
|
||||||
is($driver->className, $driverCopy->className, 'same className');
|
is(ref $driver, ref $driverCopy, 'same className');
|
||||||
cmp_deeply($driver->options, $driverCopy->options, 'same options');
|
cmp_deeply($driver->get, $driverCopy->get, 'same options');
|
||||||
|
|
||||||
my $brokenDriver = WebGUI::Shop::ShipDriver->create($session, {label=>'to be broken', enabled=>'0'});
|
|
||||||
$session->db->write('update shipper set options=NULL where shipperId=?',[$brokenDriver->getId]);
|
|
||||||
|
|
||||||
eval { $oldDriver = WebGUI::Shop::ShipDriver->new($session, $brokenDriver->getId); };
|
|
||||||
$e = Exception::Class->caught();
|
|
||||||
isa_ok($e, 'WebGUI::Error::InvalidParam', 'new croaks if the options column in the db is null');
|
|
||||||
cmp_deeply(
|
|
||||||
$e,
|
|
||||||
methods(
|
|
||||||
error => re('Options property for \S{22} was broken in the db'),
|
|
||||||
param => undef,
|
|
||||||
),
|
|
||||||
'new croaks if the options column in the db is null',
|
|
||||||
);
|
|
||||||
|
|
||||||
$session->db->write(q{update shipper set options='' where shipperId=?},[$brokenDriver->getId]);
|
|
||||||
|
|
||||||
eval { $oldDriver = WebGUI::Shop::ShipDriver->new($session, $brokenDriver->getId); };
|
|
||||||
$e = Exception::Class->caught();
|
|
||||||
isa_ok($e, 'WebGUI::Error::InvalidParam', 'new croaks if the options column in the db is empty string');
|
|
||||||
cmp_deeply(
|
|
||||||
$e,
|
|
||||||
methods(
|
|
||||||
error => re('Options property for \S{22} was broken in the db'),
|
|
||||||
param => '',
|
|
||||||
),
|
|
||||||
'new croaks if the options column in the db is empty string',
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
|
|
@ -346,15 +324,15 @@ like ($@, qr/^You must override the calculate method/, 'calculate croaks to forc
|
||||||
#
|
#
|
||||||
#######################################################################
|
#######################################################################
|
||||||
|
|
||||||
eval { $driver->set(); };
|
eval { $driver->update(); };
|
||||||
$e = Exception::Class->caught();
|
$e = Exception::Class->caught();
|
||||||
isa_ok($e, 'WebGUI::Error::InvalidParam', 'set takes exception to not giving it a hashref of options');
|
isa_ok($e, 'WebGUI::Error::InvalidParam', 'update takes exception to not giving it a hashref of options');
|
||||||
cmp_deeply(
|
cmp_deeply(
|
||||||
$e,
|
$e,
|
||||||
methods(
|
methods(
|
||||||
error => 'set was not sent a hashref of options to store in the database',
|
error => 'update was not sent a hashref of options to store in the database',
|
||||||
),
|
),
|
||||||
'set takes exception to not giving it a hashref of options',
|
'update takes exception to not giving it a hashref of options',
|
||||||
);
|
);
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue