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

218
t/Account/Profile.t Normal file
View 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

View file

@ -866,7 +866,7 @@ subtest 'canAdd tolerates being called as an object method', sub {
# Make a test user who's just in Turn Admin On
my $u = WebGUI::User->create($session);
WebGUI::Test->addToCleanup($u);
WebGUI::Test->addToCleanup($u, $snip);
$u->addToGroups(['12']);
$session->user({ user => $u });

View file

@ -0,0 +1,46 @@
# 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
#------------------------------------------------------------------
=head1 BUG DESCRIPTION
When Thread assets are copied, a new subscription group gets created for them,
but not by calling $thread->createSubscriptionGroup. Instead, a "blank" group
is created, and then the users from the old group are added to it -- which by
default has Admins subscribed in it. So, every time we copy a thread, our
admins start getting spammed with subscription updates.
=cut
use warnings;
use strict;
use Test::More tests => 2;
use Test::Exception;
use FindBin;
use lib "$FindBin::Bin/../../../lib";
use WebGUI::Test;
use WebGUI::Asset;
my $session = WebGUI::Test->session;
my $thread = WebGUI::Asset->getImportNode($session)->addChild(
{
className => 'WebGUI::Asset::Post::Thread',
}
);
WebGUI::Test->addToCleanup($thread);
$thread->createSubscriptionGroup();
my $admin = WebGUI::User->new($session, 3);
ok !$admin->isInGroup($thread->get('subscriptionGroupId'));
$thread = $thread->duplicate();
WebGUI::Test->addToCleanup($thread);
ok !$admin->isInGroup($thread->get('subscriptionGroupId'));

View file

@ -172,6 +172,7 @@ cmp_bag(
extension => 'tar',
}),
],
'extensions in the attachment_loop are correct'
) or diag Dumper($templateVars->{attachment_loop});
TODO: {

View file

@ -0,0 +1,166 @@
#-------------------------------------------------------------------
# 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
#-------------------------------------------------------------------
use FindBin;
use strict;
use lib "$FindBin::Bin/../../../lib";
##The goal of this test is to test www_editThingDataSaveViaAjax, particularly those things not tested in Thingy.t
use WebGUI::Test;
use WebGUI::Session;
use Test::More tests => 4; # increment this value for each test you create
use Test::Deep;
use JSON;
use WebGUI::Asset::Wobject::Thingy;
use Data::Dumper;
my $session = WebGUI::Test->session;
# Do our work in the import node
my $node = WebGUI::Asset->getImportNode($session);
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"Thingy Test"});
WebGUI::Test->addToCleanup($versionTag);
my $thingy = $node->addChild({className=>'WebGUI::Asset::Wobject::Thingy'});
# Test adding a new Thing
my $i18n = WebGUI::International->new($session, "Asset_Thingy");
my $groupIdEdit = $thingy->get("groupIdEdit");
my %thingProperties = (
thingId => "new",
label => $i18n->get('assetName'),
editScreenTitle => $i18n->get('edit screen title label'),
editInstructions => '',
groupIdAdd => $groupIdEdit,
groupIdEdit => $groupIdEdit,
saveButtonLabel => $i18n->get('default save button label'),
afterSave => 'searchThisThing',
editTemplateId => "ThingyTmpl000000000003",
groupIdView => $groupIdEdit,
viewTemplateId => "ThingyTmpl000000000002",
defaultView => 'searchThing',
searchScreenTitle => $i18n->get('search screen title label'),
searchDescription => '',
groupIdSearch => $groupIdEdit,
groupIdExport => $groupIdEdit,
groupIdImport => $groupIdEdit,
searchTemplateId => "ThingyTmpl000000000004",
thingsPerPage => 25,
);
my $thingId = $thingy->addThing(\%thingProperties,0);
# Test adding a field
my %fieldProperties = (
thingId => $thingId,
fieldId => "new",
label => "Optional",
dateCreated => time(),
fieldType => "text",
status => "editable",
display => 1,
);
my $field1Id = $thingy->addField(\%fieldProperties, 0);
$fieldProperties{status} = 'required';
$fieldProperties{label} = 'Required';
my $field2Id = $thingy->addField(\%fieldProperties, 0);
#################################################################
#
# www_editThingDataSaveViaAjax
#
#################################################################
$session->request->setup_body({
thingId => $thingId,
thingDataId => 'new',
"field_".$field1Id => 'test value',
"field_".$field2Id => 'required', # required
});
$session->user({userId => '3'});
$session->http->setStatus(200);
my $json = $thingy->www_editThingDataSaveViaAjax();
is $json, '{}', 'www_editThingDataSaveViaAjax: Empty JSON hash';
is $session->http->getStatus, 200, '... http status=200';
$session->request->setup_body({
thingId => $thingId,
thingDataId => 'new',
"field_".$field1Id => 'test value',
"field_".$field2Id => '',
});
my $json = from_json( $thingy->www_editThingDataSaveViaAjax());
cmp_bag ($json,
[
superhashof ({
field_name => "field_".$field2Id,
}),
],
'checking for field_name in error json'
) or diag Dumper($json);
$fieldProperties{status} = 'required';
$fieldProperties{label} = 'Required2';
my $field3Id = $thingy->addField(\%fieldProperties, 0);
$fieldProperties{status} = 'required';
$fieldProperties{label} = 'Required3';
my $field4Id = $thingy->addField(\%fieldProperties, 0);
$session->request->setup_body({
thingId => $thingId,
thingDataId => 'new',
"field_".$field1Id => 'test value',
"field_".$field2Id => '',
"field_".$field3Id => '',
"field_".$field4Id => '',
});
$json = from_json( $thingy->www_editThingDataSaveViaAjax());
cmp_bag ($json,
[
superhashof ({
field_name => "field_".$field2Id,
}),
superhashof ({
field_name => "field_".$field3Id,
}),
superhashof ({
field_name => "field_".$field4Id,
}),
],
'checking for field_name in error json (3 required fields)'
) or diag Dumper($json);

121
t/Auth.t
View file

@ -15,6 +15,9 @@
use strict;
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;
@ -30,7 +33,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
@ -59,9 +62,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(
@ -80,6 +95,8 @@ is(
is $createAccountSession->user->profileField('language'), $language, 'languageOverride is taken in to account in createAccountSave';
$createAccountSession->scratch->delete('language'); ##Remove language override
#----------------------------------------------------------------------------
# Test login and returnUrl together
# Set up request
@ -102,6 +119,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');

View file

@ -63,7 +63,7 @@ my @filterSets = (
},
{
inputText => q!<p>Paragraph</p>^H();!,
output => q!Paragraph &#94;H();!,
output => q|Paragraph &#94;H();|,
type => 'all',
comment => 'all filters macros and HTML',
},
@ -81,12 +81,12 @@ my @filterSets = (
},
{
inputText => q!&nbsp;!,
output => q!&#x26;nbsp;!,
output => q|&#x26;nbsp;|,
type => 'xml',
comment => 'xml, &nbsp;',
},
{
inputText => q!> < "!,
inputText => q|> < "|,
output => q!&#x3E; &#x3C; &#x22;!,
type => 'xml',
comment => 'xml, other characters',
@ -127,7 +127,7 @@ my @htmlTextSets = (
my $numTests = scalar @filterSets
+ scalar @macroParamSets
+ scalar @htmlTextSets
+ 3
+ 6
;
plan tests => $numTests;
@ -147,6 +147,31 @@ foreach my $testSet (@htmlTextSets) {
is($text, $testSet->{output}, $testSet->{comment});
}
my @replacement_ids = ();
push @replacement_ids, $session->db->setRow("replacements","replacementId",{
replacementId=>'new',
searchFor=>':)',
replaceWith=>'smiley.gif',
});
push @replacement_ids, $session->db->setRow("replacements","replacementId",{
replacementId=>'new',
searchFor=>'[]',
replaceWith=>'square brackets',
});
push @replacement_ids, $session->db->setRow("replacements","replacementId",{
replacementId=>'new',
searchFor=>'[IMAG]',
replaceWith=>'IMAGE',
});
WebGUI::Test->addToCleanup(sub {
foreach my $id (@replacement_ids) {
$session->db->write('delete from replacements where replacementId=?',[$id]);
}
});
is(WebGUI::HTML::processReplacements($session, 'grass'), 'grass', 'processReplacements: grass is not replaced');
is(WebGUI::HTML::processReplacements($session, 'shitake'), 'shitake', '... shitake is not replaced');
is(WebGUI::HTML::processReplacements($session, 'This is shit.'), 'This is crap.', '... shit is replaced');
is(WebGUI::HTML::processReplacements($session, ':)'), 'smiley.gif', '... unbalanced paren is replaced');
is(WebGUI::HTML::processReplacements($session, '[]'), 'square brackets', '... square brackets are replaced');
is(WebGUI::HTML::processReplacements($session, '[IMAG]'), 'IMAGE', '... image sequence processed');

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;

View file

@ -26,11 +26,6 @@ use WebGUI::Shop::AddressBook;
# Init
my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
plan tests => 20;
#----------------------------------------------------------------------------
# put your tests here
@ -128,6 +123,7 @@ cmp_deeply(
addressId => ignore(), #checked elsewhere
addressBookId => $book->getId,
addressBook => $book,
isProfile => 0,
},
'get the whole thing and check a new, blank object'
);
@ -192,3 +188,5 @@ cmp_deeply(
$address->delete;
my $check = $session->db->quickScalar('select count(*) from address where addressId=?',[$address->getId]);
is( $check, 0, 'delete worked');
done_testing;

View file

@ -22,15 +22,16 @@ use WebGUI::Test; # Must use this before any other WebGUI modules
use WebGUI::Session;
use WebGUI::Text;
use WebGUI::Shop::AddressBook;
use JSON;
#----------------------------------------------------------------------------
# Init
my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
plan tests => 23;
#Create a temporary admin user
my $tempAdmin = WebGUI::User->create($session);
$tempAdmin->addToGroups(['3']);
WebGUI::Test->addToCleanup($tempAdmin);
$session->user({ userId => $tempAdmin->getId} );
#----------------------------------------------------------------------------
# put your tests here
@ -84,7 +85,7 @@ cmp_deeply(
'... correct error message',
);
$session->user({userId => 3});
$session->user({userId => $tempAdmin->getId});
$book = WebGUI::Shop::AddressBook->new($session);
isa_ok($book, 'WebGUI::Shop::AddressBook', 'new returns the right kind of object');
@ -94,10 +95,10 @@ is($session->getId, $book->session->getId, 'session method returns OUR session o
ok($session->id->valid($book->getId), 'new makes a valid GUID style addressBookId');
is($book->get('userId'), 3, 'new uses $session->user to get the userid for this book');
is($book->userId, 3, '... testing direct accessor');
is($book->get('userId'), $tempAdmin->getId, 'create uses $session->user to get the userid for this book');
is($book->userId, $tempAdmin->getId, '... testing direct accessor');
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->new($session);
@ -163,25 +164,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');
$addrCount = $session->db->quickScalar('select count(*) from address');
$bookCount = $session->db->quickScalar('select count(*) from addressBook where addressBookId=?',[$addressBookId]);
$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;
#######################################################################
#
@ -189,7 +353,6 @@ undef $book;
#
#######################################################################
my $otherSession = WebGUI::Test->newSession;
my $mergeUser = WebGUI::User->create($otherSession);
WebGUI::Test->addToCleanup($mergeUser);
@ -208,3 +371,227 @@ 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;
done_testing;

View file

@ -16,6 +16,7 @@
use strict;
use Test::More;
use Test::Deep;
use Test::Exception;
use Scalar::Util qw/refaddr/;
use WebGUI::Test; # Must use this before any other WebGUI modules
use WebGUI::Session;
@ -30,11 +31,6 @@ use JSON 'from_json';
my $session = WebGUI::Test->session;
my $i18n = WebGUI::International->new($session, "Shop");
#----------------------------------------------------------------------------
# Tests
plan tests => 35; # Increment this number for each test you create
#----------------------------------------------------------------------------
# put your tests here
@ -219,3 +215,11 @@ is($cart->delete, undef, "Can destroy cart.");
$product->purge;
my $requiresShipping_ok = lives_ok { $cart->requiresShipping; } 'requiresShipping does not die if the asset in the cart has been deleted';
SKIP: {
skip 1, 'requiresShipping died, so skipping' unless $requiresShipping_ok;
ok !$cart->requiresShipping, 'Shipping no longer required on a cart with missing assets';
}
done_testing;

View file

@ -129,6 +129,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');