From 21e321012cfb97ddf43a57a9db03b91dd488af00 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Wed, 10 Mar 2010 09:45:37 -0800 Subject: [PATCH] Fix direct linking to posts and threads when their pagination is set to 0. Fixes bug #11464. --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Asset/Post.pm | 3 ++- lib/WebGUI/Asset/Post/Thread.pm | 3 ++- t/Asset/Post/Thread.t | 8 +++++++- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 888455dcb..6f0318f76 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,4 +1,5 @@ 7.9.1 + - fixed #11464: blank page after setting posts per page in Collaboration System to 0 (zero) 7.9.0 - added #11383: AJAX username checks at registration (Luke Robinson / Orchard Solutions) diff --git a/lib/WebGUI/Asset/Post.pm b/lib/WebGUI/Asset/Post.pm index 51c791b03..eb943969b 100644 --- a/lib/WebGUI/Asset/Post.pm +++ b/lib/WebGUI/Asset/Post.pm @@ -506,7 +506,8 @@ Returns the URL for this Post, which links directly to its anchor and page. sub getThreadLinkUrl { my $self = shift; my $url; - my $page_size = $self->getThread->getParent->get('postsPerPage'); + my $paginator = WebGUI::Paginator->new($self->session, '', $self->getThread->getParent->get('postsPerPage')); + my $page_size = $paginator->{_rpp}; ##To make sure defaults are handled correctly. my $place = $self->getRank+1; my $page = int($place/$page_size) + 1; my $page_frag = 'pn='.$page; diff --git a/lib/WebGUI/Asset/Post/Thread.pm b/lib/WebGUI/Asset/Post/Thread.pm index 809fa5e0f..da98b3966 100644 --- a/lib/WebGUI/Asset/Post/Thread.pm +++ b/lib/WebGUI/Asset/Post/Thread.pm @@ -352,7 +352,8 @@ sub getCSLinkUrl { my $self = shift; my $url; my $cs = $self->getParent; - my $page_size = $cs->get('threadsPerPage'); + my $paginator = WebGUI::Paginator->new($self->session, '', $self->getParent->get('threadsPerPage')); + my $page_size = $paginator->{_rpp}; ##To make sure defaults are handled correctly. my $place = $self->getRank+1; my $last_place = $cs->getLastChild->getRank+1; my $page = int(($last_place - $place)/$page_size) + 1; diff --git a/t/Asset/Post/Thread.t b/t/Asset/Post/Thread.t index 91173fc67..3a6705bf2 100644 --- a/t/Asset/Post/Thread.t +++ b/t/Asset/Post/Thread.t @@ -13,8 +13,9 @@ use strict; use lib "$FindBin::Bin/../../lib"; use WebGUI::Test; use WebGUI::Session; -use Test::More tests => 9; # increment this value for each test you create +use Test::More tests => 11; # increment this value for each test you create use Test::MockObject::Extends; +use Test::Exception; use WebGUI::Asset::Wobject::Collaboration; use WebGUI::Asset::Post::Thread; @@ -72,6 +73,9 @@ note 'getThreadLinkUrl'; unlike $thread->getThreadLinkUrl, qr/\?pn=\d+/, 'threads do not need pagination url query fragments'; unlike $uncommittedThread->getThreadLinkUrl, qr/\?pn=\d+/, 'uncommitted threads, too'; like $uncommittedThread->getThreadLinkUrl, qr/\?revision=\d+/, 'uncommitted threads do have a revision query param'; +$collab->update({threadsPerPage => 0, postsPerPage => 0,}); +lives_ok { $uncommittedThread->getThreadLinkUrl } '... works when pagination set to 0'; +$collab->update({threadsPerPage => 3, postsPerPage => 10,}); note 'getCSLinkUrl'; my @newThreads; @@ -82,5 +86,7 @@ like $newThreads[-1]->getCSLinkUrl, qr/^$csUrl/, 'getCsLinkUrl returns URL of th like $newThreads[-1]->getCSLinkUrl, qr/\?pn=1/, 'and has the right page number'; like $newThreads[-1]->getCSLinkUrl, qr/\?pn=1;sortBy=lineage;sortOrder=desc/, 'and has the right sort parameters'; like $thread->getCSLinkUrl, qr/\?pn=2/, 'checking 2nd thread on another page'; +$collab->update({threadsPerPage => 0, postsPerPage => 0,}); +lives_ok { $uncommittedThread->getCSLinkUrl } '... works when pagination set to 0'; # vim: syntax=perl filetype=perl