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:
Colin Kuskie 2009-09-21 19:44:43 -07:00
parent f2e8d6a70b
commit 323edd888e
5 changed files with 79 additions and 42 deletions

View file

@ -53,6 +53,7 @@
- fixed #11003: Subscribable AssetAspect: no i18n
- fixed #11004: Subscribable AssetAspect: handling the subscription group
- fixed #10990: Survey: View Transposed Results not working
- fixed #11009: Shipping address is lost after login
7.7.19
- fixed #10838: Forwarded forum post email to new CS adds reply to original thread

View file

@ -24,7 +24,8 @@ Package WebGUI::Shop::Address
=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

View file

@ -85,7 +85,9 @@ Deletes this address book and all addresses contained in it.
sub delete {
my ($self) = @_;
my $myId = id $self;
foreach my $address (@{$self->getAddresses}) {
delete $addressCache{$myId}{$address->getId};
$address->delete;
}
$self->session->db->write("delete from addressBook where addressBookId=?",[$self->getId]);

View file

@ -31,19 +31,12 @@ my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
my $tests = 23;
plan tests => 1 + $tests;
plan tests => 25;
#----------------------------------------------------------------------------
# put your tests here
my $loaded = use_ok('WebGUI::Shop::AddressBook');
my $storage;
SKIP: {
skip 'Unable to load module WebGUI::Shop::AddressBook', $tests unless $loaded;
my $e;
my $book;
@ -155,9 +148,9 @@ my $address2 = $book->addAddress({ label => q{Norton's office} });
my @addresses = @{ $book->getAddresses() };
cmp_deeply(
\@addresses,
[$address1, $address2],
cmp_bag(
[ map { $_->getId } @addresses ],
[$address1->getId, $address2->getId],
'getAddresses returns all address objects for this book'
);
@ -204,11 +197,36 @@ $bookClone->delete();
$bookCount = $session->db->quickScalar('select count(*) from addressBook');
my $addrCount = $session->db->quickScalar('select count(*) from address');
is($bookCount, 0, 'delete: book deleted');
is($addrCount, 0, 'delete: also deletes addresses in the book');
is($bookCount, 0, '... book deleted');
is($addrCount, 0, '... also deletes addresses in the 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 {
$session->db->write('delete from addressBook');

View file

@ -71,6 +71,36 @@ my $smtpdSelect;
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 {
$mocker = Test::MockObject->fake_module(
@ -162,10 +192,8 @@ BEGIN {
exit(1);
}
my $pseudoRequest = WebGUI::PseudoRequest->new;
#$SESSION = WebGUI::Session->open( $WEBGUI_ROOT, $CONFIG_FILE, $pseudoRequest );
$SESSION = WebGUI::Session->open( $WEBGUI_ROOT, $CONFIG_FILE );
$SESSION->{_request} = $pseudoRequest;
$SESSION = WebGUI::Test->newSession;
$originalSetting = clone $SESSION->setting->get;
}
@ -193,10 +221,6 @@ END {
$stor->delete;
}
}
SESSION: foreach my $session (@sessionsToDelete) {
$session->var->end;
$session->close;
}
ASSET: foreach my $asset (@assetsToPurge) {
$asset->purge;
}
@ -243,8 +267,10 @@ END {
while (my ($param, $value) = each %{ $originalSetting }) {
$SESSION->setting->set($param, $value);
}
$SESSION->var->end;
$SESSION->close if defined $SESSION;
SESSION: foreach my $session (@sessionsToDelete) {
$session->var->end;
$session->close;
}
# Close SMTPD
if ($smtpdPid) {
@ -257,6 +283,12 @@ END {
}
}
=head2 newSession ( )
Builds a WebGUI session object for testing.
=cut
=head2 mockAssetId ( $assetId, $object )
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 )
Push a list of version tags to rollback at the end of the test.