Ready for 7.10.29 development.
This commit is contained in:
commit
c806f99b7b
4236 changed files with 1217679 additions and 0 deletions
195
t/Asset/Event/edit.t
Normal file
195
t/Asset/Event/edit.t
Normal file
|
|
@ -0,0 +1,195 @@
|
|||
# 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 script uses Test::WWW::Mechanize to test adding and editing Event
|
||||
# assets.
|
||||
#
|
||||
|
||||
use FindBin;
|
||||
use strict;
|
||||
use lib "$FindBin::Bin/../../lib";
|
||||
use Test::More;
|
||||
use Test::Deep;
|
||||
use WebGUI::Test; # Must use this before any other WebGUI modules
|
||||
use WebGUI::Asset;
|
||||
use WebGUI::VersionTag;
|
||||
use WebGUI::Session;
|
||||
plan skip_all => 'set WEBGUI_LIVE to enable this test' unless $ENV{WEBGUI_LIVE};
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Init
|
||||
my $session = WebGUI::Test->session;
|
||||
my $node = WebGUI::Asset->getImportNode( $session );
|
||||
my @versionTags = ( WebGUI::VersionTag->getWorking( $session ) );
|
||||
|
||||
# Override some settings to make things easier to test
|
||||
# userFunctionStyleId
|
||||
$session->setting->set( 'userFunctionStyleId', 'PBtmpl0000000000000132' );
|
||||
$session->setting->set( 'defaultVersionTagWorkflow', 'pbworkflow000000000003' );
|
||||
|
||||
# Create a user for testing purposes
|
||||
my $user = WebGUI::User->new( $session, "new" );
|
||||
WebGUI::Test->addToCleanup($user);
|
||||
$user->username( 'dufresne' . time );
|
||||
my $identifier = 'ritahayworth';
|
||||
my $auth = WebGUI::Operation::Auth::getInstance( $session, $user->authMethod, $user->userId );
|
||||
$auth->saveParams( $user->userId, $user->authMethod, {
|
||||
'identifier' => Digest::MD5::md5_base64( $identifier ),
|
||||
});
|
||||
|
||||
my ( $mech );
|
||||
|
||||
# Get the site's base URL
|
||||
my $baseUrl = 'http://' . $session->config->get('sitename')->[0];
|
||||
|
||||
# Create a Calendar to add Events to
|
||||
my $calendar = $node->addChild( {
|
||||
className => 'WebGUI::Asset::Wobject::Calendar',
|
||||
groupIdEventEdit => '2', # Registered Users
|
||||
groupIdEdit => '3', # Admins
|
||||
workflowIdCommit => 'pbworkflow000000000003', # Commit Without approval
|
||||
} );
|
||||
|
||||
# Remember this event url when we want to edit it later
|
||||
my $eventUrl;
|
||||
|
||||
$versionTags[-1]->commit;
|
||||
WebGUI::Test->addToCleanup($versionTags[-1]);
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
if ( !eval { require Test::WWW::Mechanize; 1; } ) {
|
||||
plan skip_all => 'Cannot load Test::WWW::Mechanize. Will not test.';
|
||||
}
|
||||
$mech = Test::WWW::Mechanize->new;
|
||||
$mech->get( $baseUrl );
|
||||
if ( !$mech->success ) {
|
||||
plan skip_all => "Cannot load URL '$baseUrl'. Will not test.";
|
||||
}
|
||||
|
||||
plan skip_all => 'set WEBGUI_LIVE to enable this test'
|
||||
unless $ENV{WEBGUI_LIVE};
|
||||
|
||||
plan tests => 8; # Increment this number for each test you create
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Add event: Users without permission are not shown form
|
||||
$mech = Test::WWW::Mechanize->new;
|
||||
$mech->get( $baseUrl . $calendar->getUrl('func=add;class=WebGUI::Asset::Event') );
|
||||
|
||||
$mech->content_lacks( q{value="editSave"} );
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Add event: Users with permission are shown form to add event
|
||||
$mech = getMechLogin( $baseUrl, $user, $identifier );
|
||||
|
||||
# Properties given to the form
|
||||
my $properties = {
|
||||
title => 'Event Title',
|
||||
menuTitle => 'Event Menu Title',
|
||||
};
|
||||
|
||||
$mech->get_ok( $baseUrl . $calendar->getUrl('func=add;class=WebGUI::Asset::Event') );
|
||||
$mech->submit_form_ok(
|
||||
{
|
||||
with_fields => $properties,
|
||||
},
|
||||
'Event add form'
|
||||
);
|
||||
|
||||
# Form gets saved correctly
|
||||
my $event
|
||||
= $calendar->getLineage( ['children'], {
|
||||
returnObjects => 1,
|
||||
orderByClause => "creationDate DESC",
|
||||
} )->[0];
|
||||
|
||||
# Add properties that should be set to default
|
||||
$properties = {
|
||||
%{ $properties },
|
||||
ownerUserId => $user->userId,
|
||||
createdBy => $user->userId,
|
||||
groupIdEdit => '2',
|
||||
};
|
||||
|
||||
cmp_deeply( $event->get, superhashof( $properties ), 'Event properties saved correctly' );
|
||||
|
||||
# Save the event URL for later
|
||||
$eventUrl = $event->getUrl;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Edit Event: Users without permission are not shown form
|
||||
$mech = Test::WWW::Mechanize->new;
|
||||
|
||||
$mech->get( $baseUrl . $eventUrl . '?func=edit' );
|
||||
|
||||
$mech->content_lacks( q{value="editSave"} );
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Edit Event: User with permission is shown form to edit event
|
||||
$mech = getMechLogin( $baseUrl, $user, $identifier );
|
||||
|
||||
$mech->get_ok( $baseUrl . $eventUrl . '?func=edit' );
|
||||
|
||||
my $properties = {
|
||||
title => "Event Title" . time,
|
||||
menuTitle => "Event Menu Title" . time,
|
||||
description => "Event Description" . time,
|
||||
};
|
||||
|
||||
$mech->submit_form_ok(
|
||||
{
|
||||
with_fields => $properties,
|
||||
},
|
||||
'Event edit form'
|
||||
);
|
||||
|
||||
# Form gets saved correctly
|
||||
my $event
|
||||
= $calendar->getLineage( ['children'], {
|
||||
returnObjects => 1,
|
||||
orderByClause => "creationDate DESC",
|
||||
} )->[0];
|
||||
|
||||
# Add defaults that should not get set from the form
|
||||
$properties = {
|
||||
%{ $properties },
|
||||
ownerUserId => $user->userId,
|
||||
createdBy => $user->userId,
|
||||
groupIdEdit => '2',
|
||||
};
|
||||
|
||||
cmp_deeply( $event->get, superhashof( $properties ), 'Events properties saved correctly' );
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# getMechLogin( baseUrl, WebGUI::User, "identifier" )
|
||||
# Returns a Test::WWW::Mechanize session after logging in the given user using
|
||||
# the given identifier (password)
|
||||
# baseUrl is a fully-qualified URL to the site to login to
|
||||
sub getMechLogin {
|
||||
my $baseUrl = shift;
|
||||
my $user = shift;
|
||||
my $identifier = shift;
|
||||
|
||||
my $mech = Test::WWW::Mechanize->new;
|
||||
$mech->get( $baseUrl . '?op=auth;method=displayLogin' );
|
||||
$mech->submit_form(
|
||||
with_fields => {
|
||||
username => $user->username,
|
||||
identifier => $identifier,
|
||||
},
|
||||
);
|
||||
|
||||
return $mech;
|
||||
}
|
||||
|
||||
#vim:ft=perl
|
||||
82
t/Asset/Event/permissions.t
Normal file
82
t/Asset/Event/permissions.t
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
# 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::Test::Maker::Permission;
|
||||
use WebGUI::Session;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Init
|
||||
my $session = WebGUI::Test->session;
|
||||
my $maker = WebGUI::Test::Maker::Permission->new;
|
||||
my $node = WebGUI::Asset->getImportNode( $session );
|
||||
|
||||
$session->user({ userId => 3 });
|
||||
my @versionTags = ();
|
||||
push @versionTags, WebGUI::VersionTag->getWorking($session);
|
||||
$versionTags[-1]->set({name=>"Photo Test, add Gallery, Album and 1 Photo"});
|
||||
WebGUI::Test->addToCleanup($versionTags[-1]);
|
||||
|
||||
my $registeredUser = WebGUI::User->new( $session, "new" );
|
||||
WebGUI::Test->addToCleanup($registeredUser);
|
||||
|
||||
# Make a Calendar to add events do
|
||||
my $calendar = $node->addChild({
|
||||
className => 'WebGUI::Asset::Wobject::Calendar',
|
||||
groupIdView => '7', # Everyone
|
||||
groupIdEdit => '3', # Admins
|
||||
groupIdEventEdit => '2', # Registered Users
|
||||
});
|
||||
|
||||
$versionTags[-1]->commit;
|
||||
|
||||
# Arguments for when adding events
|
||||
my @addArgs = ( undef, undef, { skipAutoCommitWorkflows => 1 } );
|
||||
|
||||
my $event;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
plan tests => 12; # Increment this number for each test you create
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Test permissions of an event added by the Admin
|
||||
push @versionTags, WebGUI::VersionTag->getWorking($session);
|
||||
$versionTags[-1]->set({name=>"Photo Test, add Gallery, Album and 1 Photo"});
|
||||
WebGUI::Test->addToCleanup($versionTags[-1]);
|
||||
$event = $calendar->addChild({
|
||||
className => 'WebGUI::Asset::Event',
|
||||
ownerUserId => 3,
|
||||
}, @addArgs);
|
||||
|
||||
$maker->prepare( {
|
||||
object => $event,
|
||||
method => 'canView',
|
||||
pass => [ '1', '3', $registeredUser, ],
|
||||
fail => [ ],
|
||||
} )->run;
|
||||
$maker->prepare( {
|
||||
object => $event,
|
||||
method => 'canEdit',
|
||||
pass => [ '3', ],
|
||||
fail => [ '1', $registeredUser, ],
|
||||
} )->run;
|
||||
|
||||
#vim:ft=perl
|
||||
81
t/Asset/Event/recur.t
Normal file
81
t/Asset/Event/recur.t
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
# 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
|
||||
#------------------------------------------------------------------
|
||||
|
||||
# Tests the recurrence functionality of calendar events
|
||||
|
||||
use strict;
|
||||
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../../../lib";
|
||||
|
||||
use Test::More;
|
||||
use DateTime;
|
||||
use WebGUI::Asset::Event;
|
||||
|
||||
my $startDate = DateTime->new(
|
||||
year => 2000,
|
||||
month => 1,
|
||||
day => 1
|
||||
);
|
||||
|
||||
sub recur {
|
||||
my ($type, $interval, $count, @extra) = @_;
|
||||
my $r = {
|
||||
recurType => $type,
|
||||
every => $interval,
|
||||
endAfter => $count,
|
||||
@extra,
|
||||
};
|
||||
return [
|
||||
map {$_->ymd} WebGUI::Asset::Event->dateSet($r, $startDate)->as_list
|
||||
]
|
||||
}
|
||||
|
||||
is_deeply recur(daily => 3 => 5), [
|
||||
'2000-01-01', '2000-01-04', '2000-01-07', '2000-01-10', '2000-01-13',
|
||||
];
|
||||
|
||||
is_deeply recur(weekday => 3 => 5), [
|
||||
'2000-01-05', '2000-01-10', '2000-01-13', '2000-01-18', '2000-01-21',
|
||||
];
|
||||
|
||||
is_deeply recur(weekly => 2 => 10 => dayNames => [qw(m w f)]), [
|
||||
'2000-01-10', '2000-01-12', '2000-01-14',
|
||||
'2000-01-24', '2000-01-26', '2000-01-28',
|
||||
'2000-02-07', '2000-02-09', '2000-02-11', '2000-02-21'
|
||||
];
|
||||
|
||||
is_deeply recur(monthDay => 3 => 4 => dayNumber => 4), [
|
||||
'2000-01-04', '2000-04-04', '2000-07-04', '2000-10-04'
|
||||
];
|
||||
|
||||
is_deeply recur(monthWeek => 1 => 6 => dayNames => ['w'], weeks => ['fifth']), [
|
||||
'2000-01-26', '2000-02-23', '2000-03-29',
|
||||
'2000-04-26', '2000-05-31', '2000-06-28',
|
||||
];
|
||||
|
||||
is_deeply recur(yearDay => 2 => 3, months => ['feb'], dayNumber => 2), [
|
||||
'2000-02-02', '2002-02-02', '2004-02-02',
|
||||
];
|
||||
|
||||
my %labor_day = (
|
||||
months => ['sep'],
|
||||
weeks => ['first'],
|
||||
dayNames => ['m'],
|
||||
);
|
||||
is_deeply recur(yearWeek => 3 => 3, %labor_day), [
|
||||
'2000-09-04', '2003-09-01', '2006-09-04'
|
||||
];
|
||||
|
||||
done_testing;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
#vim:ft=perl
|
||||
Loading…
Add table
Add a link
Reference in a new issue