Fix Search results for Threads when useContainers=1

This commit is contained in:
Colin Kuskie 2010-02-25 08:59:33 -08:00
parent 25aad27cdb
commit 3a054b4895
7 changed files with 106 additions and 19 deletions

View file

@ -13,6 +13,7 @@
- fixed #11436: Inbox invitation use mail send instead of mail queue
- fixed #11385: Wrong user in onCompletePurchase
- fixed #11435: Invitation mail uses wrong mail 'from' header
- fixed #11440: Search for thread with containers
7.8.12
- fixed #11285: Pasting HTML into Code Editor in IE

View file

@ -497,13 +497,13 @@ sub getDeleteUrl {
#-------------------------------------------------------------------
=head2 getDirectLinkUrl ( )
=head2 getThreadLinkUrl ( )
Returns the URL for this Post, which links directly to its anchor and page.
=cut
sub getDirectLinkUrl {
sub getThreadLinkUrl {
my $self = shift;
my $url;
my $page_size = $self->getThread->getParent->get('postsPerPage');

View file

@ -340,15 +340,39 @@ sub getAutoCommitWorkflowId {
#-------------------------------------------------------------------
=head2 getDirectLinkUrl ( )
=head2 getCSLinkUrl ( )
This URL links to the page of the CS containing this thread, similar
to the getThreadLink for the Post. It does not contain the gateway
for the site.
=cut
sub getCSLinkUrl {
my $self = shift;
my $url;
my $cs = $self->getParent;
my $page_size = $cs->get('threadsPerPage');
my $place = $self->getRank+1;
my $last_place = $cs->getLastChild->getRank+1;
my $page = int(($last_place - $place)/$page_size) + 1;
my $page_frag = 'pn='.$page.';sortBy=lineage;sortOrder=desc';
$url = $self->session->url->append($cs->get('url'), $page_frag);
return $url;
}
#-------------------------------------------------------------------
=head2 getThreadLinkUrl ( )
Extend the base method from Post to remove the pagination query fragment
=cut
sub getDirectLinkUrl {
sub getThreadLinkUrl {
my $self = shift;
my $url = $self->SUPER::getDirectLinkUrl();
my $url = $self->SUPER::getThreadLinkUrl();
$url =~ s/\?pn=\d+//;
if ($url =~ m{;revision=\d+}) {
$url =~ s/;revision/?revision/;

View file

@ -130,7 +130,7 @@ sub appendPostListTemplateVars {
if ($self->get("displayLastReply")) {
my $lastPost = $post->getLastPost();
%lastReply = (
"lastReply.url" => $lastPost->getDirectLinkUrl,
"lastReply.url" => $lastPost->getThreadLinkUrl,
"lastReply.title" => $lastPost->get("title"),
"lastReply.user.isVisitor" => $lastPost->get("ownerUserId") eq "1",
"lastReply.username" => $lastPost->get("username"),
@ -145,7 +145,7 @@ sub appendPostListTemplateVars {
my %postVars = (
%{$post->get},
"id" => $post->getId,
"url" => $post->getDirectLinkUrl,
"url" => $post->getThreadLinkUrl,
rating_loop => \@rating_loop,
"content" => $post->formatContent,
"status" => $post->getStatus,
@ -1161,10 +1161,14 @@ Collaboration System
sub getThreadsPaginator {
my $self = shift;
my $scratchSortBy = $self->getId."_sortBy";
my $scratchSortBy = $self->getId."_sortBy";
my $scratchSortOrder = $self->getId."_sortDir";
my $sortBy = $self->session->form->process("sortBy") || $self->session->scratch->get($scratchSortBy) || $self->get("sortBy");
my $sortOrder = $self->session->scratch->get($scratchSortOrder) || $self->get("sortOrder");
my $sortBy = $self->session->form->process("sortBy")
|| $self->session->scratch->get($scratchSortBy)
|| $self->get("sortBy");
my $sortOrder = $self->session->form->process("sortOrder")
|| $self->session->scratch->get($scratchSortOrder)
|| $self->get("sortOrder");
if ($sortBy ne $self->session->scratch->get($scratchSortBy) && $self->session->form->process("func") ne "editSave") {
$self->session->scratch->set($scratchSortBy,$self->session->form->process("sortBy"));
$self->session->scratch->set($scratchSortOrder, $sortOrder);

View file

@ -220,7 +220,8 @@ sub view {
if (defined $asset) {
my $properties = $asset->get;
if ($self->get("useContainers")) {
$properties->{url} = $asset->getContainer->get("url");
$properties->{url} = $asset->isa('WebGUI::Asset::Post::Thread') ? $asset->getCSLinkUrl()
: $asset->getContainer->get("url");
}
#Add highlighting
$properties->{'title' } = $hl->highlight($properties->{title} || '');

View file

@ -13,7 +13,7 @@ use strict;
use lib "$FindBin::Bin/../../lib";
use WebGUI::Test;
use WebGUI::Session;
use Test::More tests => 5; # increment this value for each test you create
use Test::More tests => 9; # increment this value for each test you create
use Test::MockObject::Extends;
use WebGUI::Asset::Wobject::Collaboration;
use WebGUI::Asset::Post::Thread;
@ -30,7 +30,12 @@ addToCleanup($versionTag);
# Need to create a Collaboration system in which the post lives.
my @addArgs = ( undef, undef, { skipAutoCommitWorkflows => 1, skipNotification => 1 } );
my $collab = $node->addChild({className => 'WebGUI::Asset::Wobject::Collaboration', editTimeout => '1'}, @addArgs);
my $collab = $node->addChild({
className => 'WebGUI::Asset::Wobject::Collaboration',
editTimeout => '1',
threadsPerPage => 3,
},
@addArgs);
# finally, add the post to the collaboration system
@ -63,8 +68,19 @@ $thread->rate(1);
$thread->trash;
is($thread->get('threadRating'), 0, 'trash does not die, and updates the threadRating to 0');
unlike $thread->getDirectLinkUrl, qr/\?pn=\d+/, 'threads do not need pagination url query fragments';
unlike $uncommittedThread->getDirectLinkUrl, qr/\?pn=\d+/, 'uncommitted threads, too';
like $uncommittedThread->getDirectLinkUrl, qr/\?revision=\d+/, 'uncommitted threads do have a revision query param';
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';
note 'getCSLinkUrl';
my @newThreads;
push @newThreads, $collab->addChild($props, @addArgs);
push @newThreads, $collab->addChild($props, @addArgs);
my $csUrl = $collab->get('url');
like $newThreads[-1]->getCSLinkUrl, qr/^$csUrl/, 'getCsLinkUrl returns URL of the parent CS with no gateway';
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';
# vim: syntax=perl filetype=perl

View file

@ -16,14 +16,15 @@ 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::Deep;
use WebGUI::Asset::Wobject::Search;
use Data::Dumper;
my $session = WebGUI::Test->session;
# Do our work in the import node
my $node = WebGUI::Asset->getImportNode($session);
my $node = WebGUI::Asset->getDefault($session);
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"Search Test"});
@ -85,10 +86,50 @@ $search->update({
ok(! $@, 'view did now error out on prefix regexp wildcard')
or diag $@;
WebGUI::Test->unmockAssetId($templateId);
$session->request->setup_body({});
}
$session->request->setup_body({});
{
my $versionTag2 = WebGUI::VersionTag->getWorking($session);
$versionTag2->set({name=>"Collab setup"});
my @addArgs = ( undef, undef, { skipAutoCommitWorkflows => 1, skipNotification => 1 } );
my $collab = $node->addChild({
className => 'WebGUI::Asset::Wobject::Collaboration',
editTimeout => '1',
threadsPerPage => 3,
},
@addArgs);
# finally, add the post to the collaboration system
my $props = {
className => 'WebGUI::Asset::Post::Thread',
content => 'verbosity shale anything',
ownerUserId => 1,
};
my $thread = $collab->addChild($props, @addArgs);
$versionTag2->commit();
addToCleanup($versionTag2);
$session->request->setup_body({
doit => 1,
keywords => 'shale',
});
WebGUI::Test->mockAssetId($templateId, $templateMock);
$search->prepareView;
$search->view;
$search->update({useContainers => 0});
unlike $templateVars->{result_set}->[0]->{url}, qr{\?pn=\d}, 'search returns regular URL for a Thread';
$search->update({useContainers => 1});
$search->view;
like $templateVars->{result_set}->[0]->{url}, qr{\?pn=\d}, 'search returns paginated URL for a Thread when useContainers=1';
diag Dumper $templateVars;
WebGUI::Test->unmockAssetId($templateId);
$session->request->setup_body({});
$search->update({useContainers => 0});
}
TODO: {
local $TODO = "Tests to make later";