From 797f5f93638ae97141ab4f4dc6b376eca7973d94 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Wed, 10 Jan 2007 03:03:31 +0000 Subject: [PATCH] Add a test to Utility.t to make sure that WebGUI::Utility::round also rounds up. Add Paginator tests for paginating array data. Fix an off by 1 error in the Paginator when handling array data. SQL data is fine. --- docs/changelog/7.x.x.txt | 4 +++- lib/WebGUI/Paginator.pm | 2 +- t/Paginator.t | 34 +++++++++++++++++++++++++++++----- t/Utility.t | 3 ++- 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 034f15669..5576f370e 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -20,7 +20,9 @@ - fix: Styles were printing double head block headers. - fix: DB slaves were not being instanciated correctly. (thx Chris Palamara) - + - fix: Paginator: addDataByArrayRef off by one error (perlDreamer Consulting + LLC) + 7.3.3 - fix: Wiki Purge throws fatal - fix: Calendar now reports proper product ID on iCal feed diff --git a/lib/WebGUI/Paginator.pm b/lib/WebGUI/Paginator.pm index cd212adc3..c4599597e 100644 --- a/lib/WebGUI/Paginator.pm +++ b/lib/WebGUI/Paginator.pm @@ -527,7 +527,7 @@ sub setDataByArrayRef { my $self = shift; my $rowRef = shift; $self->{_rowRef} = $rowRef; - $self->{_totalRows} = $#{$rowRef}; + $self->{_totalRows} = $#{$rowRef} + 1; } diff --git a/t/Paginator.t b/t/Paginator.t index 7f28ed128..52f58b24d 100644 --- a/t/Paginator.t +++ b/t/Paginator.t @@ -17,14 +17,38 @@ use WebGUI::Session; use WebGUI::Utility; use WebGUI::Paginator; -use Test::More tests => 1; # increment this value for each test you create +use Test::More; # increment this value for each test you create +use Test::Deep; +use POSIX qw(ceil); my $session = WebGUI::Test->session; -my $p = WebGUI::Paginator->new($session, '/home', '', '', 1); +my $startingRowNum = 0; +my $endingRowNum = 100; -$p->setDataByQuery('select * from settings'); +my @paginatingData = $startingRowNum .. $endingRowNum; -my $settingspage = $p->getPageData; +plan tests => 6; # increment this value for each test you create -is(1,1,"a test"); +my $rowCount = $endingRowNum - $startingRowNum + 1; +my $NumberOfPages = ceil($rowCount/25); ##Default page size=25 + +my $p = WebGUI::Paginator->new($session, '/home'); + +isa_ok($p, 'WebGUI::Paginator', 'paginator object returned'); + +$p->setDataByArrayRef(\@paginatingData); + +is($p->getRowCount, $rowCount, 'all data returned by paginator'); +is($p->getNumberOfPages, $NumberOfPages, 'paginator returns right number of pages (default setting)'); + +my $page1Data = $p->getPageData(1); +cmp_bag([0..24], $page1Data, 'page 1 data correct'); + +use Data::Dumper; + +my $page2Data = $p->getPageData(2); +cmp_bag([25..49], $page2Data, 'page 2 data correct'); + +my $page5Data = $p->getPageData(5); +cmp_bag([100], $page5Data, 'page 5 data correct'); diff --git a/t/Utility.t b/t/Utility.t index 58e930f22..9543fcd52 100644 --- a/t/Utility.t +++ b/t/Utility.t @@ -17,7 +17,7 @@ use Tie::IxHash; use WebGUI::Test; use WebGUI::Session; -use Test::More tests => 21; # increment this value for each test you create +use Test::More tests => 22; # increment this value for each test you create my $session = WebGUI::Test->session; @@ -74,6 +74,7 @@ SKIP: { # round is(WebGUI::Utility::round(47.133984233, 0), 47, 'round() - 0 significant digits'); is(WebGUI::Utility::round(47.133984233, 3), 47.134, 'round() - multiple significant digits'); +is(WebGUI::Utility::round(47.6, 0), 48, 'round() - rounds up, too'); { # Just some basic tests for now.