From 2a40ab2e6ce475b9aea987f1babba41c4e7f293a Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 24 Nov 2008 02:23:48 +0000 Subject: [PATCH] Document the newly added pagination template variable. Update the tests to look for it and test it --- lib/WebGUI/Help/WebGUI.pm | 6 +++--- lib/WebGUI/i18n/English/WebGUI.pm | 5 +++++ t/Paginator.t | 31 +++++++++++++++++++------------ 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/lib/WebGUI/Help/WebGUI.pm b/lib/WebGUI/Help/WebGUI.pm index bbe661474..757a6c8ca 100644 --- a/lib/WebGUI/Help/WebGUI.pm +++ b/lib/WebGUI/Help/WebGUI.pm @@ -34,15 +34,15 @@ our $HELP = { { 'name' => 'pagination.pageCount.isMultiple' }, { 'name' => 'pagination.pageList', }, { 'name' => 'pagination.pageLoop', - 'variables' => [ { 'name' => 'pagination.url' }, { 'name' => 'pagination.text' }, { 'name' => 'pagination.range' } ] + 'variables' => [ { 'name' => 'pagination.url' }, { 'name' => 'pagination.text' }, { 'name' => 'pagination.range' }, { 'name' => 'pagination.activePage' }, ] }, { 'name' => 'pagination.pageList.upTo20' }, { 'name' => 'pagination.pageLoop.upTo20', - 'variables' => [ { 'name' => 'pagination.url' }, { 'name' => 'pagination.text' }, { 'name' => 'pagination.range' } ] + 'variables' => [ { 'name' => 'pagination.url' }, { 'name' => 'pagination.text' }, { 'name' => 'pagination.range' }, { 'name' => 'pagination.activePage' }, ] }, { 'name' => 'pagination.pageList.upTo10' }, { 'name' => 'pagination.pageLoop.upTo10', - 'variables' => [ { 'name' => 'pagination.url' }, { 'name' => 'pagination.text' }, { 'name' => 'pagination.range' } ] + 'variables' => [ { 'name' => 'pagination.url' }, { 'name' => 'pagination.text' }, { 'name' => 'pagination.range' }, { 'name' => 'pagination.activePage' }, ] } ], fields => [], diff --git a/lib/WebGUI/i18n/English/WebGUI.pm b/lib/WebGUI/i18n/English/WebGUI.pm index eb9b2e2c7..5bc022609 100755 --- a/lib/WebGUI/i18n/English/WebGUI.pm +++ b/lib/WebGUI/i18n/English/WebGUI.pm @@ -2112,6 +2112,11 @@ This group could then be named "Employees in HMO 1", and would allow you to rest lastUpdated => 1220541683, }, + 'pagination.activePage' => { + message => q|A boolean which will be true if the this page in the pageLoop is the currently viewed page.|, + lastUpdated => 1227493265, + }, + 'pagination.pageList.upTo20' => { message => q|A list of links to the 20 nearest in the paginator relative to the current page. So if you're on page 60, you'll see links for 50-70.|, lastUpdated => 1149182026, diff --git a/t/Paginator.t b/t/Paginator.t index 34692b67e..4cef079d0 100644 --- a/t/Paginator.t +++ b/t/Paginator.t @@ -48,18 +48,22 @@ cmp_bag([25..49], $p->getPageData(2), 'page 2 data correct'); cmp_bag([ ], $p->getPageData(5), 'page 5 data correct'); # Test getPageLinks -cmp_deeply( - [ - map { +{ +my $expectedPages; +$expectedPages = [ map { +{ 'pagination.text' => ( $_ + 1 ), 'pagination.range' => ( 25 * $_ + 1 ) . "-" . ( $_ * 25 + 25 <= $endingRowNum + 1 ? $_ * 25 + 25 : $endingRowNum + 1 ), # First row number - Last row number 'pagination.url' => ( $_ != 0 ? $url . '?pn=' . ( $_ + 1 ) : '' ), # Current page has no URL - } } (0..$NumberOfPages-1) - ], + } } (0..$NumberOfPages-1) ]; + +$expectedPages->[0]->{'pagination.activePage'} = 'true'; + +cmp_deeply( ($p->getPageLinks)[0], + $expectedPages, 'page links correct', ); + $startingRowNum = 0; $endingRowNum = 100; @paginatingData = ($startingRowNum..$endingRowNum); @@ -83,16 +87,19 @@ 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 -# Test getPageLinks -cmp_deeply( - ($p->getPageLinks)[0], - [ - map { +{ +$expectedPages = [ map { +{ 'pagination.text' => ( $_ + 1 ), 'pagination.range' => ( 25 * $_ + 1 ) . "-" . ( $_ * 25 + 25 <= $endingRowNum + 1 ? $_ * 25 + 25 : $endingRowNum + 1 ), # First row number - Last row number 'pagination.url' => ( $_ != 0 ? $url . '?pn=' . ( $_ + 1 ) : '' ), # Current page has no URL - } } (0..$NumberOfPages-1) - ], + } } (0..$NumberOfPages-1) ]; + +$expectedPages->[0]->{'pagination.activePage'} = 'true'; + + +# Test getPageLinks +cmp_deeply( + ($p->getPageLinks)[0], + $expectedPages, 'page links correct', );