Merge branch 'master' of git@github.com:plainblack/webgui

This commit is contained in:
daviddelikat 2009-10-14 10:42:41 -05:00
commit fa40b99182
52 changed files with 3081 additions and 3155 deletions

View file

@ -935,10 +935,12 @@ like($message, qr/Exported $numberCreatedAll pages/, "... returns correct messag
$extrasSymlink = Path::Class::File->new($exportPath, $extrasUrl);
$uploadsSymlink = Path::Class::File->new($exportPath, $uploadsUrl);
ok(-e $extrasSymlink->absolute->stringify, "exportAsHtml writes extras symlink");
ok(-e $extrasSymlink->absolute->stringify, "exportAsHtml writes extras symlink")
or diag "link not found at " . $extrasSymlink->absolute;
is(readlink $extrasSymlink->absolute->stringify, $extrasPath, "exportAsHtml extras symlink points to right place");
ok(-e $uploadsSymlink->absolute->stringify, "exportAsHtml writes uploads symlink");
ok(-e $uploadsSymlink->absolute->stringify, "exportAsHtml writes uploads symlink")
or diag "link not found at " . $uploadsSymlink->absolute;
is(readlink $uploadsSymlink->absolute->stringify, $uploadsPath, "exportAsHtml uploads symlink points to right place");
# next, make sure the root URL symlinking works.
@ -946,6 +948,7 @@ eval { ($message) = $parent->exportAsHtml( { userId => 3, depth => 99, rootUr
my $rootUrlSymlink = Path::Class::File->new($exportPath, 'index.html');
is($@, '', 'exportAsHtml does not throw an error when linking root URL');
like($message, qr/Exported $numberCreatedAll pages/, "... returns correct message");
ok(-l $rootUrlSymlink->absolute->stringify, "... writes root URL symlink");
ok(-l $rootUrlSymlink->absolute->stringify, "... writes root URL symlink")
or diag "link not found at " . $rootUrlSymlink->absolute;
is(readlink $rootUrlSymlink->absolute->stringify, WebGUI::Asset->getDefault($session)->exportGetUrlAsPath->absolute->stringify, "... root URL symlink points to right place");

64
t/Asset/Post/Thread.t Normal file
View file

@ -0,0 +1,64 @@
#-------------------------------------------------------------------
# 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";
use WebGUI::Test;
use WebGUI::Session;
use Test::More tests => 2; # increment this value for each test you create
use Test::MockObject::Extends;
use WebGUI::Asset::Wobject::Collaboration;
use WebGUI::Asset::Post::Thread;
my $session = WebGUI::Test->session;
# Do our work in the import node
my $node = WebGUI::Asset->getImportNode($session);
# Grab a named version tag
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"Collab setup"});
addToCleanup($versionTag);
# Need to create a Collaboration system in which the post lives.
my @addArgs = ( undef, undef, { skipAutoCommitWorkflows => 1, skipNotification => 1 } );
my $collab = $node->addChild({className => 'WebGUI::Asset::Wobject::Collaboration', editTimeout => '1'}, @addArgs);
# finally, add the post to the collaboration system
my $props = {
className => 'WebGUI::Asset::Post::Thread',
content => 'hello, world!',
ownerUserId => 1,
};
my $thread = $collab->addChild($props, @addArgs);
$versionTag->commit();
# Test for a sane object type
isa_ok($thread, 'WebGUI::Asset::Post::Thread');
my $env = $session->env;
$env = Test::MockObject::Extends->new($env);
my %mockEnv = (
REMOTE_ADDR => '192.168.0.2',
);
$env->mock('get', sub { return $mockEnv{$_[1]}});
$session->user({userId => 3});
$thread->rate(1);
$thread->trash;
is($thread->get('threadRating'), 0, 'trash does not die, and updates the threadRating to 0');
# vim: syntax=perl filetype=perl

View file

@ -122,6 +122,7 @@ $story = $archive->addChild({
title => 'Story 1',
subtitle => 'The story of a CMS',
byline => 'JT Smith',
story => 'WebGUI was originally called Web Done Right.',
});
isa_ok($story, 'WebGUI::Asset::Story', 'Created a Story asset');
@ -276,7 +277,7 @@ cmp_deeply(
$story->getRssData,
{
title => 'Story 1',
description => 'The story of a CMS',
description => 'WebGUI was originally called Web Done Right.',
'link' => re('story-1$'),
author => 'JT Smith',
date => $story->get('lastModified'),

View file

@ -16,7 +16,7 @@ use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use Test::More tests => 18; # increment this value for each test you create
use Test::More tests => 17; # increment this value for each test you create
use WebGUI::Asset::Wobject::WikiMaster;
use WebGUI::Asset::WikiPage;
@ -25,15 +25,16 @@ my $session = WebGUI::Test->session;
my $node = WebGUI::Asset->getImportNode($session);
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"Wiki Test"});
WebGUI::Test->tagsToRollback($versionTag);
addToCleanup($versionTag);
my $wiki = $node->addChild({className=>'WebGUI::Asset::Wobject::WikiMaster'});
$versionTag->commit;
my $wikipage = $wiki->addChild({className=>'WebGUI::Asset::WikiPage'});
my $wikipage = $wiki->addChild({className=>'WebGUI::Asset::WikiPage'}, undef, undef, {skipAutoCommitWorkflows => 1});
# Wikis create and autocommit a version tag when a child is added. Lets get the name so we can roll it back.
my $secondVersionTag = WebGUI::VersionTag->new($session,$wikipage->get("tagId"));
WebGUI::Test->tagsToRollback($secondVersionTag );
$secondVersionTag->commit;
addToCleanup($secondVersionTag );
# Test for sane object types
isa_ok($wiki, 'WebGUI::Asset::Wobject::WikiMaster');
@ -85,11 +86,3 @@ $comments = $wikipage->get('comments');
is($comments->[0]{comment}, $secondComment, "you can delete a comment");
is($wikipage->get('averageCommentRating'), 1, 'average rating is adjusted after deleting a comment');
##################
TODO: {
local $TODO = "Tests to make later";
ok(0, 'Lots and lots to do');
}

View file

@ -177,7 +177,7 @@ cmp_deeply(
$session->user({userId => 3});
my $json = $matrix->www_getCompareFormData('score');
diag $session->getId;
note $session->getId;
my $compareFormData = JSON->new->decode($json);

View file

@ -266,6 +266,7 @@ like($storage->getFileContentsAsScalar($filename), qr{
}
$survey->getAdminConsole();
my $adminConsole = $survey->getAdminConsole();
cmp_deeply(
$adminConsole->{_submenuItem},

View file

@ -20,9 +20,11 @@ use Data::Dumper;
use WebGUI::Test;
use WebGUI::Session;
use Test::More tests => 20; # increment this value for each test you create
use Test::More tests => 21; # increment this value for each test you create
use Test::Deep;
use WebGUI::Asset::Wobject::SyndicatedContent;
use XML::FeedPP;
use WebGUI::Cache;
my $session = WebGUI::Test->session;
my %var;
@ -36,7 +38,7 @@ my $node = WebGUI::Asset->getImportNode($session);
# Create a version tag to work in
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"SyndicatedContent Test"});
WebGUI::Test->tagsToRollback($versionTag);
addToCleanup($versionTag);
my $syndicated_content = $node->addChild({className=>'WebGUI::Asset::Wobject::SyndicatedContent'});
##############################
@ -138,3 +140,39 @@ EOFEED
my $vars = $syndicated_content->getTemplateVariables($feed);
ok( defined $vars->{item_loop}->[0]->{description}, 'getTemplateVariables: description is not undefined');
####################################################################
#
# generateFeed, hasTerms
#
####################################################################
my $tbbUrl = 'http://www.plainblack.com/tbb.rss';
$syndicated_content->update({
rssUrl => $tbbUrl,
hasTerms => 'WebGUI',
});
my $cache = WebGUI::Cache->new($session, $tbbUrl, 'RSS');
open my $rssFile, '<', WebGUI::Test->getTestCollateralPath('tbb.rss')
or die "Unable to get RSS file";
my $rssContent = do { local $/; <$rssFile>; };
close $rssFile;
$cache->set($rssContent, 60);
my $filteredFeed = $syndicated_content->generateFeed();
use Data::Dumper;
diag Dumper($filteredFeed->get_item());
cmp_deeply(
[ map { $_->title } $filteredFeed->get_item() ],
[
'Google Picasa Plugin for WebGUI Gallery',
'WebGUI Roadmap',
'WebGUI 8 Performance',
],
'generateFeed: filters items based on the terms being in title, or description'
);
$cache->delete;

View file

@ -26,7 +26,7 @@ my $session = WebGUI::Test->session;
# put your tests here
plan tests => 23;
plan tests => 25;
my $timeZoneUser = addUser($session);
@ -76,6 +76,14 @@ my $dt1970 = WebGUI::DateTime->new($session, 0);
isa_ok($dt1970, 'WebGUI::DateTime', 'constructed with 0');
is($dt1970->epoch, 0, '... uses 0 for epoch');
my $bday = WebGUI::DateTime->new($session, '2001-08-16');
isa_ok($bday, 'WebGUI::DateTime', 'constructed with mysql date, no time');
is(
$bday->epoch,
WebGUI::DateTime->new($session, WebGUI::Test->webguiBirthday)->truncate( to => 'day')->epoch,
'... has correct epoch'
);
sub addUser {
my $session = shift;
my $user = WebGUI::User->new($session, "new");

View file

@ -19,7 +19,7 @@ use Test::More;
use Test::Deep;
use Data::Dumper;
use MIME::Parser;
use Encode qw/decode/;
use Encode qw/decode encode/;
use WebGUI::Test;
@ -42,7 +42,7 @@ if ( $@ ) { diag( "Can't prepare mail server: $@" ) }
#----------------------------------------------------------------------------
# Tests
plan tests => 16; # Increment this number for each test you create
plan tests => 17; # Increment this number for each test you create
#----------------------------------------------------------------------------
# Test create
@ -115,6 +115,18 @@ is( $mime->parts(0)->as_string =~ m/\n/, $newlines,
"addHtmlRaw should add newlines after 78 characters",
);
use utf8;
$mail = WebGUI::Mail::Send->create( $session, {
to => 'norton@localhost',
subject => "H\x{00C4}ufige Fragen",
});
$mail->addHeaderField('List-ID', "H\x{00C4}ufige Fragen");
my $messageId = $mail->queue;
diag $messageId;
my $dbMail = WebGUI::Mail::Send->retrieve($session, $messageId);
diag ref $dbMail;
is($dbMail->getMimeEntity->head->get('List-ID'), "=?UTF-8?Q?H=C3=84ufige=20Fragen?=\n", 'addHeaderField: handles utf-8 correctly');
# TODO: Test that addHtml creates a body with the right content type
my $smtpServerOk = 0;

View file

@ -93,19 +93,6 @@ cmp_deeply (
hoverHelp => ignore(),
defaultValue => 7,
},
receiptEmailTemplateId => {
fieldType => 'template',
label => ignore(),
hoverHelp => ignore(),
defaultValue => 'bPz1yk6Y9uwMDMBcmMsSCg',
namespace => 'Shop/EmailReceipt',
},
saleNotificationGroupId => {
fieldType => 'group',
label => ignore(),
hoverHelp => ignore(),
defaultValue => 3,
},
}
} ],
,
@ -286,7 +273,7 @@ my @forms = HTML::Form->parse($html, 'http://www.webgui.org');
is (scalar @forms, 1, 'getEditForm generates just 1 form');
my @inputs = $forms[0]->inputs;
is (scalar @inputs, 14, 'getEditForm: the form has 14 controls');
is (scalar @inputs, 11, 'getEditForm: the form has 11 controls');
my @interestingFeatures;
foreach my $input (@inputs) {
@ -342,18 +329,6 @@ cmp_deeply(
name => '__groupToUse_isIn',
type => 'hidden',
},
{
name => 'receiptEmailTemplateId',
type => 'option',
},
{
name => 'saleNotificationGroupId',
type => 'option',
},
{
name => '__saleNotificationGroupId_isIn',
type => 'hidden',
},
],
'getEditForm made the correct form with all the elements'

View file

@ -372,7 +372,7 @@ my @forms = HTML::Form->parse($html, 'http://www.webgui.org');
is (scalar @forms, 1, 'getEditForm generates just 1 form');
my @inputs = $forms[0]->inputs;
is (scalar @inputs, 20, 'getEditForm: the form has 20 controls');
is (scalar @inputs, 17, 'getEditForm: the form has 17 controls');
my @interestingFeatures;
foreach my $input (@inputs) {
@ -428,18 +428,6 @@ cmp_deeply(
name => '__groupToUse_isIn',
type => 'hidden',
},
{
name => 'receiptEmailTemplateId',
type => 'option',
},
{
name => 'saleNotificationGroupId',
type => 'option',
},
{
name => '__saleNotificationGroupId_isIn',
type => 'hidden',
},
{
name => 'pspid',
type => 'text',

View file

@ -24,7 +24,7 @@ use Data::Dumper;
use WebGUI::Test; # Must use this before any other WebGUI modules
use WebGUI::Session;
plan tests => 46;
plan tests => 64;
use_ok('WebGUI::Shop::ShipDriver::USPS')
or die 'Unable to load module WebGUI::Shop::ShipDriver::USPS';
@ -42,8 +42,16 @@ $session->user({user => $user});
# put your tests here
my $storage;
my ($driver, $cart);
my ($driver2, $cart);
my $insuranceTable = <<EOTABLE;
5:1.00
10:2.00
15:3.00
20:4.00
25:5.00
30:6.00
EOTABLE
my $versionTag = WebGUI::VersionTag->getWorking($session);
my $home = WebGUI::Asset->getDefault($session);
@ -92,8 +100,16 @@ my $nivBible = $bible->setCollateral('variantsJSON', 'variantId', 'new',
}
);
my $gospels = $bible->setCollateral('variantsJSON', 'variantId', 'new',
{
shortdesc => 'Gospels from the new Testament',
price => 1.50, varSku => 'gospels',
weight => 2.0, quantity => 999999,
}
);
$versionTag->commit;
WebGUI::Test->tagsToRollback($versionTag);
addToCleanup($versionTag);
#######################################################################
#
@ -133,10 +149,11 @@ my $options = {
enabled => 1,
};
$driver = WebGUI::Shop::ShipDriver::USPS->create($session, $options);
$driver2 = WebGUI::Shop::ShipDriver::USPS->create($session, $options);
addToCleanup($driver2);
isa_ok($driver, 'WebGUI::Shop::ShipDriver::USPS');
isa_ok($driver, 'WebGUI::Shop::ShipDriver');
isa_ok($driver2, 'WebGUI::Shop::ShipDriver::USPS');
isa_ok($driver2, 'WebGUI::Shop::ShipDriver');
#######################################################################
#
@ -152,13 +169,13 @@ is (WebGUI::Shop::ShipDriver::USPS->getName($session), 'U.S. Postal Service', 'g
#
#######################################################################
my $driverId = $driver->getId;
$driver->delete;
my $driverId = $driver2->getId;
$driver2->delete;
my $count = $session->db->quickScalar('select count(*) from shipper where shipperId=?',[$driverId]);
is($count, 0, 'delete deleted the object');
undef $driver;
undef $driver2;
#######################################################################
#
@ -166,11 +183,12 @@ undef $driver;
#
#######################################################################
$driver = WebGUI::Shop::ShipDriver::USPS->create($session, {
my $driver = WebGUI::Shop::ShipDriver::USPS->create($session, {
label => 'Shipping from Shawshank',
enabled => 1,
shipType => 'PARCEL',
});
addToCleanup($driver);
eval { $driver->calculate() };
$e = Exception::Class->caught();
@ -199,6 +217,7 @@ cmp_deeply(
);
$cart = WebGUI::Shop::Cart->newBySession($session);
addToCleanup($cart);
my $addressBook = $cart->getAddressBook;
my $workAddress = $addressBook->addAddress({
label => 'work',
@ -283,6 +302,22 @@ $driver->update($properties);
$rockHammer->addToCart($rockHammer->getCollateral('variantsJSON', 'variantId', $smallHammer));
my @shippableUnits = $driver->_getShippableUnits($cart);
$properties = $driver->get();
$properties->{addInsurance} = 1;
$properties->{insuranceRates} = $insuranceTable;
$driver->update($properties);
is($driver->_calculateInsurance(@shippableUnits), 2, '_calculateInsurance: one item in cart with quantity=1, calculates insurance');
$properties->{addInsurance} = 0;
$driver->update($properties);
is($driver->_calculateInsurance(@shippableUnits), 0, '_calculateInsurance: returns 0 if insurance is not enabled');
$properties->{addInsurance} = 1;
$properties->{insuranceRates} = '';
$driver->update($properties);
is($driver->_calculateInsurance(@shippableUnits), 0, '_calculateInsurance: returns 0 if rates are not set');
my $xml = $driver->buildXML($cart, @shippableUnits);
like($xml, qr/<RateV3Request USERID="[^"]+"/, 'buildXML: checking userId is an attribute of the RateV3Request tag');
like($xml, qr/<Package ID="0"/, 'buildXML: checking ID is an attribute of the Package tag');
@ -359,8 +394,10 @@ is($cost, 5.25, '_calculateFromXML calculates shipping cost correctly for 1 item
$bibleItem = $bible->addToCart($bible->getCollateral('variantsJSON', 'variantId', $nivBible));
@shippableUnits = $driver->_getShippableUnits($cart);
$xml = $driver->buildXML($cart, @shippableUnits);
is(calculateInsurance($driver), 7, '_calculateInsurance: two items in cart with quantity=1, calculates insurance');
$xml = $driver->buildXML($cart, @shippableUnits);
$xmlData = XMLin( $xml,
KeepRoot => 1,
ForceArray => ['Package'],
@ -458,6 +495,8 @@ is($cost, 12.25, '_calculateFromXML calculates shipping cost correctly for 2 ite
$bibleItem->setQuantity(2);
@shippableUnits = $driver->_getShippableUnits($cart);
is(calculateInsurance($driver), 8, '_calculateInsurance: two items in cart with quantity=2, calculates insurance');
$cost = $driver->_calculateFromXML({
Package => [
{
@ -481,6 +520,7 @@ is($cost, 19.25, '_calculateFromXML calculates shipping cost correctly for 2 ite
$rockHammer2 = $rockHammer->addToCart($rockHammer->getCollateral('variantsJSON', 'variantId', $bigHammer));
$rockHammer2->update({shippingAddressId => $wucAddress->getId});
@shippableUnits = $driver->_getShippableUnits($cart);
is(calculateInsurance($driver), 12, '_calculateInsurance: calculates insurance');
$xml = $driver->buildXML($cart, @shippableUnits);
$xmlData = XMLin( $xml,
@ -575,6 +615,12 @@ SKIP: {
}
#######################################################################
#
# Test Priority shipping setup
#
#######################################################################
$cart->empty;
$properties = $driver->get();
$properties->{shipType} = 'PRIORITY';
@ -637,6 +683,12 @@ SKIP: {
}
#######################################################################
#
# Test EXPRESS shipping setup
#
#######################################################################
$properties = $driver->get();
$properties->{shipType} = 'EXPRESS';
$driver->update($properties);
@ -695,6 +747,11 @@ SKIP: {
}
#######################################################################
#
# Test PRIORITY VARIABLE shipping setup
#
#######################################################################
$properties = $driver->get();
$properties->{shipType} = 'PRIORITY VARIABLE';
@ -754,16 +811,60 @@ SKIP: {
}
#######################################################################
#
# _calculateInsurance edge case
#
#######################################################################
$cart->empty;
$bible->addToCart($bible->getCollateral('variantsJSON', 'variantId', $gospels));
@shippableUnits = $driver->_getShippableUnits($cart);
is(calculateInsurance($driver), 1, '_calculateInsurance: calculates insurance using the first bin');
#######################################################################
#
# _parseInsuranceRates
#
#######################################################################
my @rates;
@rates = WebGUI::Shop::ShipDriver::USPS::_parseInsuranceRates("");
cmp_deeply(\@rates, [], '_parseInsuranceRates: empty string returns empty array');
@rates = WebGUI::Shop::ShipDriver::USPS::_parseInsuranceRates();
cmp_deeply(\@rates, [], '_parseInsuranceRates: undef returns empty array');
@rates = WebGUI::Shop::ShipDriver::USPS::_parseInsuranceRates("2");
cmp_deeply(\@rates, [], '... bad rates #1');
@rates = WebGUI::Shop::ShipDriver::USPS::_parseInsuranceRates(":2");
cmp_deeply(\@rates, [], '... bad rates #2');
@rates = WebGUI::Shop::ShipDriver::USPS::_parseInsuranceRates("a:b");
cmp_deeply(\@rates, [], '... bad rates #3');
@rates = WebGUI::Shop::ShipDriver::USPS::_parseInsuranceRates("2:2");
cmp_deeply(\@rates, [ ['2', '2'] ], '... one line of good rates');
@rates = WebGUI::Shop::ShipDriver::USPS::_parseInsuranceRates("2.0:2.0");
cmp_deeply(\@rates, [ ['2.0', '2.0'] ], '... one line of good rates with decimal points');
@rates = WebGUI::Shop::ShipDriver::USPS::_parseInsuranceRates("2.0:2.0\n");
cmp_deeply(\@rates, [ ['2.0', '2.0'] ], '... one line of good rates with newline');
@rates = WebGUI::Shop::ShipDriver::USPS::_parseInsuranceRates("2.0:2.0\r\n");
cmp_deeply(\@rates, [ ['2.0', '2.0'] ], '... one line of good rates with cr/newline');
@rates = WebGUI::Shop::ShipDriver::USPS::_parseInsuranceRates("2.0 : 2.0\r\n");
cmp_deeply(\@rates, [ ['2.0', '2.0'] ], '... one line of good rates with cr/newline and spaces');
@rates = WebGUI::Shop::ShipDriver::USPS::_parseInsuranceRates(" 2.0 : 2.0 \r\n");
cmp_deeply(\@rates, [ ['2.0', '2.0'] ], '... one line of good rates with cr/newline and more spaces');
#----------------------------------------------------------------------------
# Cleanup
END {
if (defined $driver && $driver->isa('WebGUI::Shop::ShipDriver')) {
$driver->delete;
}
if (defined $cart && $cart->isa('WebGUI::Shop::Cart')) {
my $addressBook = $cart->getAddressBook();
$addressBook->delete if $addressBook;
$cart->delete;
}
sub calculateInsurance {
my $driver = shift;
my $properties = $driver->get();
$properties->{addInsurance} = 1;
$properties->{insuranceRates} = $insuranceTable;
$driver->update($properties);
my $insurance = $driver->_calculateInsurance(@shippableUnits);
$properties->{addInsurance} = 0;
$driver->update($properties);
return $insurance;
}

View file

@ -21,6 +21,8 @@ use Test::Deep;
use WebGUI::Test; # Must use this before any other WebGUI modules
use WebGUI::Session;
use WebGUI::Shop::Transaction;
use WebGUI::Inbox;
use Clone qw/clone/;
#----------------------------------------------------------------------------
# Init
@ -30,7 +32,7 @@ my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
plan tests => 68; # Increment this number for each test you create
plan tests => 77; # Increment this number for each test you create
#----------------------------------------------------------------------------
# put your tests here
@ -64,6 +66,7 @@ my $transaction = WebGUI::Shop::Transaction->create($session,{
paymentDriverLabel => 'kkk',
taxes => 7,
});
addToCleanup($transaction);
# objects work
isa_ok($transaction, "WebGUI::Shop::Transaction");
@ -223,15 +226,72 @@ TODO: {
ok(0, 'test keywords');
}
#######################################################################
#
# sendNotification
#
#######################################################################
my $shopUser = WebGUI::User->create($session);
$shopUser->username('shopUser');
my $shopGroup = WebGUI::Group->new($session, 'new');
my $shopAdmin = WebGUI::User->create($session);
$shopUser->username('shopAdmin');
$shopGroup->addUsers([$shopAdmin->getId]);
addToCleanup($shopUser, $shopAdmin, $shopGroup);
$session->setting->set('shopSaleNotificationGroupId', $shopGroup->getId);
$session->user({userId => $shopUser->getId});
my $trans = WebGUI::Shop::Transaction->create($session, {});
ok($trans->can('sendNotifications'), 'sendNotifications: valid method for transactions');
addToCleanup($trans);
##Disable sending email
my $sendmock = Test::MockObject->new( {} );
$sendmock->set_isa('WebGUI::Mail::Send');
$sendmock->set_true('addText', 'send', 'addHeaderField', 'addHtml', 'queue', 'addFooter');
local *WebGUI::Mail::Send::create;
$sendmock->fake_module('WebGUI::Mail::Send',
create => sub { return $sendmock },
);
#1234567890123456789012#
my $templateId = 'SHOP_NOTIFICATION_____';
my $templateMock = Test::MockObject->new({});
$templateMock->set_isa('WebGUI::Asset::Template');
$templateMock->set_always('getId', $templateId);
my @templateVars;
$templateMock->mock('process', sub { push @templateVars, clone $_[1]; } );
$session->setting->set('shopReceiptEmailTemplateId', $templateId);
{
WebGUI::Test->mockAssetId($templateId, $templateMock);
$trans->sendNotifications;
is(@templateVars, 2, '... called template->process twice');
my $inbox = WebGUI::Inbox->new($session);
my $userMessages = $inbox->getMessagesForUser($shopUser);
my $adminMessages = $inbox->getMessagesForUser($shopAdmin);
is(@{ $userMessages }, 1, '... sent one message to shop user');
is(@{ $adminMessages }, 1, '... sent one message to shop admin, via shopSaleNotificationGroupId');
like($userMessages->[0]->get('subject'), qr/^Receipt for Order #/, '... subject for user email okay');
like($adminMessages->[0]->get('subject'), qr/^A sale has been made/, '... subject for admin email okay');
like($templateVars[0]->{viewDetailUrl}, qr/shop=transaction;method=viewMy;/, '... viewDetailUrl okay for user');
like($templateVars[1]->{viewDetailUrl}, qr/shop=transaction;method=view;/ , '... viewDetailUrl okay for admin');
WebGUI::Test->unmockAssetId($templateId);
}
#######################################################################
#
# delete
#
#######################################################################
$transaction->delete;
is($session->db->quickScalar("select transactionId from transaction where transactionId=?",[$transaction->getId]), undef, "can delete transactions");
is($session->db->quickScalar("select count(*) from transaction where transactionId=?",[$transaction->getId]),
0, "delete: deleted transaction");
is($session->db->quickScalar("select count(*) from transactionItem where transactionId=?",[$transaction->getId]),
0, "... deleted transactionItems associated with this transaction");
#----------------------------------------------------------------------------
# Cleanup
END {
$session->db->write('delete from transaction');
$session->db->write('delete from transactionItem');
}

View file

@ -32,7 +32,7 @@ my $cwd = Cwd::cwd();
my ($extensionTests, $fileIconTests) = setupDataDrivenTests($session);
my $numTests = 127; # increment this value for each test you create
my $numTests = 134; # increment this value for each test you create
plan tests => $numTests + scalar @{ $extensionTests } + scalar @{ $fileIconTests };
my $uploadDir = $session->config->get('uploadsPath');
@ -54,6 +54,7 @@ my $storage1 = WebGUI::Storage->get($session);
is( $storage1, undef, "get requires id to be passed");
$storage1 = WebGUI::Storage->get($session, 'foobar');
addToCleanup($storage1);
isa_ok( $storage1, "WebGUI::Storage", "storage will accept non GUID arguments");
is ( $storage1->getId, 'foobar', 'getId returns the requested GUID');
@ -80,7 +81,7 @@ $guidDir->mkpath();
ok(-e $guidDir->stringify, 'created GUID storage location for backwards compatibility testing');
my $guidStorage = WebGUI::Storage->get($session, $newGuid);
WebGUI::Test->storagesToDelete($guidStorage);
addToCleanup($guidStorage);
isa_ok($guidStorage, 'WebGUI::Storage');
is($guidStorage->getId, $newGuid, 'GUID storage has correct id');
is($guidStorage->getDirectoryId, $newGuid, '... getDirectoryId');
@ -115,7 +116,7 @@ undef $storage1;
$storage1 = WebGUI::Storage->get($session, 'notAGUID');
my $storage2 = WebGUI::Storage->get($session, 'notAGoodId');
WebGUI::Test->storagesToDelete($storage2);
addToCleanup($storage2);
ok(! $storage2->getErrorCount, 'No errors due to a shared common root');
@ -147,7 +148,7 @@ CHECKDIR: while ($dirOpt = pop @dirOptions) {
last CHECKDIR if !-e $dir3;
}
my $storage3 = WebGUI::Storage->get($session, $dirOpt);
WebGUI::Test->storagesToDelete($storage3);
addToCleanup($storage3);
is( $storage3->getErrorCount, 1, 'Error during creation of object due to short GUID');
@ -223,6 +224,7 @@ foreach my $extTest (@{ $extensionTests }) {
####################################################
my $fileStore = WebGUI::Storage->create($session);
addToCleanup($fileStore);
cmp_bag($fileStore->getFiles(1), ['.'], 'Starting with an empty storage object, no files in here except for . ');
$fileStore->addFileFromScalar('.dotfile', 'dot file');
cmp_bag($fileStore->getFiles(), [ ], 'getFiles() by default does not return dot files');
@ -302,25 +304,26 @@ ok(
####################################################
my $copiedStorage = $storage1->copy();
addToCleanup($copiedStorage);
cmp_bag($copiedStorage->getFiles(), $storage1->getFiles(), 'copy: both storage objects have the same files');
my $secondCopy = WebGUI::Storage->create($session);
addToCleanup($secondCopy);
$storage1->copy($secondCopy);
cmp_bag($secondCopy->getFiles(), $storage1->getFiles(), 'copy: passing explicit variable');
my $s3copy = WebGUI::Storage->create($session);
WebGUI::Test->storagesToDelete($s3copy);
addToCleanup($s3copy);
my @filesToCopy = qw/WebGUI.pm testfile-hash-renamed.file/;
$storage1->copy($s3copy, [@filesToCopy]);
cmp_bag($s3copy->getFiles(), [ @filesToCopy ], 'copy: passing explicit variable and files to copy');
{
my $deepStorage = WebGUI::Storage->create($session);
WebGUI::Test->storagesToDelete($deepStorage);
addToCleanup($deepStorage);
my $deepDir = $deepStorage->getPathClassDir();
my $deepDeepDir = $deepDir->subdir('deep');
my $errorStr;
my @foo = $deepDeepDir->mkpath({ error => \$errorStr } );
note explain \@foo;
$deepStorage->addFileFromScalar('deep/file', 'deep file');
cmp_bag(
$deepStorage->getFiles('all'),
@ -328,7 +331,7 @@ cmp_bag($s3copy->getFiles(), [ @filesToCopy ], 'copy: passing explicit variable
'... storage setup for deep clear test'
);
my $deepCopy = $deepStorage->copy();
WebGUI::Test->storagesToDelete($deepCopy);
addToCleanup($deepCopy);
cmp_bag(
$deepCopy->getFiles('all'),
[ '.', 'deep', 'deep/file' ],
@ -351,7 +354,7 @@ cmp_bag($storage1->getFiles, [$filename], 'deleteFile: storage1 has only 1 file'
##Test for out of object file deletion
my $hackedStore = WebGUI::Storage->create($session);
WebGUI::Test->storagesToDelete($hackedStore);
addToCleanup($hackedStore);
$hackedStore->addFileFromScalar('fileToHack', 'Can this file be deleted from another object?');
ok(-e $hackedStore->getPath('fileToHack'), 'set up a file for deleteFile to try and delete illegally');
my $hackedPath = '../../../'.$hackedStore->getPathFrag().'/fileToHack';
@ -365,6 +368,7 @@ ok(-e $hackedStore->getPath('fileToHack'), 'deleteFile did not delete the file i
####################################################
my $tempStor = WebGUI::Storage->createTemp($session);
addToCleanup($tempStor);
isa_ok( $tempStor, "WebGUI::Storage", "createTemp creates WebGUI::Storage object");
is (substr($tempStor->getPathFrag, 0, 5), 'temp/', '... puts stuff in the temp directory');
@ -379,6 +383,7 @@ is($tempStor->getHexId, $session->id->toHex($tempStor->getId), '... returns the
####################################################
my $tarStorage = $copiedStorage->tar('tar.tar');
addToCleanup($tarStorage);
isa_ok( $tarStorage, "WebGUI::Storage", "tar: returns a WebGUI::Storage object");
is (substr($tarStorage->getPathFrag, 0, 5), 'temp/', 'tar: puts stuff in the temp directory');
cmp_bag($tarStorage->getFiles(), [ 'tar.tar' ], 'tar: storage contains only the tar file');
@ -391,6 +396,7 @@ isnt($tarStorage->getPath, $copiedStorage->getPath, 'tar did not reuse the same
####################################################
my $untarStorage = $tarStorage->untar('tar.tar');
addToCleanup($untarStorage);
isa_ok( $untarStorage, "WebGUI::Storage", "untar: returns a WebGUI::Storage object");
is (substr($untarStorage->getPathFrag, 0, 5), 'temp/', 'untar: puts stuff in the temp directory');
##Note, getFiles will NOT recurse, so do not use a deep directory structure here
@ -431,7 +437,7 @@ cmp_bag(
{
my $deepStorage = WebGUI::Storage->create($session);
WebGUI::Test->storagesToDelete($deepStorage);
addToCleanup($deepStorage);
my $deepDir = $deepStorage->getPathClassDir();
my $deepDeepDir = $deepDir->subdir('deep');
my $errorStr;
@ -461,13 +467,23 @@ is($fileStore->addFileFromFormPost(), '', 'addFileFromFormPost returns empty str
$session->http->setStatus(200);
$session->request->upload('files', []);
is($fileStore->addFileFromFormPost('files'), undef, 'addFileFromFormPost returns empty string when asking for a form variable with no files attached');
my $formStore = WebGUI::Storage->create($session);
addToCleanup($formStore);
is($formStore->addFileFromFormPost('files'), undef, 'addFileFromFormPost returns empty string when asking for a form variable with no files attached');
$session->request->uploadFiles(
'oneFile',
[ WebGUI::Test->getTestCollateralPath('WebGUI.pm') ],
);
is($fileStore->addFileFromFormPost('oneFile'), 'WebGUI.pm', 'Return the name of the uploaded file');
is($formStore->addFileFromFormPost('oneFile'), 'WebGUI.pm', '... returns the name of the uploaded file');
cmp_bag($formStore->getFiles, [ qw/WebGUI.pm/ ], '... adds the file to the storage location');
$session->request->uploadFiles(
'thumbFile',
[ WebGUI::Test->getTestCollateralPath('thumb-thumb.gif') ],
);
is($formStore->addFileFromFormPost('thumbFile'), 'thumb.gif', '... strips thumb- prefix from files');
cmp_bag($formStore->getFiles, [ qw/WebGUI.pm thumb.gif/ ], '... adds the file to the storage location');
####################################################
#
@ -486,7 +502,7 @@ foreach my $iconTest (@{ $fileIconTests }) {
####################################################
my $shallowStorage = WebGUI::Storage->create($session);
WebGUI::Test->storagesToDelete($shallowStorage);
addToCleanup($shallowStorage);
$shallowStorage->setPrivileges(3,3,3);
my $shallowDir = $shallowStorage->getPathClassDir();
ok(-e $shallowDir->file('.wgaccess')->stringify, 'setPrivilege: .wgaccess file created in shallow storage');
@ -496,7 +512,7 @@ is ($privs, "3\n3\n3", '... correct group contents');
$shallowStorage->deleteFile('.wgaccess');
my $deepStorage = WebGUI::Storage->create($session);
WebGUI::Test->storagesToDelete($deepStorage);
addToCleanup($deepStorage);
my $deepDir = $deepStorage->getPathClassDir();
my $deepDeepDir = $deepDir->subdir('deep');
my $errorStr;
@ -533,6 +549,7 @@ $session->config->set('cdn', $cdnCfg);
my $cdnUrl = $cdnCfg->{'url'};
my $cdnUlen = length $cdnUrl;
my $cdnStorage = WebGUI::Storage->create($session);
addToCleanup($cdnStorage);
# Functional URL before sync done
my $hexId = $session->id->toHex($cdnStorage->getId);
my $initUrl = join '/', $uploadUrl, $cdnStorage->getPathFrag;
@ -596,6 +613,7 @@ $mockEnv{HTTPS} = undef;
is ($cdnStorage->getUrl, $locUrl, 'CDN: getUrl: cleartext request to not use sslUrl');
# Copy
my $cdnCopy = $cdnStorage->copy;
addToCleanup($cdnCopy);
my $qcp = $cdnCfg->{'queuePath'} . '/' . $session->id->toHex($cdnCopy->getId);
ok (-e $qcp, 'CDN: queue file created when storage location copied');
my $dotcp = $cdnCopy->getPath . '/.cdn';
@ -624,6 +642,23 @@ undef $cdnStorage;
$session->config->delete('cdn');
####################################################
#
# Test what happens when the directory for a
# storage object does not exist.
#
####################################################
my $zombieStorage = WebGUI::Storage->create($session);
addToCleanup($zombieStorage);
my $zombieDir = $zombieStorage->getPathClassDir;
$zombieDir->remove;
is( $zombieStorage->getPathClassDir, undef, 'bad storage: getPathClassDir returns undef');
cmp_deeply( $zombieStorage->getFiles, [], '... getFiles returns an empty array ref');
cmp_deeply( $zombieStorage->setPrivileges, undef, '... setPrivileges returns undef');
cmp_deeply( $zombieStorage->clear, undef, '... setPrivileges returns undef');
####################################################
#
# Make sure after all this that our CWD is still the same
@ -694,20 +729,3 @@ sub setupDataDrivenTests {
return ($extensionTests, $fileIconTests)
}
####################################################
#
# END block, clean-up after yourself
#
####################################################
END {
foreach my $stor (
$storage1, $copiedStorage,
$secondCopy, $tempStor, $tarStorage,
$untarStorage, $fileStore,
$cdnStorage, $cdnCopy,
) {
ref $stor eq "WebGUI::Storage" and $stor->delete;
}
}

View file

@ -14,7 +14,7 @@ use lib "$FindBin::Bin/lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::VersionTag;
use Test::More tests => 68; # increment this value for each test you create
use Test::More tests => 74; # increment this value for each test you create
my $session = WebGUI::Test->session;
@ -379,6 +379,38 @@ $adminUserTag->rollback();
setSiteVersionTagMode($session, q{multiPerUser});
setUserVersionTagMode($user, q{inherited});
my $andySession = WebGUI::Test->newSession();
my $redSession = WebGUI::Test->newSession();
my $andy = WebGUI::User->create($andySession);
my $red = WebGUI::User->create($redSession);
addToCleanup($andy, $red);
my $andyTag = WebGUI::VersionTag->getWorking($andySession);
addToCleanup($andyTag);
my $redTag = WebGUI::VersionTag->new($redSession, $andyTag->getId);
$redTag->setWorking();
is($andyTag->getId, $redTag->getId, 'users share the same version tag');
$andyTag->leaveTag;
{
my $andyTagCheck = WebGUI::VersionTag->getWorking($andySession, 'nocreate');
is($andyTagCheck, undef, 'leaveTag: user andy does not have tag');
my $redTagCheck = WebGUI::VersionTag->getWorking($redSession, 'nocreate');
isa_ok($redTagCheck, 'WebGUI::VersionTag', '... user red does');
is($redTagCheck->getId, $redTag->getId, '... user red still has the same tag as before');
}
my $andyTag2 = WebGUI::VersionTag->new($session, $redTag->getId);
$andyTag2->clearWorking;
{
my $andyTagCheck = WebGUI::VersionTag->getWorking($andySession, 'nocreate');
is($andyTagCheck, undef, 'clearWorking: user andy does not have tag');
my $redSession2 = $redSession->duplicate;
addToCleanup($redSession2);
my $redTagCheck = WebGUI::VersionTag->getWorking($redSession2, 'nocreate');
is($redTagCheck, undef, 'red does not either');
}
# Local variables:
# mode: cperl

View file

@ -74,8 +74,6 @@ our @EXPORT_OK = qw(session config);
my $CLASS = __PACKAGE__;
my @guarded;
our @checkCount;
our %initCounts;
sub import {
our $CONFIG_FILE = $ENV{ WEBGUI_CONFIG };
@ -101,22 +99,34 @@ sub import {
if ($ENV{WEBGUI_TEST_DEBUG}) {
##Offset Sessions, and Scratch by 1 because 1 will exist at the start
@checkCount = (
Sessions => userSession => 1,
Scratch => userSessionScratch => 1,
Users => users => 0,
Groups => groups => 0,
mailQ => mailQueue => 0,
Tags => assetVersionTag => 0,
Assets => assetData => 0,
Workflows => Workflow => 0,
Carts => cart => 0,
my @checkCount = (
Sessions => 'userSession',
Scratch => 'userSessionScratch',
Users => 'users',
Groups => 'groups',
mailQ => 'mailQueue',
Tags => 'assetVersionTag',
Assets => 'assetData',
Workflows => 'Workflow',
Carts => 'cart',
Transactions => 'transaction',
'Transaction Items' => 'transactionItem',
'Ship Drivers' => 'shipper',
);
for ( my $i = 0; $i < @checkCount; $i += 3) {
my %initCounts;
for ( my $i = 0; $i < @checkCount; $i += 2) {
my ($label, $table) = @checkCount[$i, $i+1];
$initCounts{$table} = $session->db->quickScalar('SELECT COUNT(*) FROM ' . $table);
}
push @guarded, Scope::Guard->new(sub {
for ( my $i = 0; $i < @checkCount; $i += 2) {
my ($label, $table) = @checkCount[$i, $i+1];
my $quant = $session->db->quickScalar('SELECT COUNT(*) FROM ' . $table);
my $delta = $quant - $initCounts{$table};
if ($delta) {
$CLASS->builder->diag(sprintf '%-10s: %4d (delta %+d)', $label, $quant, $delta);
}
}
});
}
@ -133,25 +143,15 @@ sub cleanup {
pop @guarded
while @guarded;
if ( my $session = $CLASS->session ) {
$session->var->end;
my $db = delete $session->{_db};
$session->close;
##Do this absolutely last, so that there's no session or other object pieces left over.
if ($ENV{WEBGUI_TEST_DEBUG}) {
for ( my $i = 0; $i < @checkCount; $i += 3) {
my ($label, $table, $offset) = @checkCount[$i, $i+1, $i+2];
my $quant = $db->quickScalar('SELECT COUNT(*) FROM ' . $table);
my $delta = $quant - $initCounts{$table} + $offset;
if ($delta) {
$CLASS->builder->diag(sprintf '%-10s: %4d (delta %+d)', $label, $quant, $delta);
}
}
}
$db->disconnect;
if ( our $SESSION ) {
$SESSION->var->end;
$SESSION->close;
undef $SESSION;
}
}
#----------------------------------------------------------------------------
=head2 newSession ( $noCleanup )
Builds a WebGUI session object for testing.
@ -162,8 +162,6 @@ If true, the session won't be registered for automatic deletion.
=cut
#----------------------------------------------------------------------------
sub newSession {
my $noCleanup = shift;
my $pseudoRequest = WebGUI::PseudoRequest->new;
@ -176,6 +174,8 @@ sub newSession {
}
#----------------------------------------------------------------------------
=head2 mockAssetId ( $assetId, $object )
Causes WebGUI::Asset->new* initializers to return the specified
@ -767,6 +767,9 @@ were passed in. Currently able to destroy:
WebGUI::User
WebGUI::VersionTag
WebGUI::Workflow
WebGUI::Shop::Cart
WebGUI::Shop::ShipDriver
WebGUI::Shop::Transaction
Example call:
@ -835,14 +838,21 @@ Example call:
);
my %cleanup = (
'WebGUI::User' => 'delete',
'WebGUI::Group' => 'delete',
'WebGUI::Storage' => 'delete',
'WebGUI::Shop::Cart' => 'delete',
'WebGUI::Asset' => 'purge',
'WebGUI::VersionTag' => 'rollback',
'WebGUI::Workflow' => 'delete',
'WebGUI::Session' => sub {
'WebGUI::User' => 'delete',
'WebGUI::Group' => 'delete',
'WebGUI::Storage' => 'delete',
'WebGUI::Asset' => 'purge',
'WebGUI::VersionTag' => 'rollback',
'WebGUI::Workflow' => 'delete',
'WebGUI::Shop::Transaction' => 'delete',
'WebGUI::Shop::ShipDriver' => 'delete',
'WebGUI::Shop::Cart' => sub {
my $cart = shift;
my $addressBook = $cart->getAddressBook();
$addressBook->delete if $addressBook; ##Should we call cleanupGuard instead???
$cart->delete;
},
'WebGUI::Session' => sub {
my $session = shift;
$session->var->end;
$session->close;

View file

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title>The Black Blog</title>
<link>/tbb</link>
<copyright /><pubDate>Mon, 12 Oct 2009 11:54:28 -0500</pubDate>
<description /><item><title>Google Picasa Plugin for WebGUI Gallery</title>
<link>http://www.plainblack.com/tbb/google-picasa-plugin-for-webgui-gallery</link>
<author>JT</author>
<epochDate>1254854387</epochDate>
<guid isPermaLink="true">http://www.plainblack.com/tbb/google-picasa-plugin-for-webgui-gallery</guid>
<pubDate>Tue, 06 Oct 2009 13:39:47 -0500</pubDate>
<userDefined1 /><userDefined2 /><userDefined3 /><userDefined4 /><userDefined5 /><description>Today we unveil the Google Picasa plugin for WebGUI Gallery.</description>
</item>
<item><title>WebGUI Roadmap</title>
<link>http://www.plainblack.com/tbb/webgui-roadmap</link>
<author>JT</author>
<epochDate>1254325377</epochDate>
<guid isPermaLink="true">http://www.plainblack.com/tbb/webgui-roadmap</guid>
<pubDate>Wed, 30 Sep 2009 10:42:57 -0500</pubDate>
<userDefined1 /><userDefined2 /><userDefined3 /><userDefined4 /><userDefined5 /><description>The new roadmap is online.</description>
</item>
<item><title>WebGUI 8 Performance</title>
<link>http://www.plainblack.com/tbb/webgui-8-performance</link>
<author>JT</author>
<epochDate>1254236976</epochDate>
<guid isPermaLink="true">http://www.plainblack.com/tbb/webgui-8-performance</guid>
<pubDate>Tue, 29 Sep 2009 10:09:36 -0500</pubDate>
<userDefined1 /><userDefined2 /><userDefined3 /><userDefined4 /><userDefined5 /><description>WebGUI 8 is going to be the fastest version of WebGUI ever released.</description>
</item>
<item><title>I have arrived in Lisboa!</title>
<link>http://www.plainblack.com/tbb/i-have-arrived-in-lisboa</link>
<author>JT</author>
<epochDate>1249140064</epochDate>
<guid isPermaLink="true">http://www.plainblack.com/tbb/i-have-arrived-in-lisboa</guid>
<pubDate>Sat, 01 Aug 2009 10:21:04 -0500</pubDate>
<userDefined1 /><userDefined2 /><userDefined3 /><userDefined4 /><userDefined5 /><description>I&apos;m in Lisbon, Portugal for YAPC::EU.</description>
</item>
</channel>
</rss>

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB