More tests for bug fix #11009.
Abstract out making a session in WebGUI::Test. Update POD in Shop/Address. Add tests for newBySession, showing that the previous commit that allows update to update addressBookId actually fixed the bug in question.
This commit is contained in:
parent
f2e8d6a70b
commit
323edd888e
5 changed files with 79 additions and 42 deletions
|
|
@ -53,6 +53,7 @@
|
||||||
- fixed #11003: Subscribable AssetAspect: no i18n
|
- fixed #11003: Subscribable AssetAspect: no i18n
|
||||||
- fixed #11004: Subscribable AssetAspect: handling the subscription group
|
- fixed #11004: Subscribable AssetAspect: handling the subscription group
|
||||||
- fixed #10990: Survey: View Transposed Results not working
|
- fixed #10990: Survey: View Transposed Results not working
|
||||||
|
- fixed #11009: Shipping address is lost after login
|
||||||
|
|
||||||
7.7.19
|
7.7.19
|
||||||
- fixed #10838: Forwarded forum post email to new CS adds reply to original thread
|
- fixed #10838: Forwarded forum post email to new CS adds reply to original thread
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,8 @@ Package WebGUI::Shop::Address
|
||||||
|
|
||||||
=head1 DESCRIPTION
|
=head1 DESCRIPTION
|
||||||
|
|
||||||
An address is used to track shipping or payment addresses in the commerce system.
|
An address is used to track shipping or payment addresses in the commerce system. Because of
|
||||||
|
object caching in the AddressBook, addresses should never, ever be accessed directly.
|
||||||
|
|
||||||
=head1 SYNOPSIS
|
=head1 SYNOPSIS
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,9 @@ Deletes this address book and all addresses contained in it.
|
||||||
|
|
||||||
sub delete {
|
sub delete {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
|
my $myId = id $self;
|
||||||
foreach my $address (@{$self->getAddresses}) {
|
foreach my $address (@{$self->getAddresses}) {
|
||||||
|
delete $addressCache{$myId}{$address->getId};
|
||||||
$address->delete;
|
$address->delete;
|
||||||
}
|
}
|
||||||
$self->session->db->write("delete from addressBook where addressBookId=?",[$self->getId]);
|
$self->session->db->write("delete from addressBook where addressBookId=?",[$self->getId]);
|
||||||
|
|
|
||||||
|
|
@ -31,19 +31,12 @@ my $session = WebGUI::Test->session;
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Tests
|
# Tests
|
||||||
|
|
||||||
my $tests = 23;
|
plan tests => 25;
|
||||||
plan tests => 1 + $tests;
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# put your tests here
|
# put your tests here
|
||||||
|
|
||||||
my $loaded = use_ok('WebGUI::Shop::AddressBook');
|
|
||||||
|
|
||||||
my $storage;
|
my $storage;
|
||||||
|
|
||||||
SKIP: {
|
|
||||||
|
|
||||||
skip 'Unable to load module WebGUI::Shop::AddressBook', $tests unless $loaded;
|
|
||||||
my $e;
|
my $e;
|
||||||
my $book;
|
my $book;
|
||||||
|
|
||||||
|
|
@ -155,9 +148,9 @@ my $address2 = $book->addAddress({ label => q{Norton's office} });
|
||||||
|
|
||||||
my @addresses = @{ $book->getAddresses() };
|
my @addresses = @{ $book->getAddresses() };
|
||||||
|
|
||||||
cmp_deeply(
|
cmp_bag(
|
||||||
\@addresses,
|
[ map { $_->getId } @addresses ],
|
||||||
[$address1, $address2],
|
[$address1->getId, $address2->getId],
|
||||||
'getAddresses returns all address objects for this book'
|
'getAddresses returns all address objects for this book'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -204,11 +197,36 @@ $bookClone->delete();
|
||||||
$bookCount = $session->db->quickScalar('select count(*) from addressBook');
|
$bookCount = $session->db->quickScalar('select count(*) from addressBook');
|
||||||
my $addrCount = $session->db->quickScalar('select count(*) from address');
|
my $addrCount = $session->db->quickScalar('select count(*) from address');
|
||||||
|
|
||||||
is($bookCount, 0, 'delete: book deleted');
|
is($bookCount, 0, '... book deleted');
|
||||||
is($addrCount, 0, 'delete: also deletes addresses in the book');
|
is($addrCount, 0, '... also deletes addresses in the book');
|
||||||
undef $book;
|
undef $book;
|
||||||
|
|
||||||
}
|
#######################################################################
|
||||||
|
#
|
||||||
|
# newBySession
|
||||||
|
#
|
||||||
|
#######################################################################
|
||||||
|
|
||||||
|
|
||||||
|
my $otherSession = WebGUI::Test->newSession;
|
||||||
|
my $mergeUser = WebGUI::User->create($otherSession);
|
||||||
|
WebGUI::Test->usersToDelete($mergeUser);
|
||||||
|
$otherSession->user({user => $mergeUser});
|
||||||
|
my $adminBook = WebGUI::Shop::AddressBook->create($otherSession);
|
||||||
|
my $goodAddress = $adminBook->addAddress({label => 'first'});
|
||||||
|
|
||||||
|
my $session2 = WebGUI::Test->newSession;
|
||||||
|
$session2->user({user => $mergeUser});
|
||||||
|
my $bookAdmin = WebGUI::Shop::AddressBook->newBySession($session2);
|
||||||
|
|
||||||
|
cmp_bag(
|
||||||
|
[ map { $_->getId } @{ $bookAdmin->getAddresses } ],
|
||||||
|
[ $goodAddress->getId, ],
|
||||||
|
'newBySession merges address books by userId'
|
||||||
|
);
|
||||||
|
|
||||||
|
$adminBook->delete;
|
||||||
|
$bookAdmin->delete;
|
||||||
|
|
||||||
END {
|
END {
|
||||||
$session->db->write('delete from addressBook');
|
$session->db->write('delete from addressBook');
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,36 @@ my $smtpdSelect;
|
||||||
|
|
||||||
my $mocker;
|
my $mocker;
|
||||||
|
|
||||||
|
BEGIN {
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 sessionsToDelete ( $session, [$session, ...] )
|
||||||
|
|
||||||
|
Push a list of session objects onto the stack of groups to be automatically deleted
|
||||||
|
at the end of the test. Note, this will be the last group of objects to be
|
||||||
|
cleaned up.
|
||||||
|
|
||||||
|
This is a class method.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub sessionsToDelete {
|
||||||
|
my $class = shift;
|
||||||
|
push @sessionsToDelete, @_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub newSession {
|
||||||
|
my $pseudoRequest = WebGUI::PseudoRequest->new;
|
||||||
|
my $session = WebGUI::Session->open( $WEBGUI_ROOT, $CONFIG_FILE );
|
||||||
|
$session->{_request} = $pseudoRequest;
|
||||||
|
WebGUI::Test->sessionsToDelete($session);
|
||||||
|
return $session;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
|
|
||||||
$mocker = Test::MockObject->fake_module(
|
$mocker = Test::MockObject->fake_module(
|
||||||
|
|
@ -162,10 +192,8 @@ BEGIN {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
my $pseudoRequest = WebGUI::PseudoRequest->new;
|
|
||||||
#$SESSION = WebGUI::Session->open( $WEBGUI_ROOT, $CONFIG_FILE, $pseudoRequest );
|
$SESSION = WebGUI::Test->newSession;
|
||||||
$SESSION = WebGUI::Session->open( $WEBGUI_ROOT, $CONFIG_FILE );
|
|
||||||
$SESSION->{_request} = $pseudoRequest;
|
|
||||||
|
|
||||||
$originalSetting = clone $SESSION->setting->get;
|
$originalSetting = clone $SESSION->setting->get;
|
||||||
}
|
}
|
||||||
|
|
@ -193,10 +221,6 @@ END {
|
||||||
$stor->delete;
|
$stor->delete;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SESSION: foreach my $session (@sessionsToDelete) {
|
|
||||||
$session->var->end;
|
|
||||||
$session->close;
|
|
||||||
}
|
|
||||||
ASSET: foreach my $asset (@assetsToPurge) {
|
ASSET: foreach my $asset (@assetsToPurge) {
|
||||||
$asset->purge;
|
$asset->purge;
|
||||||
}
|
}
|
||||||
|
|
@ -243,8 +267,10 @@ END {
|
||||||
while (my ($param, $value) = each %{ $originalSetting }) {
|
while (my ($param, $value) = each %{ $originalSetting }) {
|
||||||
$SESSION->setting->set($param, $value);
|
$SESSION->setting->set($param, $value);
|
||||||
}
|
}
|
||||||
$SESSION->var->end;
|
SESSION: foreach my $session (@sessionsToDelete) {
|
||||||
$SESSION->close if defined $SESSION;
|
$session->var->end;
|
||||||
|
$session->close;
|
||||||
|
}
|
||||||
|
|
||||||
# Close SMTPD
|
# Close SMTPD
|
||||||
if ($smtpdPid) {
|
if ($smtpdPid) {
|
||||||
|
|
@ -257,6 +283,12 @@ END {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
=head2 newSession ( )
|
||||||
|
|
||||||
|
Builds a WebGUI session object for testing.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
=head2 mockAssetId ( $assetId, $object )
|
=head2 mockAssetId ( $assetId, $object )
|
||||||
|
|
||||||
Causes WebGUI::Asset->new* initializers to return the specified
|
Causes WebGUI::Asset->new* initializers to return the specified
|
||||||
|
|
@ -716,23 +748,6 @@ sub storagesToDelete {
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 sessionsToDelete ( $session, [$session, ...] )
|
|
||||||
|
|
||||||
Push a list of session objects onto the stack of groups to be automatically deleted
|
|
||||||
at the end of the test. Note, this will be the last group of objects to be
|
|
||||||
cleaned up.
|
|
||||||
|
|
||||||
This is a class method.
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
sub sessionsToDelete {
|
|
||||||
my $class = shift;
|
|
||||||
push @sessionsToDelete, @_;
|
|
||||||
}
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
=head2 tagsToRollback ( $tag )
|
=head2 tagsToRollback ( $tag )
|
||||||
|
|
||||||
Push a list of version tags to rollback at the end of the test.
|
Push a list of version tags to rollback at the end of the test.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue