Skip to content
Permalink
Browse files

WebGUI 8 adjustments and test upgrades.

  • Loading branch information...
perlDreamer committed Nov 1, 2011
1 parent 9a4703e commit 3b9f7ae12716f529db3e6ad05fee3b25b2c659cc
@@ -1076,8 +1076,8 @@ sub www_preview {
my $session = $self->session;
return $session->privilege->insufficient unless $self->canEdit;

my $form = $session->form;
my $http = $session->http;
my $form = $session->form;
my $response = $session->response;

try {
my $output = $self->processRaw(
@@ -1087,14 +1087,14 @@ sub www_preview {
$form->get('parser'),
);
if ($form->get('plainText')) {
$http->setMimeType('text/plain');
$response->content_type('text/plain');
}
elsif ($output !~ /<html>/) {
$output = $session->style->userStyle($output);
}
return $output;
} catch {
$http->setMimeType('text/plain');
$response->content_type('text/plain');
$_[0];
}
}
@@ -916,7 +916,7 @@ sub www_createAccountSave {
$profile->{'language'} = $self->session->scratch->getLanguageOverride;
}
$u->karma($self->session->setting->get("karmaPerLogin"),"Login","Just for logging in.") if ($self->session->setting->get("useKarma"));
$u->updateProfileFields($profile) if ($profile);
$u->update($profile);
$self->update($properties);

my $address = {};
@@ -927,6 +927,8 @@ sub www_createAccountSave {
$address->{$address_key} = $profile->{$fieldId} if ($address_key);
}

$self->session->user({user=>$u});

#Update or create and update the shop address
if ( keys %$address ) {
$address->{'isProfile' } = 1;
@@ -962,7 +964,6 @@ sub www_createAccountSave {
});
}

$self->session->user({user=>$u});
$self->_logLogin($userId,"success");

if ($self->session->setting->get("runOnRegistration")) {
@@ -138,7 +138,7 @@ sub handler {
return undef unless $op && $op eq 'generatePdf';
my $asset = getRequestedAsset($session);
return $session->privilege->noAccess unless $asset->canView;
$session->http->setMimeType('application/pdf');
$session->response->content_type('application/pdf');
return cache($asset);
}

@@ -91,6 +91,7 @@ property "addressBookId" => (
property "isProfile" => (
noFormPost => 1,
required => 0,
default => 0,
);

has [ qw/addressId addressBook/] => (
@@ -625,18 +625,18 @@ sub www_ajaxSearch {

my $name = $form->get('name');
my $fields = {
firstName => (split(" ",$name))[0] || "",
lastName => (split(" ",$name))[1] || "",
organization => $form->get('organization') || "",
address1 => $form->get('address1') || "",
address2 => $form->get('address2') || "",
address3 => $form->get('address3') || "",
city => $form->get('city') || "",
state => $form->get('state') || "",
code => $form->get('zipcode') || "",
country => $form->get('country') || "",
email => $form->get('email') || "",
phoneNumber => $form->get('phone') || "",
'address.firstName' => (split(" ",$name))[0] || "",
'address.lastName' => (split(" ",$name))[1] || "",
'address.organization' => $form->get('organization') || "",
'address.address1' => $form->get('address1') || "",
'address.address2' => $form->get('address2') || "",
'address.address3' => $form->get('address3') || "",
'address.city' => $form->get('city') || "",
'address.state' => $form->get('state') || "",
'address.code' => $form->get('zipcode') || "",
'address.country' => $form->get('country') || "",
'address.email' => $form->get('email') || "",
'address.phoneNumber' => $form->get('phone') || "",
};

my $clause = [];
@@ -645,7 +645,7 @@ sub www_ajaxSearch {
foreach my $field (keys %$fields) {
my $field_value = $fields->{$field};
if($field_value) {
$field = $session->db->dbh->quote_identifier($field);
$field = join('.', map { $session->db->quote_identifier($_) } split(/\./, $field));
$field_value = $field_value."%";
push(@$clause,qq{$field like ?});
push(@$params,$field_value);
@@ -663,8 +663,8 @@ sub www_ajaxSearch {

my $query = qq{
select
address.*,
users.username
users.username,
address.*
from
address
join addressBook on address.addressBookId = addressBook.addressBookId
@@ -679,7 +679,7 @@ sub www_ajaxSearch {
push(@$var,$hash);
}

$session->http->setMimeType('text/plain');
$session->response->content_type('text/plain');
return JSON->new->encode($var);
}

@@ -114,6 +114,7 @@ sub getDrivers {
my $self = shift;
my %drivers = ();
CLASS: foreach my $class (@{$self->session->config->get('paymentDrivers')}) {
$self->session->log->warn($class);
my $driverName = eval { WebGUI::Pluggable::instanciate($class, 'getName', [ $self->session ])};
if ($@) {
$self->session->log->warn("Error loading $class: $@");
@@ -20,10 +20,26 @@ The following methods are available from this class.
=cut

use base qw/WebGUI::Shop::PayDriver/;
use Moose;
use WebGUI::Definition::Shop;
extends 'WebGUI::Shop::PayDriver';

Readonly my $I18N => 'PayDriver_CreditCard';

define pluginName => 'Credit Card Base Class';
property useCVV2 => (
fieldType => 'yesNo',
label => ['use cvv2', $I18N],
hoverHelp => ['use cvv2 help', $I18N],
);
property credentialsTemplateId => (
fieldType => 'template',
label => ['credentials template', $I18N],
hoverHelp => ['credentials template help', $I18N],
namespace => 'Shop/Credentials',
default => 'itransact_credentials1',
);

#-------------------------------------------------------------------
sub _monthYear {
my $session = shift;
@@ -92,35 +108,6 @@ sub appendCredentialVars {
return;
}

#-------------------------------------------------------------------
sub definition {
my ($class, $session, $definition) = @_;

my $i18n = WebGUI::International->new($session, $I18N);

tie my %fields, 'Tie::IxHash', (
useCVV2 => {
fieldType => 'yesNo',
label => $i18n->get('use cvv2'),
hoverHelp => $i18n->get('use cvv2 help'),
},
credentialsTemplateId => {
fieldType => 'template',
label => $i18n->get('credentials template'),
hoverHelp => $i18n->get('credentials template help'),
namespace => 'Shop/Credentials',
defaultValue => 'itransact_credentials1',
},
);

push @{ $definition }, {
name => 'Credit Card Base Class',
properties => \%fields,
};

return $class->SUPER::definition($session, $definition);
}

#-------------------------------------------------------------------

=head2 processCredentials
@@ -8,8 +8,29 @@ use DateTime;
use Readonly;
use Business::OnlinePayment;

use Moose;
use WebGUI::Definition::Shop;
extends 'WebGUI::Shop::PayDriver::CreditCard';

Readonly my $I18N => 'PayDriver_AuthorizeNet';

define pluginName => ['name', $I18N];
property login => (
fieldType => 'text',
label => ['login', $I18N],
hoverHelp => ['login help', $I18N],
);
property transaction_key => (
fieldType => 'text',
label => ['transaction key', $I18N],
hoverHelp => ['transaction key help', $I18N],
);
property testMode => (
fieldType => 'YesNo',
label => ['test mode', $I18N],
hoverHelp => ['test mode help', $I18N],
);

=head1 NAME
WebGUI::Shop::PayDriver::CreditCard::AuthorizeNet
@@ -87,38 +108,6 @@ sub cancelRecurringPayment {
return $self->gatewayResponse($tx);
}

#-------------------------------------------------------------------
sub definition {
my ( $class, $session, $definition ) = @_;

my $i18n = WebGUI::International->new( $session, $I18N );

tie my %fields, 'Tie::IxHash', (
login => {
fieldType => 'text',
label => $i18n->get('login'),
hoverHelp => $i18n->get('login help'),
},
transaction_key => {
fieldType => 'text',
label => $i18n->get('transaction key'),
hoverHelp => $i18n->get('transaction key help'),
},
testMode => {
fieldType => 'YesNo',
label => $i18n->get('test mode'),
hoverHelp => $i18n->get('test mode help'),
},
);

push @{$definition}, {
name => $i18n->get('name'),
properties => \%fields,
};

return $class->SUPER::definition( $session, $definition );
} ## end sub definition

#-------------------------------------------------------------------

=head2 gatewayObject ( params )
@@ -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'));
@@ -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({
@@ -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,19 +108,17 @@ $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',
"returnUrl field is used to set redirect after login",
);
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'
);
@@ -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'
);
Oops, something went wrong.

0 comments on commit 3b9f7ae

Please sign in to comment.
You can’t perform that action at this time.