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

This commit is contained in:
daviddelikat 2009-10-14 10:51:56 -05:00
commit ae257f4e37
153 changed files with 246 additions and 13731 deletions

View file

@ -29,7 +29,7 @@ my $df = WebGUI::Asset->getImportNode($session)->addChild( {
className => 'WebGUI::Asset::Wobject::DataForm',
} );
WebGUI::Test->tagsToRollback( WebGUI::VersionTag->getWorking( $session ) );
addToCleanup( WebGUI::VersionTag->getWorking( $session ) );
# Add fields to the dataform
$df->createField( "name", { type => "text", } );
@ -49,18 +49,20 @@ my @entryProperties = (
}
);
my $birthday = WebGUI::Test->webguiBirthday;
my @entries = ();
for my $properties (@entryProperties) {
my $entry = $df->entryClass->newFromHash( $df, $properties );
$entry->submissionDate(WebGUI::DateTime->new($session, $birthday++));
$entry->save;
push @entries, $entry;
sleep 1;
}
#----------------------------------------------------------------------------
# Tests
plan tests => 2; # Increment this number for each test you create
plan tests => 6; # Increment this number for each test you create
#----------------------------------------------------------------------------
# Test getListTemplateVars
@ -184,8 +186,63 @@ cmp_deeply(
'getListTemplateVars is complete and correct',
);
is($tmplVar->{'pagination.pageCount'}, 1, '... and has pagination variables');
#----------------------------------------------------------------------------
# Cleanup
#-------------------------------------
#Shove in a bunch of data to test pagination
my @quoteDb = (
{ name => "Red", message => "That tall drink of water", },
{ name => "Norton", message => "Do you enjoy working in the laundry?", },
{ name => "Andy", message => "They say it has no memory", },
{ name => "Boggs", message => "Hey, we all need friends in here", },
{ name => "Andy", message => "It's my life. Don't you understand?", },
{ name => "Red", message => "Rehabilitated? Well, now let me see.", },
{ name => "Red", message => "I know what *you* think it means, sonny.", },
{ name => "Red", message => "I know what *you* think it means, sonny.", },
{ name => "Andy", message => "How can you be so obtuse?", },
{ name => "Red", message => "The man likes to play chess; let's get him some rocks. ", },
{ name => "Brooks", message => "Easy peasy japanesey.", },
{ name => "Hadley", message => "What is your malfunction?", },
{ name => "Red", message => "Hope is a dangerous thing. Hope can drive a man insane. ", },
{ name => "Red", message => "They send you here for life, and that's exactly what they take.", },
{ name => "Red", message => "Truth is, I don't want to know. Some things are best left unsaid.", },
{ name => "Andy", message => "That's the beauty of music.", },
{ name => "Red", message => "I played a mean harmonica as a younger man.", },
{ name => "Tommy", message => "I don't read so good.", },
{ name => "Andy", message => "You don't read so *well*.", },
{ name => "Red", message => "Murder, same as you.", },
{ name => "Norton", message => "Salvation lies within.", },
{ name => "Andy", message => "Remember Red, hope is a good thing.", },
{ name => "Hadley", message => "Drink up while it's cold, ladies.", },
{ name => "Red", message => "We sat and drank with the sun on our shoulders and felt like free men.", },
{ name => "Andy", message => "You see that's tax deductible, you can write that off. ", },
{ name => "Norton", message => "Lord! It's a miracle!", },
{ name => "Red", message => "I don't have her stuffed down the front of my pants right now, I'm sorry to say, but I'll get her.", },
{ name => "Andy", message => "Get busy living, or get busy dying.", },
{ name => "Brooks", message => "The world went and got itself in a big damn hurry.", },
{ name => "Andy", message => "Everybody's innocent in here. Didn't you know that?", },
);
for my $quote (@quoteDb) {
my $entry = $df->entryClass->newFromHash( $df, $quote );
$entry->submissionDate(WebGUI::DateTime->new($session, $birthday++));
$entry->save;
push @entries, $entry;
}
$tmplVar = $df->getListTemplateVars({});
is @{ $tmplVar->{record_loop} }, 25, 'list variables are paginated';
ok $tmplVar->{'pagination.pageCount.isMultiple'}, 'pagination: has multiple pages';
$session->request->setup_body({ pn => 2, });
$tmplVar = $df->getListTemplateVars({});
is @{ $tmplVar->{record_loop} }, 7, '7 entries in the 2nd page';
#vim:ft=perl

View file

@ -25,7 +25,7 @@ use Data::Dumper;
my $session = WebGUI::Test->session;
plan tests => 26; # increment this value for each test you create
plan tests => 32; # increment this value for each test you create
my $startingRowNum = 0;
my $endingRowNum = 99;
@ -107,6 +107,12 @@ is('100', $p->getPage(5), '(101) page 5 stringification okay');
is($p->getPageNumber, 1, 'Default page number is 1'); ##Additional page numbers are specified at instantiation
########################################################################
#
# getPageLinks with limits
#
########################################################################
$expectedPages = [ map { +{
'pagination.text' => ( $_ + 1 ),
'pagination.range' => ( 25 * $_ + 1 ) . "-" . ( $_ * 25 + 25 <= $endingRowNum + 1 ? $_ * 25 + 25 : $endingRowNum + 1 ), # First row number - Last row number
@ -115,12 +121,6 @@ $expectedPages = [ map { +{
$expectedPages->[0]->{'pagination.activePage'} = 'true';
########################################################################
#
# getPageLinks with limits
#
########################################################################
cmp_deeply(
($p->getPageLinks)[0],
$expectedPages,
@ -217,3 +217,65 @@ cmp_deeply(
\@pageWindow,
'set of last 10 pages selected correctly, (20/20)',
);
########################################################################
#
# iterator based paginator
#
########################################################################
my $callback = sub {
my ($start, $rowsPerPage) = @_;
my $state = $start * 2;
my $counter = 0;
my $iterator = sub {
return 50 if $_[0] eq 'rowCount';
return if ($counter >= $rowsPerPage);
$state += 2;
++$counter;
return if $state > 50;
return $state;
};
return $iterator;
};
my $p1 = WebGUI::Paginator->new($session, '/neighborhood', 5);
$p1->setDataByCallback($callback);
my $pIterator = $p1->getPageIterator;
isa_ok($pIterator, 'CODE', 'getPageIterator');
is($pIterator->('rowCount'), 50, 'generated iterator returns the correct maximum number of rows');
is($p1->getNumberOfPages, 10, 'getNumberOfPages works with an iterator');
cmp_deeply(drainIterator($pIterator, 10), [2, 4, 6, 8, 10], 'setDataByCallback: iterator returned page 1 data');
$p1->setPageNumber(2);
$p1->setDataByCallback($callback);
$pIterator = $p1->getPageIterator;
cmp_deeply(drainIterator($pIterator, 10), [12, 14, 16, 18, 20], '... iterator returned page 2 data');
$expectedPages = [ map { +{
'pagination.text' => ( $_ + 1 ),
'pagination.range' => ( 5 * $_ + 1 ) . "-" . ( ($_+1) * 5 ), # First row number - Last row number
'pagination.url' => ( $_ != 1 ? '/neighborhood' . '?pn=' . ( $_ + 1 ) : '' ), # Current page has no URL
} } (0..9) ];
$expectedPages->[1]->{'pagination.activePage'} = 'true';
cmp_deeply(
($p1->getPageLinks())[0],
$expectedPages,
'getPageLinks works with a paginator'
);
sub drainIterator {
my $iterator = shift;
my $terminalCount = shift;
my $pageData = [];
my $infiniteLoopCount = 0;
while (defined(my $item = $pIterator->())) {
push @{ $pageData }, $item;
last if ++$infiniteLoopCount >= $terminalCount;
}
return $pageData;
}