Add better support for user profile fields for addresses to the Cart and the EMS.
This commit is contained in:
parent
39049e1c7c
commit
428ea58327
21 changed files with 1657 additions and 62 deletions
218
t/Account/Profile.t
Normal file
218
t/Account/Profile.t
Normal file
|
|
@ -0,0 +1,218 @@
|
|||
# vim:syntax=perl
|
||||
#-------------------------------------------------------------------
|
||||
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
|
||||
#-------------------------------------------------------------------
|
||||
# Please read the legal notices (docs/legal.txt) and the license
|
||||
# (docs/license.txt) that came with this distribution before using
|
||||
# this software.
|
||||
#------------------------------------------------------------------
|
||||
# http://www.plainblack.com info@plainblack.com
|
||||
#------------------------------------------------------------------
|
||||
|
||||
# This tests the operation of WebGUI::Account modules. You can use
|
||||
# as a base to test your own modules.
|
||||
|
||||
use FindBin;
|
||||
use strict;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use Test::More;
|
||||
use Test::Deep;
|
||||
use Exception::Class;
|
||||
|
||||
use WebGUI::Test; # Must use this before any other WebGUI modules
|
||||
use WebGUI::Session;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Init
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
my $andy = WebGUI::User->new($session, "new");
|
||||
WebGUI::Test->addToCleanup($andy);
|
||||
$session->user({userId => $andy->getId});
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
plan tests => 17; # Increment this number for each test you create
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Test the creation of WebGUI::Account::Profile
|
||||
|
||||
# Can we load it?
|
||||
use_ok( "WebGUI::Account::Profile" );
|
||||
|
||||
SKIP: { # Not everyone has Test::Exception yet
|
||||
eval { require Test::Exception; import Test::Exception };
|
||||
# Skip 1 test if Test::Exception couldn't be loaded
|
||||
skip 1, 'Test::Exception not found' if $@;
|
||||
throws_ok( sub { WebGUI::Account::Profile->new }, 'WebGUI::Error::InvalidObject',
|
||||
'new() throws exception without session object'
|
||||
);
|
||||
};
|
||||
|
||||
my $profile;
|
||||
ok( $profile = WebGUI::Account::Profile->new( $session ),
|
||||
"WebGUI::Account::Profile object created successfully"
|
||||
);
|
||||
|
||||
# Test $profile->isa
|
||||
isa_ok( $profile, "WebGUI::Account", 'Blessed into the right class' );
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Test getUrl
|
||||
|
||||
is( $profile->getUrl, $session->url->page('op=account;module=;do='.$profile->method),
|
||||
'getUrl adds op, module, and do since no method has been set'
|
||||
);
|
||||
|
||||
is( $profile->getUrl( 'foo=bar' ), $session->url->page( 'op=account;foo=bar' ),
|
||||
'getUrl adds op if passed other parameters'
|
||||
);
|
||||
|
||||
is( $profile->getUrl( 'op=account' ), $session->url->page( 'op=account' ),
|
||||
'getUrl doesnt add op=account if already exists'
|
||||
);
|
||||
|
||||
#######################################################################
|
||||
#
|
||||
# www_editSave
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
tie my %profile_info, "Tie::IxHash", (
|
||||
firstName => "Andy",
|
||||
lastName => "Dufresne",
|
||||
homeAddress => "123 Shank Ave.",
|
||||
homeCity => "Shawshank",
|
||||
homeState => "PA",
|
||||
homeZip => "11223",
|
||||
homeCountry => "US",
|
||||
homePhone => "111-111-1111",
|
||||
email => 'andy@shawshank.com'
|
||||
);
|
||||
|
||||
$session->request->setup_body( \%profile_info );
|
||||
|
||||
$profile->www_editSave;
|
||||
|
||||
#Reset andy to the session users since stuff has changed
|
||||
$andy = $session->user;
|
||||
|
||||
#Test that the address was saved to the profile
|
||||
cmp_bag(
|
||||
[ map { $andy->profileField($_) } keys %profile_info ],
|
||||
[ values %profile_info ],
|
||||
'Profile fields were saved'
|
||||
);
|
||||
|
||||
#Test that the addressBook was created
|
||||
my $bookId = $session->db->quickScalar(
|
||||
q{ select addressBookId from addressBook where userId=? },
|
||||
[$andy->getId]
|
||||
);
|
||||
|
||||
ok( ($bookId ne ""), "Address Book was created");
|
||||
|
||||
my $book = WebGUI::Shop::AddressBook->new($session,$bookId);
|
||||
|
||||
my @addresses = @{ $book->getAddresses() };
|
||||
|
||||
is(scalar(@addresses), 1 , "One address was created in the address book");
|
||||
|
||||
my $address = $addresses[0];
|
||||
|
||||
tie my %address_info, "Tie::IxHash", (
|
||||
firstName => $address->get("firstName"),
|
||||
lastName => $address->get("lastName"),
|
||||
homeAddress => $address->get("address1"),
|
||||
homeCity => $address->get("city"),
|
||||
homeState => $address->get("state"),
|
||||
homeZip => $address->get("code"),
|
||||
homeCountry => $address->get("country"),
|
||||
homePhone => $address->get("phoneNumber"),
|
||||
email => $address->get("email")
|
||||
);
|
||||
|
||||
#Test that the address was saved properly to shop
|
||||
cmp_bag(
|
||||
[ values %profile_info ],
|
||||
[ values %address_info ],
|
||||
'Shop address was has the right information'
|
||||
);
|
||||
|
||||
#Test that the address is returned as the profile address
|
||||
my $profileAddress = $book->getProfileAddress;
|
||||
is($profileAddress->getId, $address->getId, "Profile linked properly to address");
|
||||
|
||||
#Test that the address is the default address
|
||||
my $defaultAddress = $book->getDefaultAddress;
|
||||
is(
|
||||
$defaultAddress->getId,
|
||||
$address->getId,
|
||||
"Profile address properly set to default address when created"
|
||||
);
|
||||
|
||||
#Test updates to existing addresses
|
||||
%profile_info = (
|
||||
firstName => "Andy",
|
||||
lastName => "Dufresne",
|
||||
homeAddress => "123 Seaside Ave.",
|
||||
homeCity => "Zihuatanejo",
|
||||
homeState => "Guerrero",
|
||||
homeZip => "40880",
|
||||
homeCountry => "MX",
|
||||
homePhone => "222-222-2222",
|
||||
email => 'andy@freeman.com'
|
||||
);
|
||||
|
||||
$session->request->setup_body( \%profile_info );
|
||||
|
||||
$profile->www_editSave;
|
||||
|
||||
$andy = $session->user;
|
||||
|
||||
#Test that the address was saved to the profile
|
||||
cmp_bag (
|
||||
[ map { $andy->profileField($_) } keys %profile_info ],
|
||||
[ values %profile_info ],
|
||||
'Profile fields were updated'
|
||||
);
|
||||
|
||||
#Test that there is still only one address book and one address
|
||||
my @bookIds = $session->db->quickArray(
|
||||
q{ select addressBookId from addressBook where userId=? },
|
||||
[$andy->getId]
|
||||
);
|
||||
|
||||
is( scalar(@bookIds), 1, "Only one address book exists after update" );
|
||||
|
||||
$bookId = $bookIds[0];
|
||||
$book = WebGUI::Shop::AddressBook->new($session,$bookId);
|
||||
@addresses = @{ $book->getAddresses() };
|
||||
|
||||
is( scalar(@addresses), 1 , "Only one address exists after update");
|
||||
|
||||
my $address = $addresses[0];
|
||||
|
||||
%address_info = (
|
||||
firstName => $address->get("firstName"),
|
||||
lastName => $address->get("lastName"),
|
||||
homeAddress => $address->get("address1"),
|
||||
homeCity => $address->get("city"),
|
||||
homeState => $address->get("state"),
|
||||
homeZip => $address->get("code"),
|
||||
homeCountry => $address->get("country"),
|
||||
homePhone => $address->get("phoneNumber"),
|
||||
email => $address->get("email")
|
||||
);
|
||||
|
||||
#Test that the address was saved properly to shop
|
||||
cmp_bag(
|
||||
[ values %profile_info ],
|
||||
[ values %address_info ],
|
||||
'Shop address was has the right information'
|
||||
);
|
||||
|
||||
|
||||
|
||||
#vim:ft=perl
|
||||
121
t/Auth.t
121
t/Auth.t
|
|
@ -17,6 +17,9 @@ use FindBin;
|
|||
use strict;
|
||||
use lib "$FindBin::Bin/lib";
|
||||
use Test::More;
|
||||
use Test::Deep;
|
||||
use Exception::Class;
|
||||
|
||||
use WebGUI::Test; # Must use this before any other WebGUI modules
|
||||
use WebGUI::Auth;
|
||||
use WebGUI::Session;
|
||||
|
|
@ -33,7 +36,7 @@ my ($request, $oldRequest, $output);
|
|||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
plan tests => 4; # Increment this number for each test you create
|
||||
plan tests => 11; # Increment this number for each test you create
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Test createAccountSave and returnUrl together
|
||||
|
|
@ -65,9 +68,21 @@ WebGUI::Test->addToCleanup(sub {
|
|||
"SELECT userId FROM users WHERE username=?",
|
||||
[ $username ]
|
||||
);
|
||||
|
||||
|
||||
my $addressBookId = $session->db->quickScalar(
|
||||
"select addressBookId from addressBook where userId=?",
|
||||
[ $userId ]
|
||||
);
|
||||
|
||||
if($addressBookId) {
|
||||
$session->db->write(
|
||||
"delete from address where addressBookId=?",
|
||||
[$addressBookId]
|
||||
);
|
||||
}
|
||||
|
||||
my @tableList
|
||||
= qw{authentication users userProfileData groupings inbox userLoginLog};
|
||||
= qw{authentication users userProfileData groupings inbox userLoginLog addressBook};
|
||||
|
||||
for my $table ( @tableList ) {
|
||||
$session->db->write(
|
||||
|
|
@ -89,6 +104,8 @@ $session->scratch->delete('language'); ##Remove language override
|
|||
# Session Cleanup
|
||||
$session->{_request} = $oldRequest;
|
||||
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Test login and returnUrl together
|
||||
# Set up request
|
||||
|
|
@ -114,6 +131,104 @@ is $output, undef, 'login returns undef when showMessageOnLogin is false';
|
|||
|
||||
# Session Cleanup
|
||||
$session->{_request} = $oldRequest;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Test createAccountSave
|
||||
$username = $session->id->generate;
|
||||
push @cleanupUsernames, $username;
|
||||
|
||||
#Test updates to existing addresses
|
||||
tie my %profile_info, "Tie::IxHash", (
|
||||
firstName => "Andy",
|
||||
lastName => "Dufresne",
|
||||
homeAddress => "123 Shank Ave.",
|
||||
homeCity => "Shawshank",
|
||||
homeState => "PA",
|
||||
homeZip => "11223",
|
||||
homeCountry => "US",
|
||||
homePhone => "111-111-1111",
|
||||
email => 'andy@shawshank.com'
|
||||
);
|
||||
|
||||
$auth->createAccountSave( $username, { }, "PASSWORD", \%profile_info );
|
||||
|
||||
#Reset andy to the session users since stuff has changed
|
||||
my $andy = $session->user;
|
||||
|
||||
#Test that the address was saved to the profile
|
||||
cmp_bag(
|
||||
[ map { $andy->profileField($_) } keys %profile_info ],
|
||||
[ values %profile_info ],
|
||||
'Profile fields were saved'
|
||||
);
|
||||
|
||||
#Test that the addressBook was created
|
||||
my $bookId = $session->db->quickScalar(
|
||||
q{ select addressBookId from addressBook where userId=? },
|
||||
[$andy->getId]
|
||||
);
|
||||
|
||||
ok( ($bookId ne ""), "Address Book was created");
|
||||
|
||||
my $book = WebGUI::Shop::AddressBook->new($session,$bookId);
|
||||
|
||||
my @addresses = @{ $book->getAddresses() };
|
||||
|
||||
is(scalar(@addresses), 1 , "One address was created in the address book");
|
||||
|
||||
my $address = $addresses[0];
|
||||
|
||||
tie my %address_info, "Tie::IxHash", (
|
||||
firstName => $address->get("firstName"),
|
||||
lastName => $address->get("lastName"),
|
||||
homeAddress => $address->get("address1"),
|
||||
homeCity => $address->get("city"),
|
||||
homeState => $address->get("state"),
|
||||
homeZip => $address->get("code"),
|
||||
homeCountry => $address->get("country"),
|
||||
homePhone => $address->get("phoneNumber"),
|
||||
email => $address->get("email")
|
||||
);
|
||||
|
||||
#Test that the address was saved properly to shop
|
||||
cmp_bag(
|
||||
[ values %profile_info ],
|
||||
[ values %address_info ],
|
||||
'Shop address was has the right information'
|
||||
);
|
||||
|
||||
#Test that the address is returned as the profile address
|
||||
my $profileAddress = $book->getProfileAddress;
|
||||
is($profileAddress->getId, $address->getId, "Profile linked properly to address");
|
||||
|
||||
#Test that the address is the default address
|
||||
my $defaultAddress = $book->getDefaultAddress;
|
||||
is(
|
||||
$defaultAddress->getId,
|
||||
$address->getId,
|
||||
"Profile address properly set to default address when created"
|
||||
);
|
||||
|
||||
$username = $session->id->generate;
|
||||
push @cleanupUsernames, $username;
|
||||
|
||||
#Test updates to existing addresses
|
||||
%profile_info = (
|
||||
firstName => "Andy",
|
||||
lastName => "Dufresne",
|
||||
email => 'andy@shawshank.com'
|
||||
);
|
||||
|
||||
$auth->createAccountSave( $username, { }, "PASSWORD", \%profile_info );
|
||||
|
||||
#Test that the addressBook was not created
|
||||
my $bookCount = $session->db->quickScalar(
|
||||
q{ select count(addressBookId) from addressBook where userId=? },
|
||||
[$session->user->getId]
|
||||
);
|
||||
|
||||
is( $bookCount, 0, "Address Book was not created for user without address fields");
|
||||
|
||||
sub installPigLatin {
|
||||
use File::Copy;
|
||||
mkdir File::Spec->catdir(WebGUI::Test->lib, 'WebGUI', 'i18n', 'PigLatin');
|
||||
|
|
|
|||
194
t/Operation/User.t
Normal file
194
t/Operation/User.t
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
# vim:syntax=perl
|
||||
#-------------------------------------------------------------------
|
||||
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
|
||||
#-------------------------------------------------------------------
|
||||
# Please read the legal notices (docs/legal.txt) and the license
|
||||
# (docs/license.txt) that came with this distribution before using
|
||||
# this software.
|
||||
#------------------------------------------------------------------
|
||||
# http://www.plainblack.com info@plainblack.com
|
||||
#------------------------------------------------------------------
|
||||
|
||||
# This tests the operation of Authentication
|
||||
#
|
||||
#
|
||||
|
||||
use FindBin;
|
||||
use strict;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use Test::More;
|
||||
use Test::Deep;
|
||||
use Exception::Class;
|
||||
|
||||
use WebGUI::Test; # Must use this before any other WebGUI modules
|
||||
use WebGUI::Session;
|
||||
use WebGUI::User;
|
||||
use WebGUI::Operation::User;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Init
|
||||
my $session = WebGUI::Test->session;
|
||||
$session->user({ userId => 3 });
|
||||
|
||||
my $andy = WebGUI::User->new($session, "new");
|
||||
WebGUI::Test->addToCleanup($andy);
|
||||
$andy->username("andydufresne");
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
plan tests => 10; # Increment this number for each test you create
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
|
||||
#######################################################################
|
||||
#
|
||||
# www_editUserSave
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
tie my %profile_info, "Tie::IxHash", (
|
||||
firstName => "Andy",
|
||||
lastName => "Dufresne",
|
||||
homeAddress => "123 Shank Ave.",
|
||||
homeCity => "Shawshank",
|
||||
homeState => "PA",
|
||||
homeZip => "11223",
|
||||
homeCountry => "US",
|
||||
homePhone => "111-111-1111",
|
||||
email => 'andy@shawshank.com'
|
||||
);
|
||||
|
||||
$session->request->setup_body({
|
||||
uid => $andy->getId,
|
||||
username => $andy->username,
|
||||
webguiCsrfToken => $session->scratch->get('webguiCsrfToken'),
|
||||
%profile_info
|
||||
});
|
||||
$session->request->method('POST');
|
||||
|
||||
WebGUI::Operation::User::www_editUserSave($session);
|
||||
|
||||
$andy = WebGUI::User->new($session,$andy->getId);
|
||||
|
||||
#Test that the address was saved to the profile
|
||||
cmp_bag(
|
||||
[ map { $andy->profileField($_) } keys %profile_info ],
|
||||
[ values %profile_info ],
|
||||
'Profile fields were saved'
|
||||
);
|
||||
|
||||
#Test that the addressBook was created
|
||||
my $bookId = $session->db->quickScalar(
|
||||
q{ select addressBookId from addressBook where userId=? },
|
||||
[$andy->getId]
|
||||
);
|
||||
|
||||
ok( ($bookId ne ""), "Address Book was created");
|
||||
|
||||
my $book = WebGUI::Shop::AddressBook->new($session,$bookId);
|
||||
|
||||
my @addresses = @{ $book->getAddresses() };
|
||||
|
||||
is(scalar(@addresses), 1 , "One address was created in the address book");
|
||||
|
||||
my $address = $addresses[0];
|
||||
|
||||
tie my %address_info, "Tie::IxHash", (
|
||||
firstName => $address->get("firstName"),
|
||||
lastName => $address->get("lastName"),
|
||||
homeAddress => $address->get("address1"),
|
||||
homeCity => $address->get("city"),
|
||||
homeState => $address->get("state"),
|
||||
homeZip => $address->get("code"),
|
||||
homeCountry => $address->get("country"),
|
||||
homePhone => $address->get("phoneNumber"),
|
||||
email => $address->get("email")
|
||||
);
|
||||
|
||||
#Test that the address was saved properly to shop
|
||||
cmp_bag(
|
||||
[ values %profile_info ],
|
||||
[ values %address_info ],
|
||||
'Shop address was has the right information'
|
||||
);
|
||||
|
||||
#Test that the address is returned as the profile address
|
||||
my $profileAddress = $book->getProfileAddress;
|
||||
is($profileAddress->getId, $address->getId, "Profile linked properly to address");
|
||||
|
||||
#Test that the address is the default address
|
||||
my $defaultAddress = $book->getDefaultAddress;
|
||||
is(
|
||||
$defaultAddress->getId,
|
||||
$address->getId,
|
||||
"Profile address properly set to default address when created"
|
||||
);
|
||||
|
||||
|
||||
#Test updates to existing addresses
|
||||
%profile_info = (
|
||||
firstName => "Andy",
|
||||
lastName => "Dufresne",
|
||||
homeAddress => "123 Seaside Ave.",
|
||||
homeCity => "Zihuatanejo",
|
||||
homeState => "Guerrero",
|
||||
homeZip => "40880",
|
||||
homeCountry => "MX",
|
||||
homePhone => "222-222-2222",
|
||||
email => 'andy@freeman.com'
|
||||
);
|
||||
|
||||
$session->request->setup_body({
|
||||
uid => $andy->getId,
|
||||
username => $andy->username,
|
||||
webguiCsrfToken => $session->scratch->get('webguiCsrfToken'),
|
||||
%profile_info
|
||||
});
|
||||
$session->request->method('POST');
|
||||
WebGUI::Operation::User::www_editUserSave($session);
|
||||
|
||||
$andy = WebGUI::User->new($session,$andy->getId);
|
||||
|
||||
#Test that the address was saved to the profile
|
||||
cmp_bag (
|
||||
[ map { $andy->profileField($_) } keys %profile_info ],
|
||||
[ values %profile_info ],
|
||||
'Profile fields were updated'
|
||||
);
|
||||
|
||||
#Test that there is still only one address book and one address
|
||||
my @bookIds = $session->db->quickArray(
|
||||
q{ select addressBookId from addressBook where userId=? },
|
||||
[$andy->getId]
|
||||
);
|
||||
|
||||
is( scalar(@bookIds), 1, "Only one address book exists after update" );
|
||||
|
||||
$bookId = $bookIds[0];
|
||||
$book = WebGUI::Shop::AddressBook->new($session,$bookId);
|
||||
@addresses = @{ $book->getAddresses() };
|
||||
|
||||
is( scalar(@addresses), 1 , "Only one address exists after update");
|
||||
|
||||
my $address = $addresses[0];
|
||||
|
||||
%address_info = (
|
||||
firstName => $address->get("firstName"),
|
||||
lastName => $address->get("lastName"),
|
||||
homeAddress => $address->get("address1"),
|
||||
homeCity => $address->get("city"),
|
||||
homeState => $address->get("state"),
|
||||
homeZip => $address->get("code"),
|
||||
homeCountry => $address->get("country"),
|
||||
homePhone => $address->get("phoneNumber"),
|
||||
email => $address->get("email")
|
||||
);
|
||||
|
||||
#Test that the address was saved properly to shop
|
||||
cmp_bag(
|
||||
[ values %profile_info ],
|
||||
[ values %address_info ],
|
||||
'Shop address was has the right information'
|
||||
);
|
||||
|
|
@ -141,6 +141,7 @@ cmp_deeply(
|
|||
organization => undef,
|
||||
addressId => ignore(), #checked elsewhere
|
||||
addressBookId => $book->getId,
|
||||
isProfile => 0,
|
||||
},
|
||||
'get the whole thing and check a new, blank object'
|
||||
);
|
||||
|
|
|
|||
|
|
@ -23,15 +23,21 @@ use Exception::Class;
|
|||
use WebGUI::Test; # Must use this before any other WebGUI modules
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Text;
|
||||
use JSON;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Init
|
||||
my $session = WebGUI::Test->session;
|
||||
#Create a temporary admin user
|
||||
my $tempAdmin = WebGUI::User->create($session);
|
||||
$tempAdmin->addToGroups(['3']);
|
||||
WebGUI::Test->addToCleanup($tempAdmin);
|
||||
$session->user({ userId => $tempAdmin->getId} );
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
plan tests => 26;
|
||||
plan tests => 42;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# put your tests here
|
||||
|
|
@ -114,7 +120,7 @@ cmp_deeply(
|
|||
'... correct error message',
|
||||
);
|
||||
|
||||
$session->user({userId => 3});
|
||||
$session->user({userId => $tempAdmin->getId});
|
||||
$book = WebGUI::Shop::AddressBook->create($session);
|
||||
isa_ok($book, 'WebGUI::Shop::AddressBook', 'create returns the right kind of object');
|
||||
|
||||
|
|
@ -124,9 +130,9 @@ is($session->getId, $book->session->getId, 'session method returns OUR session o
|
|||
|
||||
ok($session->id->valid($book->getId), 'create makes a valid GUID style addressBookId');
|
||||
|
||||
is($book->get('userId'), 3, 'create uses $session->user to get the userid for this book');
|
||||
is($book->get('userId'), $tempAdmin->getId, 'create uses $session->user to get the userid for this book');
|
||||
|
||||
my $bookCount = $session->db->quickScalar('select count(*) from addressBook');
|
||||
my $bookCount = $session->db->quickScalar('select count(*) from addressBook where addressBookId=?',[$book->getId]);
|
||||
is($bookCount, 1, 'only 1 address book was created');
|
||||
|
||||
my $alreadyHaveBook = WebGUI::Shop::AddressBook->create($session);
|
||||
|
|
@ -191,25 +197,188 @@ cmp_deeply(
|
|||
'update updates the db, too'
|
||||
);
|
||||
|
||||
#######################################################################
|
||||
#
|
||||
# getProfileAddress
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
eval { $book->getProfileAddress };
|
||||
|
||||
$e = Exception::Class->caught();
|
||||
isa_ok($e, 'WebGUI::Error::ObjectNotFound', 'getProfileAddress takes exception to a profile address not being set');
|
||||
cmp_deeply(
|
||||
$e,
|
||||
methods(
|
||||
error => 'No profile address.',
|
||||
),
|
||||
'... correct error message',
|
||||
);
|
||||
|
||||
$address1->update({ isProfile => 1 });
|
||||
|
||||
my $profile_address = eval{ $book->getProfileAddress() };
|
||||
|
||||
is($profile_address->getId,$address1->getId,"getProfileAddress returns addresses tied to profiles");
|
||||
|
||||
#######################################################################
|
||||
#
|
||||
# www_editAddressSave
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
#Clear the book address cache
|
||||
$book->uncache;
|
||||
|
||||
my $address_info = {
|
||||
label => 'Profile Label',
|
||||
addressId => $address1->getId,
|
||||
firstName => 'Andy',
|
||||
lastName => 'Dufresne',
|
||||
address1 => '123 Shank Ave',
|
||||
address2 => 'Cell Block E',
|
||||
address3 => 'Cell 12',
|
||||
city => 'Shawshank',
|
||||
state => 'PA',
|
||||
code => '11223',
|
||||
country => 'US',
|
||||
phoneNumber => '111-111-1111',
|
||||
email => 'andy@shawshank.com',
|
||||
organization => 'Shawshank'
|
||||
};
|
||||
|
||||
$session->request->setup_body({
|
||||
%$address_info,
|
||||
callback => q|{'url':''}|
|
||||
});
|
||||
|
||||
$book->www_editAddressSave;
|
||||
|
||||
$address1 = $book->getAddress($address1->getId);
|
||||
|
||||
cmp_bag(
|
||||
[ map { $address1->get($_) } keys %$address_info ],
|
||||
[ values %$address_info ],
|
||||
'Address fields were saved'
|
||||
);
|
||||
|
||||
my $u = WebGUI::User->new($session,$book->get("userId"));
|
||||
|
||||
cmp_bag(
|
||||
[ map { $u->profileField($_) } keys %{ $book->getProfileAddressMappings } ],
|
||||
[ map { $address1->get($_) } values %{ $book->getProfileAddressMappings } ],
|
||||
'Profile address was updated and matches address fields'
|
||||
);
|
||||
|
||||
#Test that updates to non profile address does not update the profile
|
||||
$book->uncache;
|
||||
|
||||
$address_info = {
|
||||
label => 'Non Profile Label',
|
||||
addressId => $address2->getId,
|
||||
firstName => 'Ellis',
|
||||
lastName => 'Redding',
|
||||
address1 => '123 Shank Ave',
|
||||
address2 => 'Cell Block E',
|
||||
address3 => 'Cell 15',
|
||||
city => 'Shawshank',
|
||||
state => 'PA',
|
||||
code => '11223',
|
||||
country => 'US',
|
||||
phoneNumber => '111-111-1111',
|
||||
email => 'red@shawshank.com',
|
||||
organization => 'Shawshank'
|
||||
};
|
||||
|
||||
|
||||
$session->request->setup_body({
|
||||
%$address_info,
|
||||
callback => q|{'url':''}|
|
||||
});
|
||||
|
||||
$book->www_editAddressSave;
|
||||
|
||||
$address1 = $book->getAddress($address1->getId);
|
||||
$address2 = $book->getAddress($address2->getId);
|
||||
|
||||
cmp_bag(
|
||||
[ map { $address2->get($_) } keys %$address_info ],
|
||||
[ values %$address_info ],
|
||||
'Non Profile Address fields were saved'
|
||||
);
|
||||
|
||||
cmp_bag(
|
||||
[ map { $u->profileField($_) } keys %{ $book->getProfileAddressMappings } ],
|
||||
[ map { $address1->get($_) } values %{ $book->getProfileAddressMappings } ],
|
||||
'Profile address was not updated when non profile fields were saved'
|
||||
);
|
||||
|
||||
#######################################################################
|
||||
#
|
||||
# www_deleteAddress
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
#clear the cache
|
||||
$book->uncache;
|
||||
|
||||
$session->request->setup_body({
|
||||
'addressId' => $address2->getId,
|
||||
'callback' => q|{'url':''}|
|
||||
});
|
||||
$book->www_deleteAddress;
|
||||
|
||||
@addresses = @{ $book->getAddresses() };
|
||||
|
||||
cmp_bag(
|
||||
[ map { $_->getId } @addresses ],
|
||||
[$address1->getId],
|
||||
'Address was deleted properly'
|
||||
);
|
||||
|
||||
|
||||
#clear the cache
|
||||
$book->uncache;
|
||||
|
||||
$session->request->setup_body({
|
||||
'addressId' => $address1->getId,
|
||||
'callback' => q|{'url':''}|
|
||||
});
|
||||
$book->www_deleteAddress;
|
||||
|
||||
@addresses = @{ $book->getAddresses() };
|
||||
|
||||
cmp_bag(
|
||||
[ map { $_->getId } @addresses ],
|
||||
[$address1->getId],
|
||||
'Profile Address was not deleted'
|
||||
);
|
||||
|
||||
|
||||
#######################################################################
|
||||
#
|
||||
# delete
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
#clear the cache
|
||||
$book->uncache;
|
||||
|
||||
my $addressBookId = $alreadyHaveBook->getId;
|
||||
my $firstCount = $session->db->quickScalar('select count(*) from addressBook where addressBookId=?',[$addressBookId]);
|
||||
$alreadyHaveBook->delete();
|
||||
$bookCount = $session->db->quickScalar('select count(*) from addressBook');
|
||||
my $addrCount = $session->db->quickScalar('select count(*) from address');
|
||||
my $afterCount = $session->db->quickScalar('select count(*) from addressBook where addressBookId=?',[$addressBookId]);
|
||||
my $addrCount = $session->db->quickScalar('select count(*) from address where addressBookId=?',[$addressBookId]);
|
||||
|
||||
is($bookCount, 1, 'delete: one book deleted');
|
||||
ok(($firstCount == 1 && $afterCount == 0), 'delete: one book deleted');
|
||||
|
||||
$addressBookId = $bookClone->getId;
|
||||
$bookClone->delete();
|
||||
$bookCount = $session->db->quickScalar('select count(*) from addressBook');
|
||||
my $addrCount = $session->db->quickScalar('select count(*) from address');
|
||||
$bookCount = $session->db->quickScalar('select count(*) from addressBook where addressBookId=?',[$addressBookId]);
|
||||
my $addrCount = $session->db->quickScalar('select count(*) from address where addressBookId=?',[$addressBookId]);
|
||||
|
||||
is($bookCount, 0, '... book deleted');
|
||||
is($addrCount, 0, '... also deletes addresses in the book');
|
||||
undef $book;
|
||||
|
||||
#######################################################################
|
||||
#
|
||||
|
|
@ -217,7 +386,6 @@ undef $book;
|
|||
#
|
||||
#######################################################################
|
||||
|
||||
|
||||
my $otherSession = WebGUI::Test->newSession;
|
||||
my $mergeUser = WebGUI::User->create($otherSession);
|
||||
WebGUI::Test->addToCleanup($mergeUser);
|
||||
|
|
@ -235,3 +403,225 @@ cmp_bag(
|
|||
[ $goodAddress->getId, ],
|
||||
'newByUserId works'
|
||||
);
|
||||
|
||||
#######################################################################
|
||||
#
|
||||
# www_ajaxSearch
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
#Create some data to search for
|
||||
my $andySession = WebGUI::Test->newSession;
|
||||
my $andy = WebGUI::User->create($andySession);
|
||||
WebGUI::Test->addToCleanup($andy);
|
||||
$andySession->user({ userId => $andy->getId });
|
||||
my $andyBook = WebGUI::Shop::AddressBook->create($andySession);
|
||||
WebGUI::Test->addToCleanup($andyBook);
|
||||
|
||||
my $andyAddr1 = $andyBook->addAddress({
|
||||
label => 'Andy1',
|
||||
firstName => 'Andy',
|
||||
lastName => 'Dufresne',
|
||||
address1 => '123 Shank Ave',
|
||||
address2 => 'Cell Block E',
|
||||
address3 => 'Cell 12',
|
||||
city => 'Shawshank',
|
||||
state => 'PA',
|
||||
code => '11223',
|
||||
country => 'US',
|
||||
phoneNumber => '111-111-1111',
|
||||
email => 'andy@shawshank.com',
|
||||
organization => 'Shawshank'
|
||||
});
|
||||
|
||||
my $andyAddr2 = $andyBook->addAddress({
|
||||
label => 'Andy2',
|
||||
firstName => 'Andy',
|
||||
lastName => 'Dufresne',
|
||||
address1 => '123 Seaside Ave',
|
||||
address2 => '',
|
||||
address3 => '',
|
||||
city => 'Zihuatanejo',
|
||||
state => '',
|
||||
code => '40880',
|
||||
country => 'MX',
|
||||
phoneNumber => '222-222-2222',
|
||||
email => 'andy@freeman.com',
|
||||
organization => 'Unaffiliated'
|
||||
});
|
||||
|
||||
|
||||
my $redSession = WebGUI::Test->newSession;
|
||||
my $red = WebGUI::User->create($redSession);
|
||||
WebGUI::Test->addToCleanup($red);
|
||||
$redSession->user({userId => $red->getId});
|
||||
my $redBook = WebGUI::Shop::AddressBook->create($redSession);
|
||||
WebGUI::Test->addToCleanup($redBook);
|
||||
|
||||
my $redAddr = $redBook->addAddress({
|
||||
label => 'Red1',
|
||||
firstName => 'Ellis',
|
||||
lastName => 'Redding',
|
||||
address1 => '123 Shank Ave',
|
||||
address2 => 'Cell Block E',
|
||||
address3 => 'Cell 15',
|
||||
city => 'Shawshank',
|
||||
state => 'PA',
|
||||
code => '11223',
|
||||
country => 'US',
|
||||
phoneNumber => '111-111-1111',
|
||||
email => 'red@shawshank.com',
|
||||
organization => 'Shawshank'
|
||||
});
|
||||
|
||||
|
||||
my $brooksSession = WebGUI::Test->newSession;
|
||||
my $brooks = WebGUI::User->create($brooksSession);
|
||||
WebGUI::Test->addToCleanup($brooks);
|
||||
$brooksSession->user({userId => $brooks->getId});
|
||||
my $brooksBook = WebGUI::Shop::AddressBook->create($brooksSession);
|
||||
WebGUI::Test->addToCleanup($brooksBook);
|
||||
|
||||
my $brooksAddr = $brooksBook->addAddress({
|
||||
label => 'Brooks1',
|
||||
firstName => 'Brooks',
|
||||
lastName => 'Hatlen',
|
||||
address1 => '123 Shank Ave',
|
||||
address2 => 'Cell Block E',
|
||||
address3 => 'Cell 22',
|
||||
city => 'Shawshank',
|
||||
state => 'PA',
|
||||
code => '11223',
|
||||
country => 'US',
|
||||
phoneNumber => '111-111-1111',
|
||||
email => 'brooks@shawshank.com',
|
||||
organization => 'Shawshank'
|
||||
});
|
||||
|
||||
#Test search as admin
|
||||
$session->request->setup_body({
|
||||
'name' => 'Andy Du'
|
||||
});
|
||||
|
||||
my $results = JSON->new->decode($book->www_ajaxSearch);
|
||||
|
||||
cmp_bag(
|
||||
$results,
|
||||
[
|
||||
{ %{$andyAddr1->get}, username => $andy->username },
|
||||
{ %{$andyAddr2->get}, username => $andy->username },
|
||||
],
|
||||
'Ajax Address Search matches name correctly for admins'
|
||||
);
|
||||
|
||||
#Test search for multiple fields
|
||||
$session->request->setup_body({
|
||||
'name' => 'Andy Du',
|
||||
'organization' => 'Shaw',
|
||||
'address1' => '123',
|
||||
'address2' => 'Cell',
|
||||
'address3' => 'Cell',
|
||||
'city' => 'Shaw',
|
||||
'state' => 'P',
|
||||
'zipcode' => '11',
|
||||
'country' => 'U',
|
||||
'email' => 'andy',
|
||||
'phone' => '111',
|
||||
});
|
||||
|
||||
$results = JSON->new->decode($book->www_ajaxSearch);
|
||||
|
||||
cmp_bag(
|
||||
$results,
|
||||
[{ %{$andyAddr1->get}, username => $andy->username }],
|
||||
'Ajax Address Search matches multiple fields correctly'
|
||||
);
|
||||
|
||||
#Test limiting
|
||||
$session->request->setup_body({
|
||||
'name' => 'Andy Du',
|
||||
'organization' => 'Shaw',
|
||||
'address1' => '123',
|
||||
'address2' => 'Cell',
|
||||
'address3' => 'Cell',
|
||||
'city' => 'Shaw',
|
||||
'state' => 'Q', #This should cause no results to come back
|
||||
'zipcode' => '11',
|
||||
'country' => 'U',
|
||||
'email' => 'andy',
|
||||
'phone' => '111',
|
||||
});
|
||||
|
||||
$results = JSON->new->decode($book->www_ajaxSearch);
|
||||
|
||||
cmp_bag(
|
||||
$results,
|
||||
[],
|
||||
'Ajax Address Search limits results correctly'
|
||||
);
|
||||
|
||||
#Test searching across users
|
||||
#Test as admin
|
||||
$session->request->setup_body({
|
||||
'organization' => 'Shawshank'
|
||||
});
|
||||
|
||||
$results = JSON->new->decode($book->www_ajaxSearch);
|
||||
|
||||
cmp_bag(
|
||||
$results,
|
||||
[
|
||||
{ %{$andyAddr1->get}, username => $andy->username },
|
||||
{ %{$redAddr->get}, username => $red->username },
|
||||
{ %{$brooksAddr->get}, username => $brooks->username },
|
||||
],
|
||||
'Ajax Address Search returns cross user results for admins'
|
||||
);
|
||||
|
||||
#Test as shop admin
|
||||
$andy->addToGroups([ $andySession->setting->get('groupIdAdminCommerce') ]);
|
||||
$andySession->request->setup_body({
|
||||
'organization' => 'Shawshank'
|
||||
});
|
||||
$results = JSON->new->decode($andyBook->www_ajaxSearch);
|
||||
|
||||
cmp_bag(
|
||||
$results,
|
||||
[
|
||||
{ %{$andyAddr1->get}, username => $andy->username },
|
||||
{ %{$redAddr->get}, username => $red->username },
|
||||
{ %{$brooksAddr->get}, username => $brooks->username },
|
||||
],
|
||||
'Ajax Address Search returns cross user results for shop admins'
|
||||
);
|
||||
|
||||
#Test search as shop cashier
|
||||
$red->addToGroups([ $redSession->setting->get('groupIdCashier') ]);
|
||||
$redSession->request->setup_body({
|
||||
'organization' => 'Shawshank'
|
||||
});
|
||||
$results = JSON->new->decode($redBook->www_ajaxSearch);
|
||||
|
||||
cmp_bag(
|
||||
$results,
|
||||
[
|
||||
{ %{$andyAddr1->get}, username => $andy->username },
|
||||
{ %{$redAddr->get}, username => $red->username },
|
||||
{ %{$brooksAddr->get}, username => $brooks->username },
|
||||
],
|
||||
'Ajax Address Search returns cross user results for shop cashiers'
|
||||
);
|
||||
|
||||
#Test search as non privileged
|
||||
$brooksSession->request->setup_body({
|
||||
'organization' => 'Shawshank'
|
||||
});
|
||||
$results = JSON->new->decode($brooksBook->www_ajaxSearch);
|
||||
|
||||
cmp_bag(
|
||||
$results,
|
||||
[{ %{$brooksAddr->get}, username => $brooks->username }],
|
||||
'Ajax Address Search returns only current user results for non privileged users'
|
||||
);
|
||||
|
||||
undef $book;
|
||||
|
|
|
|||
|
|
@ -144,6 +144,7 @@ my $defaultPayDrivers = {
|
|||
'WebGUI::Shop::PayDriver::Ogone' => 'Ogone',
|
||||
'WebGUI::Shop::PayDriver::PayPal::PayPalStd' => 'PayPal',
|
||||
'WebGUI::Shop::PayDriver::PayPal::ExpressCheckout' => 'PayPal Express Checkout',
|
||||
'WebGUI::Shop::PayDriver::CreditCard::AuthorizeNet' => 'Credit Card (Authorize.net)',
|
||||
};
|
||||
|
||||
cmp_deeply( $drivers, $defaultPayDrivers, 'getDrivers returns the default PayDrivers');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue