WebGUI 8 adjustments and test upgrades.

This commit is contained in:
Colin Kuskie 2011-11-01 15:41:01 -07:00
parent 9a4703eca0
commit 3b9f7ae127
14 changed files with 115 additions and 132 deletions

View file

@ -31,12 +31,17 @@ use WebGUI::Test;
use WebGUI::Asset;
my $session = WebGUI::Test->session;
my $thread = WebGUI::Asset->getImportNode($session)->addChild(
my $cs = WebGUI::Asset->getImportNode($session)->addChild(
{
className => 'WebGUI::Asset::Wobject::Collaboration',
}
);
my $thread = $cs->addChild(
{
className => 'WebGUI::Asset::Post::Thread',
}
);
WebGUI::Test->addToCleanup($thread);
WebGUI::Test->addToCleanup($cs);
$thread->createSubscriptionGroup();
my $admin = WebGUI::User->new($session, 3);
ok !$admin->isInGroup($thread->get('subscriptionGroupId'));

View file

@ -92,10 +92,10 @@ $session->request->setup_body({
});
$session->user({userId => '3'});
$session->http->setStatus(200);
$session->response->status(200);
my $json = $thingy->www_editThingDataSaveViaAjax();
is $json, '{}', 'www_editThingDataSaveViaAjax: Empty JSON hash';
is $session->http->getStatus, 200, '... http status=200';
is $session->response->status, 200, '... http status=200';
$session->request->setup_body({

View file

@ -28,7 +28,6 @@ my $session = WebGUI::Test->session;
my @cleanupUsernames = (); # Will be cleaned up when we're done
my $auth; # will be used to create auth instances
my ($request, $oldRequest, $output);
#----------------------------------------------------------------------------
# Tests
@ -54,7 +53,7 @@ WebGUI::Test->addToCleanup(sub {
});
$createAccountSession->scratch->setLanguageOverride($language);
$output = $auth->www_createAccountSave( $username, { }, "PASSWORD" );
my $output = $auth->www_createAccountSave( $username, { }, "PASSWORD" );
WebGUI::Test->addToCleanup(sub {
for my $username ( @cleanupUsernames ) {
# We don't create actual, real users, so we have to cleanup by hand
@ -92,7 +91,7 @@ is(
"returnUrl field is used to set redirect after createAccountSave",
);
is $createAccountSession->user->profileField('language'), $language, 'languageOverride is taken in to account in createAccountSave';
is $createAccountSession->user->get('language'), $language, 'languageOverride is taken in to account in createAccountSave';
$createAccountSession->scratch->delete('language'); ##Remove language override
@ -109,7 +108,7 @@ $auth = WebGUI::Auth->new( $loginSession, 3 );
my $username = $loginSession->id->generate;
push @cleanupUsernames, $username;
$session->setting->set('showMessageOnLogin', 0);
$output = $auth->login;
$output = $auth->www_login;
is(
$loginSession->response->location, 'REDIRECT_LOGIN_URL',
@ -117,11 +116,9 @@ is(
);
is $output, undef, 'login returns undef when showMessageOnLogin is false';
# Session Cleanup
$session->{_request} = $oldRequest;
#----------------------------------------------------------------------------
# Test createAccountSave
$auth = WebGUI::Auth->new( $session );
$username = $session->id->generate;
push @cleanupUsernames, $username;
@ -138,14 +135,14 @@ tie my %profile_info, "Tie::IxHash", (
email => 'andy@shawshank.com'
);
$auth->createAccountSave( $username, { }, "PASSWORD", \%profile_info );
diag $auth->www_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 ],
[ map { $andy->get($_) } keys %profile_info ],
[ values %profile_info ],
'Profile fields were saved'
);

View file

@ -123,7 +123,7 @@ cmp_deeply(
addressId => ignore(), #checked elsewhere
addressBookId => $book->getId,
addressBook => $book,
isProfile => 0,
isProfile => bool(0),
},
'get the whole thing and check a new, blank object'
);

View file

@ -16,6 +16,7 @@
use strict;
use Test::More;
use Test::Deep;
use Data::Dumper;
use Exception::Class;
use WebGUI::Test; # Must use this before any other WebGUI modules
@ -194,9 +195,6 @@ is($profile_address->getId,$address1->getId,"getProfileAddress returns addresses
#
#######################################################################
#Clear the book address cache
$book->uncache;
my $address_info = {
label => 'Profile Label',
addressId => $address1->getId,
@ -232,14 +230,11 @@ cmp_bag(
my $u = WebGUI::User->new($session,$book->get("userId"));
cmp_bag(
[ map { $u->profileField($_) } keys %{ $book->getProfileAddressMappings } ],
[ map { $u->get($_) } 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,
@ -275,7 +270,7 @@ cmp_bag(
);
cmp_bag(
[ map { $u->profileField($_) } keys %{ $book->getProfileAddressMappings } ],
[ map { $u->get($_) } keys %{ $book->getProfileAddressMappings } ],
[ map { $address1->get($_) } values %{ $book->getProfileAddressMappings } ],
'Profile address was not updated when non profile fields were saved'
);
@ -286,9 +281,6 @@ cmp_bag(
#
#######################################################################
#clear the cache
$book->uncache;
$session->request->setup_body({
'addressId' => $address2->getId,
'callback' => q|{'url':''}|
@ -304,9 +296,6 @@ cmp_bag(
);
#clear the cache
$book->uncache;
$session->request->setup_body({
'addressId' => $address1->getId,
'callback' => q|{'url':''}|
@ -328,9 +317,6 @@ cmp_bag(
#
#######################################################################
#clear the cache
$book->uncache;
my $addressBookId = $alreadyHaveBook->getId;
my $firstCount = $session->db->quickScalar('select count(*) from addressBook where addressBookId=?',[$addressBookId]);
$alreadyHaveBook->delete();
@ -381,6 +367,7 @@ cmp_bag(
#Create some data to search for
my $andySession = WebGUI::Test->newSession;
my $andy = WebGUI::User->create($andySession);
$andy->username('andy');
WebGUI::Test->addToCleanup($andy);
$andySession->user({ userId => $andy->getId });
my $andyBook = WebGUI::Shop::AddressBook->create($andySession);
@ -421,6 +408,7 @@ my $andyAddr2 = $andyBook->addAddress({
my $redSession = WebGUI::Test->newSession;
my $red = WebGUI::User->create($redSession);
$red->username('red');
WebGUI::Test->addToCleanup($red);
$redSession->user({userId => $red->getId});
my $redBook = WebGUI::Shop::AddressBook->create($redSession);
@ -439,12 +427,14 @@ my $redAddr = $redBook->addAddress({
country => 'US',
phoneNumber => '111-111-1111',
email => 'red@shawshank.com',
organization => 'Shawshank'
organization => 'Shawshank',
isProfile => 0,
});
my $brooksSession = WebGUI::Test->newSession;
my $brooks = WebGUI::User->create($brooksSession);
$brooks->username('brooks');
WebGUI::Test->addToCleanup($brooks);
$brooksSession->user({userId => $brooks->getId});
my $brooksBook = WebGUI::Shop::AddressBook->create($brooksSession);
@ -463,7 +453,8 @@ my $brooksAddr = $brooksBook->addAddress({
country => 'US',
phoneNumber => '111-111-1111',
email => 'brooks@shawshank.com',
organization => 'Shawshank'
organization => 'Shawshank',
isProfile => 0,
});
#Test search as admin
@ -473,11 +464,20 @@ $session->request->setup_body({
my $results = JSON->new->decode($book->www_ajaxSearch);
my $andyAddr1_get = $andyAddr1->get;
my $andyAddr2_get = $andyAddr2->get;
my $redAddr_get = $redAddr->get;
my $brooksAddr_get = $brooksAddr->get;
foreach my $addr ($andyAddr1_get, $andyAddr2_get, $redAddr_get, $brooksAddr_get) {
delete $addr->{addressBook};
}
cmp_bag(
$results,
[
{ %{$andyAddr1->get}, username => $andy->username },
{ %{$andyAddr2->get}, username => $andy->username },
{ %{$andyAddr1_get}, username => $andy->username, },
{ %{$andyAddr2_get}, username => $andy->username, },
],
'Ajax Address Search matches name correctly for admins'
);
@ -501,7 +501,7 @@ $results = JSON->new->decode($book->www_ajaxSearch);
cmp_bag(
$results,
[{ %{$andyAddr1->get}, username => $andy->username }],
[{ %{$andyAddr1_get}, username => $andy->username }],
'Ajax Address Search matches multiple fields correctly'
);
@ -539,9 +539,9 @@ $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 },
{ %{$andyAddr1_get}, username => $andy->username },
{ %{$redAddr_get}, username => $red->username },
{ %{$brooksAddr_get}, username => $brooks->username },
],
'Ajax Address Search returns cross user results for admins'
);
@ -556,9 +556,9 @@ $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 },
{ %{$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'
);
@ -573,9 +573,9 @@ $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 },
{ %{$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'
);
@ -588,7 +588,7 @@ $results = JSON->new->decode($brooksBook->www_ajaxSearch);
cmp_bag(
$results,
[{ %{$brooksAddr->get}, username => $brooks->username }],
[{ %{$brooksAddr_get}, username => $brooks->username }],
'Ajax Address Search returns only current user results for non privileged users'
);

View file

@ -17,6 +17,7 @@ use strict;
use Test::More;
use Test::Deep;
use Test::Exception;
use Data::Dumper;
use JSON;
use HTML::Form;
@ -132,7 +133,8 @@ my $defaultPayDrivers = {
'WebGUI::Shop::PayDriver::CreditCard::AuthorizeNet' => 'Credit Card (Authorize.net)',
};
cmp_deeply( $drivers, $defaultPayDrivers, 'getDrivers returns the default PayDrivers');
cmp_deeply( $drivers, $defaultPayDrivers, 'getDrivers returns the default PayDrivers')
or diag Dumper $drivers;
#######################################################################
#