Skip to content

Commit

Permalink
Allow the default Search root to be overridden by a form variable. Ad…
Browse files Browse the repository at this point in the history
…ds RFE #11460.
  • Loading branch information
perlDreamer committed Mar 9, 2010
1 parent 35492ca commit 8f95101
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/changelog/7.x.x.txt
Expand Up @@ -11,6 +11,7 @@
- fixed #11453: fileUpload.pl does not handle files with spaces, overwriting
- fixed #11458: Use packed template removes wanted whitespace
- fixed #11459: "default template" warning after upgrade to 7.8.14
- added #11460: Override the search root asset. (United Knowledge)

7.8.13
- fixed #11418: confusing typ-o in gotcha
Expand Down
6 changes: 5 additions & 1 deletion lib/WebGUI/Asset/Wobject/Search.pm
Expand Up @@ -181,13 +181,17 @@ sub view {
value=>$keywords
});
$var{'no_results' } = $i18n->get("no results");
my $searchRoot = $self->getValue('searchRoot');
if (my $searchOverride = $form->get('searchroot', 'asset')) {
$searchRoot = $searchOverride;
}

if ($form->get("doit")) {
my $search = WebGUI::Search->new($session);
my %rules = (
keywords =>$keywords,
lineage =>[
WebGUI::Asset->newByDynamicClass($session,$self->getValue("searchRoot"))->get("lineage")
WebGUI::Asset->newByDynamicClass($session, $searchRoot)->get("lineage"),
],
);
my @classes = split("\n",$self->get("classLimiter"));
Expand Down
74 changes: 74 additions & 0 deletions t/Asset/Wobject/Search/searchroot.t
@@ -0,0 +1,74 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------

use FindBin;
use strict;
use JSON qw/from_json/;
use lib "$FindBin::Bin/../../../lib";

##The goal of this test is to test the creation of Search Wobjects.

use WebGUI::Test;
use WebGUI::Session;
use Test::More tests => 2; # increment this value for each test you create
use Test::Deep;
use WebGUI::Asset::Wobject::Search;

my $session = WebGUI::Test->session;
$session->user({userId => 3});

# Do our work in the import node
my $node = WebGUI::Asset->getImportNode($session);


my $default = WebGUI::Asset->getDefault($session);
my $importArticle = $node->addChild({
className => 'WebGUI::Asset::Wobject::Article',
description => 'rockhound',
});
my $defaultArticle = $default->addChild({
className => 'WebGUI::Asset::Wobject::Article',
description => 'rockhound',
});
my $template = $node->addChild({
className => 'WebGUI::Asset::Template',
template => qq{[<tmpl_loop result_set>"<tmpl_var assetId>"<tmpl_unless __LAST__>,</tmpl_unless></tmpl_loop>]},
});
my $search = $default->addChild({
className => 'WebGUI::Asset::Wobject::Search',
searchRoot => $default->getId,
templateId => $template->getId,
});
my $tag2 = WebGUI::VersionTag->getWorking($session);
$tag2->commit;

$search->prepareView();
$session->request->setup_body({doit => 1, keywords => 'rockhound'});
my $json = $search->view();
my $assetIds = from_json($json);
cmp_deeply(
$assetIds,
[ $defaultArticle->getId ],
'search with no override returns asset from default asset'
);

$session->request->setup_body({doit => 1, keywords => 'rockhound', searchroot => $node->getId,});
$json = $search->view();
$assetIds = from_json($json);
cmp_deeply(
$assetIds,
[ $importArticle->getId ],
'search with override returns asset from import node'
);


$session->request->setup_body({});
$tag2->rollback;

0 comments on commit 8f95101

Please sign in to comment.