Ready for 7.10.29 development.

This commit is contained in:
Colin Kuskie 2013-03-20 21:38:23 -07:00
commit c806f99b7b
4236 changed files with 1217679 additions and 0 deletions

View file

@ -0,0 +1,49 @@
# 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
Thread's duplicate method fails if the subscriptionGroupId isn't a valid group
(for instance, if it was imported from another site). It should just not copy
the group in that case.
=cut
use warnings;
use strict;
use Test::More tests => 4;
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',
subscriptionGroupId => $session->id->generate(),
}
);
WebGUI::Test->addToCleanup($thread);
SKIP: {
my $copy;
skip('duplicate died', 3) unless
lives_ok { $copy = $thread->duplicate() } q"duplicate() doesn't die";
WebGUI::Test->addToCleanup($copy);
my $groupId = $copy->get('subscriptionGroupId');
ok $groupId, 'Copy has a group id';
isnt $groupId, $thread->get('subscriptionGroupId'), '...a different one';
ok(WebGUI::Group->new($session, $groupId), '...and it instantiates');
};

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

@ -0,0 +1,237 @@
# 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
#------------------------------------------------------------------
# Test the getAdjacentThread (getNextThread and getPreviousThread)
#
#
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;
#----------------------------------------------------------------------------
# Init
my $session = WebGUI::Test->session;
my @versionTags = ( WebGUI::VersionTag->getWorking( $session ) );
my @addChildArgs = ( {skipAutoCommitWorkflows=>1} );
my $collab = WebGUI::Asset->getImportNode( $session )->addChild({
className => 'WebGUI::Asset::Wobject::Collaboration',
threadsPerPage => 20,
});
my @threads = (
$collab->addChild( {
className => 'WebGUI::Asset::Post::Thread',
title => "X - Foo",
isSticky => 0,
threadRating => 4,
}, undef, 1, @addChildArgs),
$collab->addChild( {
className => 'WebGUI::Asset::Post::Thread',
title => "W - Bar",
isSticky => 0,
threadRating => 2,
}, undef, 2, @addChildArgs),
$collab->addChild( {
className => 'WebGUI::Asset::Post::Thread',
title => "Z - Baz",
isSticky => 1,
threadRating => 6,
}, undef, 3, @addChildArgs),
$collab->addChild( {
className => 'WebGUI::Asset::Post::Thread',
title => "Y - Shank",
isSticky => 1,
threadRating => 5,
}, undef, 4, @addChildArgs),
);
$_->setSkipNotification for @threads;
$versionTags[-1]->commit;
WebGUI::Test->addToCleanup($versionTags[-1]);
#----------------------------------------------------------------------------
# Tests
plan tests => 50; # Increment this number for each test you create
#----------------------------------------------------------------------------
# Test get adjacent threads
# sticky threads always come first
my ( $sort );
# sortBy default if nothing set in asset
$sort = sub { $b->get('revisionDate') <=> $a->get('revisionDate') };
testGetAdjacentThread( "default sort", $sort, [ qw( 3 2 1 0 ) ], @threads );
# clear scratch to reset sort
$session->scratch->delete($collab->getId.'_sortBy');
$session->scratch->delete($collab->getId.'_sortDir');
# sortBy default if no default value in asset properties
SKIP: {
skip "This works in Collaboration->getThreadsPaginator. Old code that can be excised?", 8;
# ( assetData.revisionDate DESC )
$session->db->write(
'UPDATE Collaboration SET sortBy=NULL,sortOrder=NULL WHERE assetId=?',
[$collab->getId]
);
my $collab2 = WebGUI::Asset::Wobject::Collaboration->new( $session, $collab->getId );
$sort = sub { $b->get('revisionDate') <=> $a->get('revisionDate') };
testGetAdjacentThread( "no sort set in Collab props", $sort, [ qw( 3 2 1 0 ) ], @threads );
undef $collab2;
}
# sortBy default from asset
$collab->update({
sortBy => 'assetData.revisionDate',
sortOrder => 'asc',
});
$sort = sub { $a->get('revisionDate') <=> $b->get('revisionDate') };
testGetAdjacentThread( "sort by default from asset", $sort, [ qw( 0 1 2 3 ) ], @threads );
# clear scratch to reset sort
$session->scratch->delete($collab->getId.'_sortBy');
$session->scratch->delete($collab->getId.'_sortDir');
# Reset to defaults
$collab->update({
sortBy => 'assetData.revisionDate',
sortOrder => 'desc',
});
# sortBy set directly from scratch
$session->scratch->set($collab->getId.'_sortBy','title');
$session->scratch->set($collab->getId.'_sortDir','desc');
$sort = sub { $b->get('title') cmp $a->get('title') };
testGetAdjacentThread( "sort by set from scratch", $sort, [ qw( 2 3 0 1 ) ], @threads );
# clear scratch to reset sort
$session->scratch->delete($collab->getId.'_sortBy');
$session->scratch->delete($collab->getId.'_sortDir');
# if sortby = "rating", sort is really by "threadRating" column
$collab->update({ sortBy => "rating" });
$sort = sub { $b->get('threadRating') <=> $a->get('threadRating') };
testGetAdjacentThread( "sort by rating is threadRating", $sort, [ qw( 2 3 0 1 ) ], @threads );
# clear scratch to reset sort
$session->scratch->delete($collab->getId.'_sortBy');
$session->scratch->delete($collab->getId.'_sortDir');
# getAdjacentThread checks for version tags
$collab->update({
sortBy => 'assetData.revisionDate',
sortOrder => 'desc',
});
push @versionTags, WebGUI::VersionTag->getWorking( $session );
WebGUI::Test->addToCleanup($versionTags[-1]);
push @threads, $collab->addChild( {
className => 'WebGUI::Asset::Post::Thread',
title => "Abababa",
isSticky => 0,
threadRating => 1_000_000,
}, undef, 6, @addChildArgs
);
$sort = sub { $b->get('revisionDate') <=> $a->get('revisionDate') };
testGetAdjacentThread( "sort by default from asset with version tag", $sort, [ qw( 4 3 2 1 0 ) ], @threads );
# clear scratch to reset sort
$session->scratch->delete($collab->getId.'_sortBy');
$session->scratch->delete($collab->getId.'_sortDir');
#----------------------------------------------------------------------------
# testGetAdjacentThread ( label, sort, order, @threads )
# Performs two tests for each thread in [order]
# Label = a label for the test (usually the sort order)
# Sort = a subroutine to pass to sortThreads
# Order = An array ref of indexes from @threads in the correct order
# @threads = all the threads
sub testGetAdjacentThread {
my ( $label, $sort, $order, @threads ) = @_;
my $idxFirst = shift @{$order};
my $idxLast = pop @{$order};
# First
is( $threads[$idxFirst]->getNextThread->getId,
getNextThread( $sort, $threads[$idxFirst], @threads )->getId,
"$label: Get Next Thread (first)"
);
is( $threads[$idxFirst]->getPreviousThread,
undef,
"$label: Get Previous Thread (first)"
);
# Middle
for my $i ( 1..@{$order} ) {
my $thread = $threads[ $order->[$i-1] ];
is( $thread->getNextThread->getId,
getNextThread( $sort, $thread, @threads )->getId,
"$label: Get Next Thread (" . ($i+1) . ")"
);
is( $thread->getPreviousThread->getId,
getPreviousThread( $sort, $thread, @threads )->getId,
"$label: Get Previous Thread (" . ($i+1) . ")"
);
}
# Last
is( $threads[$idxLast]->getNextThread,
undef,
"$label: Get Next Thread (last)"
);
is( $threads[$idxLast]->getPreviousThread->getId,
getPreviousThread( $sort, $threads[$idxLast], @threads )->getId,
"$label: Get Previous Thread (last)"
);
# Delete internal caches so that tests don't fail mysteriously
for ( @threads ) { delete $_->{_next}; delete $_->{_previous}; delete $_->{_parent} }
}
#----------------------------------------------------------------------------
# sortThreads( \&sortSub, @threads )
# Sort threads according to the given subref. Return an arrayref of hashrefs
sub sortThreads {
my ( $sortSub, @threads ) = @_;
my $sorted = [
# Threads don't do sticky!
#sort { $b->get('isSticky') cmp $a->get('isSticky') }
# Do requested sort
sort $sortSub
@threads
];
return $sorted;
}
sub getNextThread {
my ( $sortSub, $thread, @threads ) = @_;
my @sorted = @{ sortThreads( $sortSub, @threads ) };
for my $i ( 0..$#sorted ) {
if ( $sorted[$i]->getId eq $thread->getId ) {
return $sorted[$i+1];
}
}
}
sub getPreviousThread {
my ( $sortSub, $thread, @threads ) = @_;
# Use reverse so that $i-1 != -1 (which gets us the last thread)
my @sorted = reverse @{ sortThreads( $sortSub, @threads ) };
for my $i ( 0..$#sorted ) {
if ( $sorted[$i]->getId eq $thread->getId ) {
return $sorted[$i+1];
}
}
}

View file

@ -0,0 +1,125 @@
# 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
#------------------------------------------------------------------
# Write a little about what this script tests.
#
#
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::Maker::Permission;
#----------------------------------------------------------------------------
# Init
my $session = WebGUI::Test->session;
$session->user( { userId => 3 } );
my $maker = WebGUI::Test::Maker::Permission->new;
my $node = WebGUI::Asset->getImportNode( $session );
my %user;
$user{"2"} = WebGUI::User->new( $session, "new" );
WebGUI::Test->addToCleanup($user{'2'});
$user{"2"}->addToGroups( ['2'] ); # Registered user
my $versionTag = WebGUI::VersionTag->getWorking( $session );
WebGUI::Test->addToCleanup($versionTag);
$versionTag->set( { name => "Collaboration Test" } );
my @addArgs = ( undef, undef, { skipAutoCommitWorkflows => 1, skipNotification => 1 } );
my $collab
= $node->addChild({
className => "WebGUI::Asset::Wobject::Collaboration",
groupIdView => 7, # Everyone
groupIdEdit => 3, # Admins
groupToEditPost => 3, # Admins
ownerUserId => 3, # Admin
postGroupId => 2, # Registered Users
canStartThreadGroupId => 3, # Admin
allowReplies => 1,
editTimeout => 60 * 60 * 24, # 24 hours
}, @addArgs );
my $thread
= $collab->addChild({
className => 'WebGUI::Asset::Post::Thread',
ownerUserId => $user{"2"}->userId,
groupIdView => 7,
}, @addArgs );
$versionTag->commit( { timeout => 1_000_000 } );
# Re-load the collab to get the newly committed properties
$collab = WebGUI::Asset->newByDynamicClass( $session, $collab->getId );
$thread = WebGUI::Asset->newByDynamicClass( $session, $thread->getId );
#----------------------------------------------------------------------------
# Tests
plan tests => 36;
#----------------------------------------------------------------------------
# Permissions for threads
# View
$maker->prepare( {
object => $thread,
method => 'canView',
pass => [ '1', $user{"2"}, '3', ],
} )->run;
# Subscribe
$maker->prepare( {
object => $thread,
method => 'canSubscribe',
pass => [ $user{"2"}, '3', ],
fail => [ '1', ],
} )->run;
# Edit
$maker->prepare( {
object => $thread,
method => 'canEdit',
pass => [ $user{"2"}, '3', ],
fail => [ '1', ],
} )->run;
# Reply
$maker->prepare( {
object => $thread,
method => 'canReply',
pass => [ $user{"2"}, '3', ],
fail => [ '1', ],
} )->run;
# Reply with allowReplies = 0
$collab->update({ allowReplies => 0 });
$thread = WebGUI::Asset->newByDynamicClass( $session, $thread->getId );
$maker->prepare( {
object => $thread,
method => 'canReply',
fail => [ '1', $user{"2"}, '3', ],
} )->run;
$collab->update({ allowReplies => 1 });
# Reply with thread isLocked
$thread->lock;
$maker->prepare( {
object => $thread,
method => 'canReply',
fail => [ '1', $user{"2"}, '3', ],
} )->run;
$thread->unlock;
WebGUI::Test->addToCleanup('WebGUI::Group' => $thread->get('subscriptionGroupId'));