Merge commit 'v7.10.22' into WebGUI8

This commit is contained in:
Colin Kuskie 2011-10-31 20:13:01 -07:00
commit 431cd280a4
92 changed files with 3543 additions and 313 deletions

View file

@ -10,28 +10,24 @@
#------------------------------------------------------------------
# Test the User operation
#
#
use FindBin;
use strict;
use lib "$FindBin::Bin/lib";
use Test::More;
use WebGUI::Test; # Must use this before any other WebGUI modules
use WebGUI::Session;
use WebGUI::Test::Mechanize;
use WebGUI::User;
use WebGUI::Operation::User;
use Test::More;
use Test::Deep;
#----------------------------------------------------------------------------
# Init
my $session = WebGUI::Test->session;
$session->user({ userId => 3 });
#----------------------------------------------------------------------------
# Tests
plan tests => 17; # Increment this number for each test you create
#----------------------------------------------------------------------------
# Create a new user
my $mech = WebGUI::Test::Mechanize->new( config => WebGUI::Test->file );
@ -40,7 +36,7 @@ $mech->session->user({userId => 3});
$mech->get_ok( '?op=editUser;uid=new' );
my %fields = (
username => 'AndyDufresne',
username => 'AndrewDufresne',
email => 'andy@shawshank.doj.gov',
alias => 'Randall Stevens',
status => 'Active',
@ -55,12 +51,12 @@ $mech->submit_form_ok({
"Add a new user",
);
ok( my $user = WebGUI::User->newByUsername( $session, 'AndyDufresne' ), "user exists" );
ok( my $user = WebGUI::User->newByUsername( $session, 'AndrewDufresne' ), "user exists" );
WebGUI::Test->addToCleanup( $user );
is( $user->get('email'), $fields{email} );
is( $user->get('alias'), $fields{alias} );
is( $user->status, $fields{status} );
ok( $user->isInGroup( 12 ) );
is( $user->get('email'), $fields{email}, 'checking email' );
is( $user->get('alias'), $fields{alias}, '... alias' );
is( $user->status, $fields{status}, '... status' );
ok( $user->isInGroup( 12 ), '... added to group 12' );
my $auth = WebGUI::Auth::WebGUI->new( $session, $user );
is( $auth->get('identifier'), $auth->hashPassword('zihuatanejo'), "password was set correctly" );
@ -83,11 +79,166 @@ $mech->submit_form_ok({
);
ok( my $user = WebGUI::User->newByUsername( $mech->session, 'EllisRedding' ), "user exists" );
is( $user->get('email'), $fields{email} );
is( $user->get('alias'), $fields{alias} );
is( $user->status, $fields{status} );
ok( not $user->isInGroup( 12 ) );
is( $user->get('email'), $fields{email}, '... checking email' );
is( $user->get('alias'), $fields{alias}, '... checking alias' );
is( $user->status, $fields{status}, '... checking status' );
ok( not ($user->isInGroup( 12 )), '.. checking group deletion' );
$auth = WebGUI::Auth::WebGUI->new( $session, $user );
is( $auth->get('identifier'), $auth->hashPassword('rehabilitated'), "password was set correctly" );
#vim:ft=perl
#######################################################################
#
# Address testing in the profile
#
#######################################################################
my $andy = WebGUI::User->new($session, "new");
WebGUI::Test->addToCleanup($andy);
$andy->username("andydufresne");
$mech->get_ok( '?op=editUser;uid=' . $andy->getId );
my %profile_info = (
firstName => "Andy",
lastName => "Dufresne",
homeAddress => "123 Shank Ave.",
homeCity => "Shawshank",
homeState => "PA",
homeZip => "11223",
homeCountry => "US",
homePhone => "111-111-1111",
email => 'andy@shawshank.com'
);
$mech->submit_form_ok({
fields => {
%profile_info,
},
},
"Edit an existing user for address testing",
);
$andy = WebGUI::User->new($session,$andy->getId);
#Test that the address was saved to the profile
cmp_bag(
[ map { $andy->get($_) } 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];
ok ($address->get('isProfile'), '... and it is a profile address');
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 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'
);
$mech->get_ok( '?op=editUser;uid=' . $andy->getId );
$mech->submit_form_ok({
fields => {
%profile_info,
},
},
"Update existing address info",
);
$andy = WebGUI::User->new($session,$andy->getId);
#Test that the address was saved to the profile
cmp_bag (
[ map { $andy->get($_) } 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 has the right information'
);
done_testing;