Merge commit 'v7.10.15' into 8
Conflicts: docs/gotcha.txt docs/previousVersion.sql docs/templates.txt lib/WebGUI.pm lib/WebGUI/Asset.pm lib/WebGUI/Asset/Event.pm lib/WebGUI/Asset/File.pm lib/WebGUI/Asset/MapPoint.pm lib/WebGUI/Asset/RichEdit.pm lib/WebGUI/Asset/Sku/Product.pm lib/WebGUI/Asset/Snippet.pm lib/WebGUI/Asset/Story.pm lib/WebGUI/Asset/Template.pm lib/WebGUI/Asset/Template/TemplateToolkit.pm lib/WebGUI/Asset/Wobject/Calendar.pm lib/WebGUI/Asset/Wobject/Carousel.pm lib/WebGUI/Asset/Wobject/Collaboration.pm lib/WebGUI/Asset/Wobject/Dashboard.pm lib/WebGUI/Asset/Wobject/DataForm.pm lib/WebGUI/Asset/Wobject/Folder.pm lib/WebGUI/Asset/Wobject/Map.pm lib/WebGUI/Asset/Wobject/Search.pm lib/WebGUI/Asset/Wobject/Shelf.pm lib/WebGUI/Asset/Wobject/StockData.pm lib/WebGUI/Asset/Wobject/StoryTopic.pm lib/WebGUI/Asset/Wobject/SyndicatedContent.pm lib/WebGUI/Asset/Wobject/Thingy.pm lib/WebGUI/Asset/Wobject/WeatherData.pm lib/WebGUI/AssetClipboard.pm lib/WebGUI/AssetCollateral/DataForm/Entry.pm lib/WebGUI/AssetExportHtml.pm lib/WebGUI/AssetLineage.pm lib/WebGUI/AssetMetaData.pm lib/WebGUI/AssetTrash.pm lib/WebGUI/AssetVersioning.pm lib/WebGUI/Auth.pm lib/WebGUI/Cache/CHI.pm lib/WebGUI/Content/AssetManager.pm lib/WebGUI/Fork/ProgressBar.pm lib/WebGUI/Form/JsonTable.pm lib/WebGUI/Form/TimeField.pm lib/WebGUI/Form/Zipcode.pm lib/WebGUI/Group.pm lib/WebGUI/International.pm lib/WebGUI/Macro/AssetProxy.pm lib/WebGUI/Macro/FileUrl.pm lib/WebGUI/Operation/SSO.pm lib/WebGUI/Operation/User.pm lib/WebGUI/Role/Asset/Subscribable.pm lib/WebGUI/Shop/Cart.pm lib/WebGUI/Shop/Transaction.pm lib/WebGUI/Shop/TransactionItem.pm lib/WebGUI/Test.pm lib/WebGUI/URL/Content.pm lib/WebGUI/URL/Uploads.pm lib/WebGUI/User.pm lib/WebGUI/Workflow/Activity/ExtendCalendarRecurrences.pm lib/WebGUI/Workflow/Activity/SendNewsletters.pm lib/WebGUI/i18n/English/Asset.pm lib/WebGUI/i18n/English/WebGUI.pm sbin/installClass.pl sbin/rebuildLineage.pl sbin/search.pl sbin/testEnvironment.pl t/Asset/Asset.t t/Asset/AssetClipboard.t t/Asset/AssetLineage.t t/Asset/AssetMetaData.t t/Asset/Event.t t/Asset/File.t t/Asset/File/Image.t t/Asset/Post/notification.t t/Asset/Sku.t t/Asset/Story.t t/Asset/Template.t t/Asset/Wobject/Collaboration/templateVariables.t t/Asset/Wobject/Collaboration/unarchiveAll.t t/Asset/Wobject/Shelf.t t/Auth.t t/Macro/EditableToggle.t t/Macro/FilePump.t t/Shop/Cart.t t/Shop/Transaction.t t/Storage.t t/User.t t/Workflow.t
This commit is contained in:
commit
277faae8a1
783 changed files with 32041 additions and 25495 deletions
|
|
@ -93,12 +93,7 @@ is ($duplicateFilename, $filename, "duplicate method copies collateral");
|
|||
$duplicateArticle->purge();
|
||||
|
||||
# The get method will create the directory if it doesnt exist... very strange.
|
||||
$duplicateStorage = WebGUI::Storage->get($session,$duplicateStorageId);
|
||||
|
||||
# so lets check for the file instead
|
||||
$duplicateFilename = $duplicateStorage->getFiles->[0];
|
||||
|
||||
is ($duplicateFilename, undef, 'purge method deletes collateral');
|
||||
ok (!WebGUI::Storage->storageExists($session, $duplicateStorageId), 'purge method deletes collateral');
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,9 +18,6 @@ use WebGUI::Session;
|
|||
use Test::More tests => 1; # increment this value for each test you create
|
||||
use Test::Deep;
|
||||
|
||||
my $one = [1, 2, 3, 4];
|
||||
my @two = ();
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
my $dataFormIds = $session->db->buildArrayRef("select asset.assetId, assetData.revisionDate from DataForm left join asset on asset.assetId=DataForm.assetId left join assetData on assetData.revisionDate=DataForm.revisionDate and assetData.assetId=DataForm.assetId where asset.state='published' and assetData.revisionDate=(SELECT max(revisionDate) from assetData where assetData.assetId=asset.assetId and (assetData.status='approved' or assetData.tagId=?)) order by assetData.title");
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ my @fields = (
|
|||
# Test the field_loop
|
||||
my $fieldVars = [];
|
||||
for my $field ( @fields ) {
|
||||
my $var = {};
|
||||
my $var = { 'field.controls' => ignore() };
|
||||
for my $key ( keys %$field ) {
|
||||
$var->{ 'field.' . $key } = $field->{ $key };
|
||||
}
|
||||
|
|
|
|||
67
t/Asset/Wobject/Folder.t
Normal file
67
t/Asset/Wobject/Folder.t
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
#-------------------------------------------------------------------
|
||||
# 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 File::Spec;
|
||||
use lib "$FindBin::Bin/../../lib";
|
||||
|
||||
use Test::MockTime qw/:all/; ##Must be loaded before all other code
|
||||
use WebGUI::Test;
|
||||
use WebGUI::Session;
|
||||
use Test::More tests => 3; # increment this value for each test you create
|
||||
use WebGUI::Asset::Wobject::Folder;
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
# Do our work in the import node
|
||||
my $node = WebGUI::Asset->getImportNode($session);
|
||||
|
||||
################################################################
|
||||
#
|
||||
# getContentLastModifiedBy
|
||||
#
|
||||
################################################################
|
||||
|
||||
my $revised_user1 = WebGUI::User->new($session, 'new');
|
||||
my $revised_user2 = WebGUI::User->new($session, 'new');
|
||||
WebGUI::Test->addToCleanup($revised_user1, $revised_user2 );
|
||||
$session->user({userId => 3});
|
||||
set_relative_time(-600);
|
||||
WebGUI::Test->addToCleanup(sub { restore_time(); });
|
||||
my $versionTag = WebGUI::VersionTag->getWorking($session);
|
||||
my $folder = $node->addChild({
|
||||
className => 'WebGUI::Asset::Wobject::Folder',
|
||||
}, undef, 12);
|
||||
$session->user({user => $revised_user1});
|
||||
my $snip1 = $folder->addChild({
|
||||
className => 'WebGUI::Asset::Snippet',
|
||||
}, undef, 14);
|
||||
|
||||
set_relative_time(-500);
|
||||
$session->user({user => $revised_user2});
|
||||
my $snip2 = $folder->addChild({
|
||||
className => 'WebGUI::Asset::Snippet',
|
||||
}, undef, 16);
|
||||
|
||||
$folder = $folder->cloneFromDb;
|
||||
$snip1 = $snip1->cloneFromDb;
|
||||
$snip2 = $snip2->cloneFromDb;
|
||||
WebGUI::Test->addToCleanup($folder);
|
||||
is $folder->getContentLastModifiedBy, $snip2->get('revisedBy'), 'getContentLastModifiedBy returns revisedBy for most recent child asset';
|
||||
is $folder->getContentLastModifiedBy, $revised_user2->userId, '... real userId check';
|
||||
$session->user({user => $revised_user1});
|
||||
|
||||
set_relative_time(-100);
|
||||
|
||||
$snip1 = $snip1->addRevision({ title => 'titular', }, 18);
|
||||
is $folder->getContentLastModifiedBy, $revised_user1->userId, '... check that a new revision tracks';
|
||||
|
||||
|
||||
67
t/Asset/Wobject/Layout.t
Normal file
67
t/Asset/Wobject/Layout.t
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
#-------------------------------------------------------------------
|
||||
# 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 File::Spec;
|
||||
use lib "$FindBin::Bin/../../lib";
|
||||
|
||||
use Test::MockTime qw/:all/; ##Must be loaded before all other code
|
||||
use WebGUI::Test;
|
||||
use WebGUI::Session;
|
||||
use Test::More tests => 3; # increment this value for each test you create
|
||||
use WebGUI::Asset::Wobject::Layout;
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
# Do our work in the import node
|
||||
my $node = WebGUI::Asset->getImportNode($session);
|
||||
|
||||
################################################################
|
||||
#
|
||||
# getContentLastModifiedBy
|
||||
#
|
||||
################################################################
|
||||
|
||||
my $revised_user1 = WebGUI::User->new($session, 'new');
|
||||
my $revised_user2 = WebGUI::User->new($session, 'new');
|
||||
WebGUI::Test->addToCleanup($revised_user1, $revised_user2 );
|
||||
$session->user({userId => 3});
|
||||
set_relative_time(-600);
|
||||
WebGUI::Test->addToCleanup(sub { restore_time(); });
|
||||
my $versionTag = WebGUI::VersionTag->getWorking($session);
|
||||
my $page = $node->addChild({
|
||||
className => 'WebGUI::Asset::Wobject::Layout',
|
||||
}, undef, 12);
|
||||
$session->user({user => $revised_user1});
|
||||
my $snip1 = $page->addChild({
|
||||
className => 'WebGUI::Asset::Snippet',
|
||||
}, undef, 14);
|
||||
|
||||
set_relative_time(-500);
|
||||
$session->user({user => $revised_user2});
|
||||
my $snip2 = $page->addChild({
|
||||
className => 'WebGUI::Asset::Snippet',
|
||||
}, undef, 16);
|
||||
|
||||
$page = $page->cloneFromDb;
|
||||
$snip1 = $snip1->cloneFromDb;
|
||||
$snip2 = $snip2->cloneFromDb;
|
||||
WebGUI::Test->addToCleanup($page);
|
||||
is $page->getContentLastModifiedBy, $snip2->get('revisedBy'), 'getContentLastModifiedBy returns revisedBy for most recent child asset';
|
||||
is $page->getContentLastModifiedBy, $revised_user2->userId, '... real userId check';
|
||||
$session->user({user => $revised_user1});
|
||||
|
||||
set_relative_time(-100);
|
||||
|
||||
$snip1 = $snip1->addRevision({ title => 'titular', }, 18);
|
||||
is $page->getContentLastModifiedBy, $revised_user1->userId, '... check that a new revision tracks';
|
||||
|
||||
|
||||
|
|
@ -51,6 +51,7 @@ skip "Unable to load module $class", $tests unless $loaded;
|
|||
my $defaultNode = WebGUI::Test->asset;
|
||||
my $template = $defaultNode->addChild({
|
||||
className => 'WebGUI::Asset::Template',
|
||||
parser => 'WebGUI::Asset::Template::HTMLTemplate',
|
||||
title => 'test poll template',
|
||||
template => q|
|
||||
{
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ use strict;
|
|||
use WebGUI::Test;
|
||||
use WebGUI::Test::MockAsset;
|
||||
use WebGUI::Session;
|
||||
use Test::More tests => 11; # increment this value for each test you create
|
||||
use Test::More tests => 13; # increment this value for each test you create
|
||||
use Test::Deep;
|
||||
use WebGUI::Asset::Wobject::Search;
|
||||
use Data::Dumper;
|
||||
|
|
@ -28,7 +28,7 @@ my $node = WebGUI::Asset->getDefault($session);
|
|||
my $versionTag = WebGUI::VersionTag->getWorking($session);
|
||||
$versionTag->set({name=>"Search Test"});
|
||||
my %tag = ( tagId => $versionTag->getId, status => "pending" );
|
||||
addToCleanup($versionTag);
|
||||
WebGUI::Test->addToCleanup($versionTag);
|
||||
my $search = $node->addChild({className=>'WebGUI::Asset::Wobject::Search', %tag});
|
||||
|
||||
# Test for a sane object type
|
||||
|
|
@ -110,7 +110,7 @@ $search->update({
|
|||
my $thread = $collab->addChild($props, @addArgs);
|
||||
$thread->setSkipNotification;
|
||||
$versionTag2->commit();
|
||||
addToCleanup($versionTag2);
|
||||
WebGUI::Test->addToCleanup($versionTag2);
|
||||
|
||||
$session->request->setup_body({
|
||||
doit => 1,
|
||||
|
|
@ -128,6 +128,49 @@ $search->update({
|
|||
$search->update({useContainers => 0});
|
||||
}
|
||||
|
||||
{
|
||||
# Test useContainers when the user cannot view the container
|
||||
my $versionTag3 = WebGUI::VersionTag->getWorking($session);
|
||||
$versionTag3->set({name=>"Folder setup"});
|
||||
$tag{tagId} = $versionTag3->getId;
|
||||
my @addArgs = ( undef, undef, { skipAutoCommitWorkflows => 1, skipNotification => 1 } );
|
||||
my $folder = $node->addChild({
|
||||
className => 'WebGUI::Asset::Wobject::Folder',
|
||||
groupIdView => '3', # Admins
|
||||
%tag,
|
||||
},
|
||||
@addArgs);
|
||||
# add an article anyone can see
|
||||
my $props = {
|
||||
className => 'WebGUI::Asset::Wobject::Article',
|
||||
synopsis => 'juxtaposition coolwhip cheezewhiz',
|
||||
groupIdView => '7', # Everyone
|
||||
tagId => $versionTag3->getId,
|
||||
status => 'pending',
|
||||
};
|
||||
|
||||
my $snippet = $folder->addChild($props, @addArgs);
|
||||
$versionTag3->commit();
|
||||
WebGUI::Test->addToCleanup($versionTag3);
|
||||
|
||||
$session->request->setup_body({
|
||||
doit => 1,
|
||||
keywords => 'juxtaposition',
|
||||
});
|
||||
WebGUI::Test::MockAsset->mock_id($templateId, $templateMock);
|
||||
$search->prepareView;
|
||||
$search->view;
|
||||
$search->update({useContainers => 0});
|
||||
note( explain $templateVars );
|
||||
is $templateVars->{result_set}->[0]->{url}, $snippet->get('url'), 'search returns regular URL for article';
|
||||
$search->update({useContainers => 1});
|
||||
$search->view;
|
||||
is $templateVars->{result_set}->[0]->{url}, $snippet->get('url'), 'search returns regular URL for article because user cannot see container';
|
||||
|
||||
WebGUI::Test::MockAsset->unmock_id($templateId);
|
||||
$session->request->setup_body({});
|
||||
$search->update({useContainers => 0});
|
||||
}
|
||||
|
||||
TODO: {
|
||||
local $TODO = "Tests to make later";
|
||||
|
|
|
|||
97
t/Asset/Wobject/Search/addRecord.t
Normal file
97
t/Asset/Wobject/Search/addRecord.t
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
#-------------------------------------------------------------------
|
||||
# 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 searching for and returning data about
|
||||
##records created with WebGUI::Search::Index::addRecord;
|
||||
|
||||
use WebGUI::Test;
|
||||
use WebGUI::Session;
|
||||
use Test::More tests => 6; # increment this value for each test you create
|
||||
use Test::Deep;
|
||||
use WebGUI::Test::MockAsset;
|
||||
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::Test->asset;
|
||||
my $importArticle = WebGUI::Test->asset->addChild({
|
||||
className => 'WebGUI::Asset::Wobject::Article',
|
||||
description => 'rockhound',
|
||||
});
|
||||
|
||||
my $templateId = 'SEARCH_ASSET_TEMPLATE_';
|
||||
my $templateMock = Test::MockObject->new({});
|
||||
$templateMock->set_isa('WebGUI::Asset::Template');
|
||||
$templateMock->set_always('getId', $templateId);
|
||||
$templateMock->set_always('prepare', 1);
|
||||
my $templateVars;
|
||||
$templateMock->mock('process', sub { $templateVars = $_[1]; } );
|
||||
|
||||
my $defaultArticle = $default->addChild({
|
||||
className => 'WebGUI::Asset::Wobject::Article',
|
||||
description => 'shawshank prison',
|
||||
url => 'introduction'
|
||||
});
|
||||
$defaultArticle->indexContent;
|
||||
my $search = $default->addChild({
|
||||
className => 'WebGUI::Asset::Wobject::Search',
|
||||
searchRoot => $default->getId,
|
||||
templateId => $templateId,
|
||||
});
|
||||
$search->indexContent;
|
||||
my $indexer = WebGUI::Search::Index->new($defaultArticle);
|
||||
$indexer->addRecord(url => 'brochure', keywords => 'roomy spacious prison');
|
||||
|
||||
{
|
||||
WebGUI::Test::MockAsset->mock_id($templateId, $templateMock);
|
||||
$search->prepareView();
|
||||
$session->request->setup_body({doit => 1, keywords => 'shawshank'});
|
||||
$search->view();
|
||||
WebGUI::Test::MockAsset->unmock_id($templateId);
|
||||
}
|
||||
|
||||
is scalar @{ $templateVars->{result_set} }, 1, 'search for shawshank, returns 1 record';
|
||||
is $templateVars->{result_set}->[0]->{url}, 'introduction', '... url is correct';
|
||||
|
||||
{
|
||||
WebGUI::Test::MockAsset->mock_id($templateId, $templateMock);
|
||||
$search->prepareView();
|
||||
$session->request->setup_body({doit => 1, keywords => 'prison'});
|
||||
$search->view();
|
||||
WebGUI::Test::MockAsset->unmock_id($templateId);
|
||||
}
|
||||
|
||||
is scalar @{ $templateVars->{result_set} }, 2, 'search for prison, returns 2 records';
|
||||
cmp_bag(
|
||||
[ map { $_->{url} } @{ $templateVars->{result_set} } ],
|
||||
[qw/ introduction brochure/ ],
|
||||
'... urls are correct'
|
||||
);
|
||||
cmp_bag(
|
||||
[ map { $_->{groupIdView} } @{ $templateVars->{result_set} } ],
|
||||
[ 7, 7 ],
|
||||
' groupIdViews are correct (2nd record inherits from the parent)'
|
||||
);
|
||||
cmp_bag(
|
||||
[ map { $_->{title_nohighlight} } @{ $templateVars->{result_set} } ],
|
||||
[ ($defaultArticle->get('title'))x2 ],
|
||||
' titles are correct (2nd record inherits from the parent)'
|
||||
);
|
||||
|
||||
|
|
@ -42,6 +42,7 @@ my $defaultArticle = $default->addChild({
|
|||
});
|
||||
my $template = $node->addChild({
|
||||
className => 'WebGUI::Asset::Template',
|
||||
parser => 'WebGUI::Asset::Template::HTMLTemplate',
|
||||
template => qq{[<tmpl_loop result_set>"<tmpl_var assetId>"<tmpl_unless __LAST__>,</tmpl_unless></tmpl_loop>]},
|
||||
%tag,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ SKIP: {
|
|||
|
||||
my $testTemplate = $root->addChild({
|
||||
className => 'WebGUI::Asset::Template',
|
||||
parser => 'WebGUI::Asset::Template::HTMLTemplate',
|
||||
template => q|{ "noViewableSkus":"<tmpl_var noViewableSkus>","emptyShelf":"<tmpl_var emptyShelf>"}|,
|
||||
});
|
||||
my $testShelf = $root->addChild({
|
||||
|
|
|
|||
65
t/Asset/Wobject/StockData.t
Normal file
65
t/Asset/Wobject/StockData.t
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
# vim:syntax=perl
|
||||
#-------------------------------------------------------------------
|
||||
# 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
|
||||
#------------------------------------------------------------------
|
||||
|
||||
# This tests the AssetReport asset
|
||||
#
|
||||
#
|
||||
|
||||
use Test::MockTime qw/:all/;
|
||||
use FindBin;
|
||||
use strict;
|
||||
use lib "$FindBin::Bin/../../lib";
|
||||
use Test::More;
|
||||
use Test::Deep;
|
||||
use JSON;
|
||||
use WebGUI::Test; # Must use this before any other WebGUI modules
|
||||
use WebGUI::Session;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Init
|
||||
my $session = WebGUI::Test->session;
|
||||
my $node = WebGUI::Asset->getImportNode( $session );
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
plan tests => 6; # Increment this number for each test you create
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Asset Report creation
|
||||
my $asset = $node->addChild( {
|
||||
className => 'WebGUI::Asset::Wobject::StockData',
|
||||
source => 'usa',
|
||||
defaultStocks => "GWR",
|
||||
cacheTimeout => 2000,
|
||||
} );
|
||||
WebGUI::Test->addToCleanup($asset);
|
||||
|
||||
my $now = time();
|
||||
set_relative_time(-1000);
|
||||
|
||||
my $stocks = $asset->_getStocks(["GWR"]);
|
||||
is $stocks->{qw/GWR symbol/}, 'GWR', 'stock fetch successful';
|
||||
cmp_ok $stocks->{qw/GWR last_fetch/}, '<', $now-500, 'last_fetch set in the past';
|
||||
my $last_fetch = $stocks->{qw/GWR last_fetch/};
|
||||
|
||||
is $session->cache->get( join "", $asset->getId, 'usa', 'GWR' )->{qw/GWR symbol/},
|
||||
'GWR',
|
||||
'cache loaded with valid data';
|
||||
|
||||
restore_time();
|
||||
|
||||
my $stocks2 = $asset->_getStocks([qw/GWR UNP/]);
|
||||
is $stocks2->{qw/UNP symbol/}, 'UNP', 'stock fetch successful, new stock';
|
||||
is $stocks2->{qw/GWR symbol/}, 'GWR', '... cached stock';
|
||||
is $stocks2->{qw/GWR last_fetch/}, $last_fetch, 'GWR stock lookup was cached';
|
||||
|
||||
#vim:ft=perl
|
||||
|
|
@ -29,15 +29,13 @@ my $session = WebGUI::Test->session;
|
|||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
plan tests => 20;
|
||||
plan tests => 21;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# put your tests here
|
||||
|
||||
my $class = 'WebGUI::Asset::Wobject::StoryTopic';
|
||||
|
||||
my $versionTag = WebGUI::VersionTag->getWorking($session);
|
||||
|
||||
my $archive = WebGUI::Test->asset->addChild({className => 'WebGUI::Asset::Wobject::StoryArchive', title => 'My Stories', url => '/home/mystories'});
|
||||
|
||||
my $now = time();
|
||||
|
|
@ -47,8 +45,6 @@ my $yesterday = $now-24*3600;
|
|||
my $newFolder = $archive->getFolder($yesterday);
|
||||
|
||||
my $creationDateSth = $session->db->prepare('update asset set creationDate=? where assetId=?');
|
||||
$versionTag->commit;
|
||||
WebGUI::Test->addToCleanup($versionTag);
|
||||
|
||||
my $pastStory = $newFolder->addChild({ className => 'WebGUI::Asset::Story', title => "Yesterday is history", keywords => 'andy,norton'});
|
||||
$creationDateSth->execute([$yesterday, $pastStory->getId]);
|
||||
|
|
@ -71,7 +67,6 @@ STORY: foreach my $name (@characters) {
|
|||
|
||||
$storyHandler->{bogs}->update({subtitle => 'drinking his food through a straw'});
|
||||
|
||||
my $topicTag = WebGUI::VersionTag->getWorking($session);
|
||||
my $topic = WebGUI::Test->asset->addChild({
|
||||
className => 'WebGUI::Asset::Wobject::StoryTopic',
|
||||
title => 'Popular inmates in Shawshank Prison',
|
||||
|
|
@ -85,9 +80,6 @@ $topic->update({
|
|||
storiesShort => 3,
|
||||
});
|
||||
|
||||
$topicTag->commit;
|
||||
WebGUI::Test->addToCleanup($topicTag);
|
||||
|
||||
$topic = $topic->cloneFromDb;
|
||||
|
||||
################################################################
|
||||
|
|
@ -96,6 +88,39 @@ $topic = $topic->cloneFromDb;
|
|||
#
|
||||
################################################################
|
||||
|
||||
# When it's okay that the variables we get will have extra keys and
|
||||
# values beyond what we're checking for, we'll use this function.
|
||||
sub cmp_variable_loop {
|
||||
my ($got, $expected, $name) = @_;
|
||||
local $Test::Builder::Level = $Test::Builder::Level + 1;
|
||||
my $sg = @$got;
|
||||
my $se = @$expected;
|
||||
unless (@$got == @$expected) {
|
||||
fail($name);
|
||||
diag(<<EOM);
|
||||
Arrayrefs are not the same length.
|
||||
got : $sg
|
||||
expect : $se
|
||||
EOM
|
||||
return 0;
|
||||
}
|
||||
|
||||
my $failed;
|
||||
for my $i (0..$#$got) {
|
||||
my $g = $got->[$i];
|
||||
my $e = $expected->[$i];
|
||||
my ($ok, $stack) = Test::Deep::cmp_details($g, superhashof($e));
|
||||
unless ($ok) {
|
||||
unless ($failed) {
|
||||
fail($name);
|
||||
$failed = 1;
|
||||
}
|
||||
diag(Test::Deep::deep_diag($stack));
|
||||
}
|
||||
}
|
||||
return $failed ? 0 : pass($name);
|
||||
}
|
||||
|
||||
my $templateVars;
|
||||
$templateVars = $topic->viewTemplateVariables();
|
||||
|
||||
|
|
@ -108,7 +133,7 @@ cmp_deeply(
|
|||
}),
|
||||
'viewTemplateVars: RSS and Atom feed template variables'
|
||||
);
|
||||
cmp_deeply(
|
||||
cmp_variable_loop(
|
||||
$templateVars->{story_loop},
|
||||
[
|
||||
{
|
||||
|
|
@ -126,7 +151,8 @@ cmp_deeply(
|
|||
);
|
||||
|
||||
ok(
|
||||
exists $templateVars->{topStoryTitle}
|
||||
exists $templateVars->{topStory}
|
||||
&& exists $templateVars->{topStoryTitle}
|
||||
&& exists $templateVars->{topStoryUrl}
|
||||
&& exists $templateVars->{topStoryCreationDate}
|
||||
&& exists $templateVars->{topStorySubtitle},
|
||||
|
|
@ -136,7 +162,7 @@ ok(! $templateVars->{standAlone}, 'viewTemplateVars: not in standalone mode');
|
|||
|
||||
$topic->{_standAlone} = 1;
|
||||
$templateVars = $topic->viewTemplateVariables();
|
||||
cmp_deeply(
|
||||
cmp_variable_loop(
|
||||
$templateVars->{story_loop},
|
||||
[
|
||||
{
|
||||
|
|
@ -168,6 +194,13 @@ cmp_deeply(
|
|||
'viewTemplateVars has right number and contents in the story_loop in standalone mode. Top story not present in story_loop'
|
||||
);
|
||||
|
||||
cmp_deeply($templateVars->{topStory}, superhashof({
|
||||
title => 'bogs',
|
||||
subtitle => 'drinking his food through a straw',
|
||||
creationDate => $now,
|
||||
}));
|
||||
|
||||
|
||||
is($templateVars->{topStoryTitle}, 'bogs', '... topStoryTitle');
|
||||
is(
|
||||
$templateVars->{topStorySubtitle},
|
||||
|
|
@ -243,7 +276,7 @@ $topic->update({
|
|||
storiesShort => 3,
|
||||
});
|
||||
$templateVars = $topic->viewTemplateVariables;
|
||||
cmp_deeply(
|
||||
cmp_variable_loop(
|
||||
$templateVars->{story_loop},
|
||||
[
|
||||
{
|
||||
|
|
@ -326,7 +359,7 @@ $topic->update( { storySortOrder => 'Alphabetically' } );
|
|||
|
||||
$templateVars = $topic->viewTemplateVariables();
|
||||
|
||||
cmp_deeply(
|
||||
cmp_variable_loop(
|
||||
[
|
||||
{
|
||||
title => $templateVars->{topStoryTitle},
|
||||
|
|
@ -370,9 +403,7 @@ my $emptyarchive = WebGUI::Test->asset->addChild({
|
|||
url => '/home/badstories',
|
||||
keywords => 'aksjhgkja asgjhshs assajshhsg5',
|
||||
});
|
||||
WebGUI::Test->addToCleanup($emptyarchive); # blows up under the debugger...?
|
||||
|
||||
$versionTag->commit;
|
||||
$emptyarchive->{_standAlone} = 1;
|
||||
ok(eval { $emptyarchive->viewTemplateVariables() }, "viewTemplateVariables with _standAlone = 1 doesn't throw an error");
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ use Data::Dumper;
|
|||
|
||||
use WebGUI::Test;
|
||||
use WebGUI::Session;
|
||||
use Test::More tests => 29; # increment this value for each test you create
|
||||
use Test::More tests => 30; # increment this value for each test you create
|
||||
use Test::Deep;
|
||||
use WebGUI::Asset::Wobject::SyndicatedContent;
|
||||
use XML::FeedPP;
|
||||
|
|
@ -138,7 +138,7 @@ ok( defined $vars->{item_loop}->[0]->{description}, 'getTemplateVariables: descr
|
|||
##Construct a feed with a wrapped description, to check for paragraph handling.
|
||||
$feed = XML::FeedPP->new(<<EOFEED);
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<rss version="2.0">
|
||||
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss">
|
||||
<channel>
|
||||
<title>The WebGUI buglist</title>
|
||||
<link>/tbb</link>
|
||||
|
|
@ -159,6 +159,11 @@ character, creating invalid markup.</p>
|
|||
<p>No more text is shown of the first paragraph beyond the bold characters of the first line.</p>
|
||||
<p>Third paragraph, for completeness.</p>
|
||||
</description>
|
||||
<media:content
|
||||
url="http://www.plainblack.com/wg_btn.jpg"
|
||||
filesize="1415"
|
||||
type="image/jpeg"
|
||||
medium="image" />
|
||||
</item>
|
||||
</channel>
|
||||
</rss>
|
||||
|
|
@ -179,6 +184,15 @@ is $vars->{item_loop}->[0]->{descriptionFirstSentence},
|
|||
Rich Text editor in the first sentence of the description.",
|
||||
'... first sentence, with HTML stripped';
|
||||
|
||||
is_deeply $vars->{item_loop}->[0]->{media}, [
|
||||
{
|
||||
url => 'http://www.plainblack.com/wg_btn.jpg',
|
||||
type => 'image/jpeg',
|
||||
medium => 'image',
|
||||
filesize => 1415,
|
||||
}
|
||||
], 'MediaRSS';
|
||||
|
||||
####################################################################
|
||||
#
|
||||
# generateFeed, hasTerms
|
||||
|
|
|
|||
|
|
@ -253,6 +253,7 @@ cmp_deeply(
|
|||
field_type => "textarea",
|
||||
}],
|
||||
viewScreenTitle => "",
|
||||
'Thingy field' => 'test value',
|
||||
},
|
||||
'Getting newly added thing data as JSON: www_viewThingDataViaAjax returns correct data as JSON.'
|
||||
);
|
||||
|
|
@ -430,7 +431,6 @@ $session->request->setup_body({
|
|||
$session->user({userId => '3'});
|
||||
$session->response->status(200);
|
||||
my $json = $thingy->www_editThingDataSaveViaAjax();
|
||||
diag "json: ".$json;
|
||||
is $json, '{}', 'www_editThingDataSaveViaAjax: Empty JSON hash';
|
||||
is $session->response->status, 200, '... http status=200';
|
||||
|
||||
|
|
|
|||
88
t/Asset/Wobject/Thingy/duplicate.t
Normal file
88
t/Asset/Wobject/Thingy/duplicate.t
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
#-------------------------------------------------------------------
|
||||
# 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 lib "$FindBin::Bin/../../../lib";
|
||||
|
||||
##The goal of this test is to test editThingDataSave, particularly those things not tested in Thingy.t
|
||||
|
||||
use WebGUI::Test;
|
||||
use WebGUI::Session;
|
||||
use Test::More tests => 6; # increment this value for each test you create
|
||||
use Test::Deep;
|
||||
use JSON;
|
||||
use WebGUI::Asset::Wobject::Thingy;
|
||||
use WebGUI::Search;
|
||||
use WebGUI::Search::Index;
|
||||
use Data::Dumper;
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
# Do our work in the import node
|
||||
my $node = WebGUI::Test->asset;
|
||||
|
||||
my $thingy = $node->addChild({
|
||||
className => 'WebGUI::Asset::Wobject::Thingy',
|
||||
groupIdView => 7,
|
||||
url => 'some_thing',
|
||||
});
|
||||
is $session->db->quickScalar('select count(*) from assetIndex where assetId=?',[$thingy->getId]), 0, 'no records yet';
|
||||
$thingy->commit;
|
||||
|
||||
# Test indexThing, without needing a real thing
|
||||
my $groupIdEdit = $thingy->get("groupIdEdit");
|
||||
my %thingProperties = (
|
||||
thingId => "THING_RECORD",
|
||||
label => 'Label',
|
||||
editScreenTitle => 'Edit',
|
||||
editInstructions => 'instruction_edit',
|
||||
groupIdAdd => $groupIdEdit,
|
||||
groupIdEdit => $groupIdEdit,
|
||||
saveButtonLabel => 'save',
|
||||
afterSave => 'searchThisThing',
|
||||
editTemplateId => "ThingyTmpl000000000003",
|
||||
groupIdView => '2',
|
||||
viewTemplateId => "ThingyTmpl000000000002",
|
||||
defaultView => 'searchThing',
|
||||
searchScreenTitle => 'Search',
|
||||
searchDescription => 'description_search',
|
||||
groupIdSearch => $groupIdEdit,
|
||||
groupIdExport => $groupIdEdit,
|
||||
groupIdImport => $groupIdEdit,
|
||||
searchTemplateId => "ThingyTmpl000000000004",
|
||||
thingsPerPage => 25,
|
||||
);
|
||||
my $thingId = $thingy->addThing(\%thingProperties);
|
||||
%thingProperties = %{ $thingy->getThing($thingId) };
|
||||
|
||||
my $field1Id = $thingy->addField({
|
||||
thingId => $thingId,
|
||||
fieldId => "new",
|
||||
label => "textual",
|
||||
dateCreated => time(),
|
||||
fieldType => "text",
|
||||
status => "editable",
|
||||
display => 1,
|
||||
}, 0);
|
||||
|
||||
is $thingy->getThings->rows, 1, 'Thingy has 1 thing';
|
||||
|
||||
my $fields = $session->db->prepare('select fieldId from Thingy_fields where assetId=?');
|
||||
$fields->execute([$thingy->getId]);
|
||||
is $fields->rows, '1', 'Thingy has 1 field';
|
||||
|
||||
my $duplicated = $thingy->duplicate;
|
||||
WebGUI::Test->addToCleanup($duplicated);
|
||||
is $thingy->getThings->rows, 1, 'Thingy still has 1 thing';
|
||||
is $duplicated->getThings->rows, 1, 'Duplicated thingy has 1 thing, too';
|
||||
|
||||
$fields->execute([$duplicated->getId]);
|
||||
is $fields->rows, '1', 'Duplicated thingy has 1 field';
|
||||
106
t/Asset/Wobject/Thingy/editThingDataSave.t
Normal file
106
t/Asset/Wobject/Thingy/editThingDataSave.t
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
#-------------------------------------------------------------------
|
||||
# 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 lib "$FindBin::Bin/../../../lib";
|
||||
|
||||
##The goal of this test is to test editThingDataSave, particularly those things not tested in Thingy.t
|
||||
|
||||
use WebGUI::Test;
|
||||
use WebGUI::Session;
|
||||
use Test::More tests => 6; # increment this value for each test you create
|
||||
use Test::Deep;
|
||||
use JSON;
|
||||
use WebGUI::Asset::Wobject::Thingy;
|
||||
use Data::Dumper;
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
# Do our work in the import node
|
||||
my $node = WebGUI::Test->asset;
|
||||
my $thingy = $node->addChild({className=>'WebGUI::Asset::Wobject::Thingy'});
|
||||
|
||||
# Test adding a new Thing
|
||||
my $i18n = WebGUI::International->new($session, "Asset_Thingy");
|
||||
my $groupIdEdit = $thingy->get("groupIdEdit");
|
||||
my %thingProperties = (
|
||||
thingId => "new",
|
||||
label => $i18n->get('assetName'),
|
||||
editScreenTitle => $i18n->get('edit screen title label'),
|
||||
editInstructions => '',
|
||||
groupIdAdd => $groupIdEdit,
|
||||
groupIdEdit => $groupIdEdit,
|
||||
saveButtonLabel => $i18n->get('default save button label'),
|
||||
afterSave => 'searchThisThing',
|
||||
editTemplateId => "ThingyTmpl000000000003",
|
||||
groupIdView => $groupIdEdit,
|
||||
viewTemplateId => "ThingyTmpl000000000002",
|
||||
defaultView => 'searchThing',
|
||||
searchScreenTitle => $i18n->get('search screen title label'),
|
||||
searchDescription => '',
|
||||
groupIdSearch => $groupIdEdit,
|
||||
groupIdExport => $groupIdEdit,
|
||||
groupIdImport => $groupIdEdit,
|
||||
searchTemplateId => "ThingyTmpl000000000004",
|
||||
thingsPerPage => 25,
|
||||
);
|
||||
|
||||
my $thingId = $thingy->addThing(\%thingProperties,0);
|
||||
|
||||
# Test adding a field
|
||||
|
||||
my %fieldProperties = (
|
||||
thingId => $thingId,
|
||||
fieldId => "new",
|
||||
label => "Optional",
|
||||
dateCreated => time(),
|
||||
fieldType => "text",
|
||||
status => "editable",
|
||||
display => 1,
|
||||
);
|
||||
|
||||
my $field1Id = $thingy->addField(\%fieldProperties, 0);
|
||||
$fieldProperties{status} = 'required';
|
||||
$fieldProperties{label} = 'Required';
|
||||
my $field2Id = $thingy->addField(\%fieldProperties, 0);
|
||||
|
||||
# Test adding, editing, getting and deleting thing data
|
||||
|
||||
my ($newThingDataId, $errors);
|
||||
($newThingDataId, $errors) = $thingy->editThingDataSave($thingId, 'new',
|
||||
{
|
||||
"field_".$field1Id => 'test value',
|
||||
"field_".$field2Id => 'test value',
|
||||
},
|
||||
);
|
||||
|
||||
cmp_deeply(
|
||||
$errors,
|
||||
[],
|
||||
'no errors for a valid thing data save'
|
||||
);
|
||||
|
||||
ok $session->id->valid($newThingDataId), 'valid GUID for saved field';
|
||||
|
||||
my $row_exists = $session->db->quickScalar('select count(*) from `Thingy_'.$thingId.'`');
|
||||
is $row_exists, 1, 'data written to the database';
|
||||
|
||||
($newThingDataId, $errors) = $thingy->editThingDataSave($thingId, 'new',
|
||||
{
|
||||
"field_".$field1Id => 'another test value',
|
||||
},
|
||||
);
|
||||
|
||||
is scalar @{ $errors }, 1, 'one error due to missing, required field';
|
||||
is $newThingDataId, '', '... no row id returned';
|
||||
|
||||
$row_exists = $session->db->quickScalar('select count(*) from `Thingy_'.$thingId.'`');
|
||||
is $row_exists, 1, '... no new data written to the datbase';
|
||||
119
t/Asset/Wobject/Thingy/getSearchTemplateVars.t
Normal file
119
t/Asset/Wobject/Thingy/getSearchTemplateVars.t
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
#-------------------------------------------------------------------
|
||||
# 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 lib "$FindBin::Bin/../../../lib";
|
||||
|
||||
##The goal of this test is to test getSearchTemplateVariables
|
||||
|
||||
use WebGUI::Test;
|
||||
use WebGUI::Session;
|
||||
use Test::More tests => 6; # increment this value for each test you create
|
||||
use Test::Deep;
|
||||
use JSON;
|
||||
use WebGUI::Asset::Wobject::Thingy;
|
||||
use WebGUI::Search;
|
||||
use WebGUI::Search::Index;
|
||||
use Data::Dumper;
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
# Do our work in the import node
|
||||
my $node = WebGUI::Test->asset;
|
||||
|
||||
my $thingy = $node->addChild({
|
||||
className => 'WebGUI::Asset::Wobject::Thingy',
|
||||
groupIdView => 7,
|
||||
url => 'some_thing',
|
||||
});
|
||||
is $session->db->quickScalar('select count(*) from assetIndex where assetId=?',[$thingy->getId]), 0, 'no records yet';
|
||||
$thingy->commit;
|
||||
|
||||
# Test indexThing, without needing a real thing
|
||||
my $groupIdEdit = $thingy->get("groupIdEdit");
|
||||
my %thingProperties = (
|
||||
thingId => "THING_RECORD",
|
||||
label => 'Label',
|
||||
editScreenTitle => 'Edit',
|
||||
editInstructions => 'instruction_edit',
|
||||
groupIdAdd => $groupIdEdit,
|
||||
groupIdEdit => $groupIdEdit,
|
||||
saveButtonLabel => 'save',
|
||||
afterSave => 'searchThisThing',
|
||||
editTemplateId => "ThingyTmpl000000000003",
|
||||
groupIdView => '7',
|
||||
viewTemplateId => "ThingyTmpl000000000002",
|
||||
defaultView => 'searchThing',
|
||||
searchScreenTitle => 'Search',
|
||||
searchDescription => 'description_search',
|
||||
groupIdSearch => '7',
|
||||
groupIdExport => $groupIdEdit,
|
||||
groupIdImport => $groupIdEdit,
|
||||
searchTemplateId => "ThingyTmpl000000000004",
|
||||
thingsPerPage => 25,
|
||||
);
|
||||
my $thingId = $thingy->addThing(\%thingProperties);
|
||||
%thingProperties = %{ $thingy->getThing($thingId) };
|
||||
|
||||
my $field1Id = $thingy->addField({
|
||||
thingId => $thingId,
|
||||
fieldId => "new",
|
||||
label => "textual",
|
||||
dateCreated => time(),
|
||||
fieldType => "text",
|
||||
status => "editable",
|
||||
display => 1,
|
||||
searchIn => 1,
|
||||
displayInSearch => 1,
|
||||
}, 0);
|
||||
|
||||
is $thingy->getThings->rows, 1, 'Thingy has 1 thing';
|
||||
|
||||
my $fields = $session->db->quickScalar('select count(*) from Thingy_fields where assetId=? and thingId=?',[$thingy->getId, $thingId]);
|
||||
is $fields, '1', 'Thingy has 1 field';
|
||||
|
||||
$thingy->editThingDataSave($thingId, 'new', {
|
||||
thingDataId => 'new',
|
||||
"field_$field1Id" => 'texty',
|
||||
});
|
||||
|
||||
$thingy->editThingDataSave($thingId, 'new', {
|
||||
thingDataId => 'new',
|
||||
"field_$field1Id" => 'crusty',
|
||||
});
|
||||
|
||||
$session->request->setup_body({
|
||||
thingId => $thingId,
|
||||
});
|
||||
|
||||
my $vars;
|
||||
$vars = $thingy->getSearchTemplateVars();
|
||||
my @results;
|
||||
@results = map { $_->{searchResult_field_loop}->[0]->{field_value} } @{ $vars->{searchResult_loop} };
|
||||
cmp_bag(\@results, [qw/texty crusty/], 'with no func set, returns all data');
|
||||
|
||||
$session->request->setup_body({
|
||||
thingId => $thingId,
|
||||
func => 'search',
|
||||
'field_'.$field1Id => 'texty',
|
||||
});
|
||||
$vars = $thingy->getSearchTemplateVars();
|
||||
@results = map { $_->{searchResult_field_loop}->[0]->{field_value} } @{ $vars->{searchResult_loop} };
|
||||
cmp_bag(\@results, [qw/texty/], 'with no func=search, returns only what we searched for');
|
||||
|
||||
$session->request->setup_body({
|
||||
thingId => $thingId,
|
||||
func => 'searchViaAjax',
|
||||
'field_'.$field1Id => 'crusty',
|
||||
});
|
||||
$vars = $thingy->getSearchTemplateVars();
|
||||
@results = map { $_->{searchResult_field_loop}->[0]->{field_value} } @{ $vars->{searchResult_loop} };
|
||||
cmp_bag(\@results, [qw/crusty/], 'with no func=searchViaAjax, returns only what we searched for');
|
||||
296
t/Asset/Wobject/Thingy/indexing.t
Normal file
296
t/Asset/Wobject/Thingy/indexing.t
Normal file
|
|
@ -0,0 +1,296 @@
|
|||
#-------------------------------------------------------------------
|
||||
# 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 Test::MockTime qw/:all/;
|
||||
use FindBin;
|
||||
use strict;
|
||||
use lib "$FindBin::Bin/../../../lib";
|
||||
|
||||
##The goal of this test is to test editThingDataSave, particularly those things not tested in Thingy.t
|
||||
|
||||
use WebGUI::Test;
|
||||
use WebGUI::Session;
|
||||
use Test::More tests => 24; # increment this value for each test you create
|
||||
use Test::Deep;
|
||||
use JSON;
|
||||
use WebGUI::Asset::Wobject::Thingy;
|
||||
use WebGUI::Search;
|
||||
use WebGUI::Search::Index;
|
||||
use Data::Dumper;
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
# Do our work in the import node
|
||||
my $node = WebGUI::Asset->getImportNode($session);
|
||||
|
||||
set_relative_time(-60);
|
||||
|
||||
my $versionTag = WebGUI::VersionTag->getWorking($session);
|
||||
$versionTag->set({name=>"Thingy Test"});
|
||||
WebGUI::Test->addToCleanup($versionTag);
|
||||
my $thingy = $node->addChild({
|
||||
className => 'WebGUI::Asset::Wobject::Thingy',
|
||||
groupIdView => 7,
|
||||
url => 'some_thing',
|
||||
tagId => $versionTag->getId,
|
||||
status => "pending",
|
||||
});
|
||||
is $session->db->quickScalar('select count(*) from assetIndex where assetId=?',[$thingy->getId]), 0, 'no records yet';
|
||||
$versionTag->commit;
|
||||
$thingy = $thingy->cloneFromDb;
|
||||
|
||||
# Test indexThing, without needing a real thing
|
||||
my $groupIdEdit = $thingy->get("groupIdEdit");
|
||||
my %thingProperties = (
|
||||
thingId => "THING_RECORD",
|
||||
label => 'Label',
|
||||
editScreenTitle => 'Edit',
|
||||
editInstructions => 'instruction_edit',
|
||||
groupIdAdd => $groupIdEdit,
|
||||
groupIdEdit => $groupIdEdit,
|
||||
saveButtonLabel => 'save',
|
||||
afterSave => 'searchThisThing',
|
||||
editTemplateId => "ThingyTmpl000000000003",
|
||||
groupIdView => '2',
|
||||
viewTemplateId => "ThingyTmpl000000000002",
|
||||
defaultView => 'searchThing',
|
||||
searchScreenTitle => 'Search',
|
||||
searchDescription => 'description_search',
|
||||
groupIdSearch => $groupIdEdit,
|
||||
groupIdExport => $groupIdEdit,
|
||||
groupIdImport => $groupIdEdit,
|
||||
searchTemplateId => "ThingyTmpl000000000004",
|
||||
thingsPerPage => 25,
|
||||
);
|
||||
is $session->db->quickScalar('select count(*) from assetIndex where assetId=?',[$thingy->getId]), 1, 'committing the asset adds a record';
|
||||
|
||||
$thingy->indexThing(\%thingProperties);
|
||||
|
||||
is $session->db->quickScalar('select count(*) from assetIndex where assetId=?',[$thingy->getId]), 2, 'indexThing: adds a record to the assetIndex';
|
||||
|
||||
my $record;
|
||||
|
||||
$record = $session->db->quickHashRef('select * from assetIndex where assetId=?',[$thingy->getId]);
|
||||
cmp_deeply(
|
||||
$record,
|
||||
superhashof({
|
||||
subId => 'THING_RECORD',
|
||||
url => $thingy->getUrl('func=search;thingId=THING_RECORD'),
|
||||
title => 'Label',
|
||||
groupIdView => 2,
|
||||
keywords => all(
|
||||
re('Label'),
|
||||
re('Edit'),
|
||||
re('instruction_edit'),
|
||||
re('Search'),
|
||||
re('description_search'),
|
||||
),
|
||||
}),
|
||||
'... correct record entered via indexThing'
|
||||
);
|
||||
|
||||
$thingy->deleteThingIndex('THING_RECORD');
|
||||
is $session->db->quickScalar('select count(*) from assetIndex where assetId=?',[$thingy->getId]), 1, 'deleteThingIndex removes the record of the Thing from assetIndex';
|
||||
|
||||
$thingy->indexThing(\%thingProperties);
|
||||
$thingProperties{saveButtonLabel} = 'Save';
|
||||
$thingy->indexThing(\%thingProperties);
|
||||
is $session->db->quickScalar('select count(*) from assetIndex where assetId=?',[$thingy->getId]), 2, 'indexThing safely handles updating the same record';
|
||||
|
||||
$thingy->deleteThingIndex('THING_RECORD');
|
||||
|
||||
my $thingId = $thingy->addThing(\%thingProperties);
|
||||
%thingProperties = %{ $thingy->getThing($thingId) };
|
||||
$thingy->indexThing(\%thingProperties);
|
||||
is $session->db->quickScalar('select count(*) from assetIndex where assetId=?',[$thingy->getId]), 2, 'two index entries, setup for indexThingData';
|
||||
|
||||
my $field1Id = $thingy->addField({
|
||||
thingId => $thingId,
|
||||
fieldId => "new",
|
||||
label => "textual",
|
||||
dateCreated => time(),
|
||||
fieldType => "text",
|
||||
status => "editable",
|
||||
display => 1,
|
||||
}, 0);
|
||||
|
||||
$thingy->indexThingData($thingId, {
|
||||
thingDataId => 'THING_DATA',
|
||||
"field_$field1Id" => 'texty',
|
||||
});
|
||||
is $session->db->quickScalar('select count(*) from assetIndex where assetId=?',[$thingy->getId]), 2, 'indexThingData added no records, displayInSearch=0';
|
||||
|
||||
$thingy->deleteField($field1Id, $thingId);
|
||||
$field1Id = $thingy->addField({
|
||||
thingId => $thingId,
|
||||
fieldId => "new",
|
||||
label => "textual",
|
||||
dateCreated => time(),
|
||||
fieldType => "text",
|
||||
status => "editable",
|
||||
display => 1,
|
||||
displayInSearch => 1,
|
||||
}, 0);
|
||||
|
||||
$thingy->indexThingData($thingId, {
|
||||
thingDataId => 'THING_DATA',
|
||||
"field_$field1Id" => 'texty',
|
||||
});
|
||||
is $session->db->quickScalar('select count(*) from assetIndex where assetId=?',[$thingy->getId]), 3, 'indexThingData added one record, displayInSearch=1';
|
||||
|
||||
$thingy->indexThingData($thingId, {
|
||||
thingDataId => 'THING_DATA',
|
||||
"field_$field1Id" => 'texty',
|
||||
});
|
||||
is $session->db->quickScalar('select count(*) from assetIndex where assetId=?',[$thingy->getId]), 3, 'indexThingData added 1 record';
|
||||
my $search;
|
||||
$search = WebGUI::Search->new($session)->search({ lineage => [$thingy->get('lineage')], keywords => 'texty'});
|
||||
is @{ $search->getAssetIds }, 1, '... verify that it is the right record';
|
||||
cmp_deeply(
|
||||
$search->getPaginatorResultSet->getPageData,
|
||||
[
|
||||
{
|
||||
assetId => $thingy->getId,
|
||||
className => 'WebGUI::Asset::Wobject::Thingy',
|
||||
creationDate => ignore(),
|
||||
groupIdEdit => $groupIdEdit,
|
||||
groupIdView => 2, ##From the thing
|
||||
ownerUserId => 3,
|
||||
revisionDate => ignore(),
|
||||
score => ignore(),
|
||||
synopsis => ignore(),
|
||||
title => 'Label', ##From the Thing's label
|
||||
url => $thingy->getUrl('func=viewThingData;thingId='.$thingId.';thingDataId=THING_DATA'),
|
||||
}
|
||||
],
|
||||
'Checking indexed data for the thingData'
|
||||
);
|
||||
|
||||
$thingy->deleteThingDataIndex('THING_DATA');
|
||||
is $session->db->quickScalar('select count(*) from assetIndex where assetId=?',[$thingy->getId]), 2, 'deleteThingDataIndex deleted just 1 record';
|
||||
|
||||
my $field2Id = $thingy->addField({
|
||||
thingId => $thingId,
|
||||
fieldId => "new",
|
||||
label => "dated",
|
||||
dateCreated => time(),
|
||||
fieldType => "date",
|
||||
status => "editable",
|
||||
display => 1,
|
||||
displayInSearch => 1,
|
||||
viewScreenTitle => 1,
|
||||
}, 0);
|
||||
|
||||
my $birthday = WebGUI::Test->webguiBirthday;
|
||||
|
||||
$thingy->indexThingData($thingId, {
|
||||
thingDataId => 'THING_DATA',
|
||||
"field_$field1Id" => 'texty',
|
||||
"field_$field2Id" => $birthday,
|
||||
});
|
||||
is $session->db->quickScalar('select count(*) from assetIndex where assetId=?',[$thingy->getId]), 3, 'indexThingData added 1 record';
|
||||
|
||||
$search = WebGUI::Search->new($session)->search({ lineage => [$thingy->get('lineage')], keywords => $birthday});
|
||||
is @{ $search->getAssetIds }, 0, 'birthday not added as a keyword';
|
||||
$search = WebGUI::Search->new($session)->search({ lineage => [$thingy->get('lineage')], keywords => 'texty'});
|
||||
is @{ $search->getAssetIds }, 1, 'texty added as a keyword';
|
||||
$search = WebGUI::Search->new($session)->search({ lineage => [$thingy->get('lineage')], keywords => 'texty'});
|
||||
cmp_deeply(
|
||||
$search->getPaginatorResultSet->getPageData,
|
||||
[
|
||||
{
|
||||
assetId => $thingy->getId,
|
||||
className => 'WebGUI::Asset::Wobject::Thingy',
|
||||
creationDate => ignore(),
|
||||
groupIdEdit => $groupIdEdit,
|
||||
groupIdView => 2, ##From the thing
|
||||
ownerUserId => 3,
|
||||
revisionDate => ignore(),
|
||||
score => ignore(),
|
||||
synopsis => ignore(),
|
||||
title => '8/16/2001', ##From viewScreenTitle, which is $birthday in user's preferred date format
|
||||
url => $thingy->getUrl('func=viewThingData;thingId='.$thingId.';thingDataId=THING_DATA'),
|
||||
}
|
||||
],
|
||||
'Checking indexed data for the thingData'
|
||||
);
|
||||
|
||||
|
||||
$thingy->deleteThingDataIndex('THING_DATA');
|
||||
|
||||
my $field3Id = $thingy->addField({
|
||||
thingId => $thingId,
|
||||
fieldId => "new",
|
||||
label => "nailfile",
|
||||
dateCreated => time(),
|
||||
fieldType => "file",
|
||||
status => "editable",
|
||||
display => 1,
|
||||
displayInSearch => 1,
|
||||
}, 0);
|
||||
|
||||
my $storage = WebGUI::Storage->create($session);
|
||||
$storage->addFileFromScalar('filing.txt', 'filings');
|
||||
WebGUI::Test->addToCleanup($storage);
|
||||
|
||||
$thingy->indexThingData($thingId, {
|
||||
thingDataId => 'THING_DATA',
|
||||
"field_$field1Id" => 'texty',
|
||||
"field_$field2Id" => $birthday,
|
||||
"field_$field3Id" => $storage->getId,
|
||||
});
|
||||
|
||||
$search = WebGUI::Search->new($session)->search({ lineage => [$thingy->get('lineage')], keywords => 'texty'});
|
||||
is @{ $search->getAssetIds }, 1, 'texty added as a keyword';
|
||||
$search = WebGUI::Search->new($session)->search({ lineage => [$thingy->get('lineage')], keywords => 'filings'});
|
||||
is @{ $search->getAssetIds }, 1, 'filings added as a keyword from a file';
|
||||
|
||||
restore_time();
|
||||
|
||||
##Make a real data entry for indexContent
|
||||
$thingy->deleteThingDataIndex('THING_DATA');
|
||||
$thingy->editThingDataSave($thingId, 'new', {
|
||||
thingDataId => 'new',
|
||||
"field_$field1Id" => 'texty',
|
||||
"field_$field2Id" => $birthday,
|
||||
"field_$field3Id" => $storage->getId,
|
||||
});
|
||||
|
||||
$search = WebGUI::Search->new($session)->search({ lineage => [$thingy->get('lineage')], });
|
||||
is @{ $search->getAssetIds }, 3, 'setup for indexContent, start with 3 records...';
|
||||
|
||||
my $updateTag = WebGUI::VersionTag->getWorking($session);
|
||||
WebGUI::Test->addToCleanup($updateTag);
|
||||
$thingy = $thingy->addRevision({ url => 'wild_thing', tagId => $updateTag->getId, status => "pending" });
|
||||
$updateTag->commit;
|
||||
$thingy = $thingy->cloneFromDb;
|
||||
|
||||
$search = WebGUI::Search->new($session)->search({ lineage => [$thingy->get('lineage')], });
|
||||
is @{ $search->getAssetIds }, 3, '... end with 3 records';
|
||||
my $records = $search->getResultSet();
|
||||
my @urls;
|
||||
while (my $record = $records->hashRef) {
|
||||
push @urls, $record->{url};
|
||||
}
|
||||
|
||||
cmp_deeply(
|
||||
\@urls,
|
||||
array_each(re('wild_thing')),
|
||||
'All search URLs updated on commit'
|
||||
) or diag Dumper(\@urls);
|
||||
|
||||
$search = WebGUI::Search->new($session)->search({ lineage => [$thingy->get('lineage')], keywords => 'texty'});
|
||||
is @{ $search->getAssetIds }, 1, 'setup for deleteField, texty keyword has one hit';
|
||||
|
||||
$thingy->deleteField($field1Id, $thingId);
|
||||
|
||||
$search = WebGUI::Search->new($session)->search({ lineage => [$thingy->get('lineage')], keywords => 'texty'});
|
||||
is @{ $search->getAssetIds }, 0, 'deleteField causes the thing to be reindexed';
|
||||
|
||||
108
t/Asset/Wobject/WeatherData.t
Normal file
108
t/Asset/Wobject/WeatherData.t
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
# vim:syntax=perl
|
||||
#-------------------------------------------------------------------
|
||||
# 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
|
||||
#------------------------------------------------------------------
|
||||
|
||||
# This tests the AssetReport asset
|
||||
#
|
||||
#
|
||||
|
||||
use Test::MockTime qw/:all/;
|
||||
use FindBin;
|
||||
use strict;
|
||||
use lib "$FindBin::Bin/../../lib";
|
||||
use Test::More;
|
||||
use Test::Deep;
|
||||
use Clone qw/clone/;
|
||||
|
||||
use WebGUI::Test; # Must use this before any other WebGUI modules
|
||||
use WebGUI::Session;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Init
|
||||
my $session = WebGUI::Test->session;
|
||||
my $node = WebGUI::Asset->getImportNode( $session );
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
my $can_test = 1;
|
||||
|
||||
my $partnerId = $session->config->get('testing/WeatherData_partnerId');
|
||||
if (!$partnerId) {
|
||||
$partnerId = 'partnerId';
|
||||
$can_test = 0;
|
||||
}
|
||||
|
||||
my $licenseKey = $session->config->get('testing/WeatherData_licenseKey');
|
||||
if (!$licenseKey) {
|
||||
$partnerId = 'licenseKey';
|
||||
$can_test = 0;
|
||||
}
|
||||
|
||||
if ($can_test) {
|
||||
plan tests => 7; # Increment this number for each test you create
|
||||
}
|
||||
else {
|
||||
plan skip_all => 'Missing credentials for Weather.com';
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Asset Report creation
|
||||
|
||||
#1234567890123456789012#
|
||||
my $templateId = 'FAKE_WEATHER_TEMPLATEq';
|
||||
|
||||
my $templateMock = Test::MockObject->new({});
|
||||
$templateMock->set_isa('WebGUI::Asset::Template');
|
||||
$templateMock->set_always('getId', $templateId);
|
||||
my $templateVars;
|
||||
$templateMock->mock('process', sub { $templateVars = clone $_[1]; } );
|
||||
|
||||
my $asset = $node->addChild( {
|
||||
className => 'WebGUI::Asset::Wobject::WeatherData',
|
||||
cacheTimeout => 2000,
|
||||
partnerId => $partnerId,
|
||||
licenseKey => $licenseKey,
|
||||
locations => "53715",
|
||||
templateId => $templateId,
|
||||
} );
|
||||
WebGUI::Test->addToCleanup($asset);
|
||||
|
||||
my $now = time();
|
||||
diag $now;
|
||||
set_relative_time(-1000);
|
||||
diag time();
|
||||
|
||||
WebGUI::Test->mockAssetId($templateId, $templateMock);
|
||||
$asset->prepareView();
|
||||
$asset->view();
|
||||
|
||||
my $weather_data = $templateVars->{'ourLocations.loop'}->[0];
|
||||
|
||||
is $weather_data->{cityState}, 'Madison, WI (53715)', 'data from weather.com returned';
|
||||
my $last_fetch = $weather_data->{last_fetch};
|
||||
diag $last_fetch;
|
||||
cmp_ok $last_fetch, '<', $now-500, 'last_fetch set in the past';
|
||||
|
||||
is $session->cache->get(join "", $asset->getId, '53715' )->{'locations'}->[0]->{cityState}, 'Madison, WI (53715)', 'cache loaded with valid data';
|
||||
|
||||
restore_time();
|
||||
|
||||
is $session->cache->get(join "", $asset->getId, '53715' )->{'locations'}->[0]->{cityState}, 'Madison, WI (53715)', 'cache loaded with valid data';
|
||||
|
||||
$asset->update({locations => "53715\n97123"});
|
||||
|
||||
$asset->view();
|
||||
$weather_data = $templateVars->{'ourLocations.loop'};
|
||||
is $weather_data->[1]->{cityState}, 'Hillsboro, OR (97123)', 'weather data fetch successful, new location';
|
||||
is $weather_data->[0]->{cityState}, 'Madison, WI (53715)', '...cached weather data';
|
||||
is $weather_data->[0]->{last_fetch}, $last_fetch, '53715 lookup was cached';
|
||||
|
||||
#vim:ft=perl
|
||||
|
|
@ -35,6 +35,7 @@ my $wiki
|
|||
topLevelKeywords => 'criminals,inmates,staff',
|
||||
url => 'testwiki',
|
||||
title => 'testwiki',
|
||||
groupIdView => '2',
|
||||
}, @childCoda );
|
||||
|
||||
my %page_set = ();
|
||||
|
|
@ -48,7 +49,7 @@ foreach my $keywords (qw/staff inmates criminals/) {
|
|||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
plan tests => 11; # Increment this number for each test you create
|
||||
plan tests => 15; # Increment this number for each test you create
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
#
|
||||
|
|
@ -236,4 +237,15 @@ cmp_deeply(
|
|||
|
||||
$page_set{criminals}->update({keywords => 'red,andy,tommy'});
|
||||
|
||||
$session->user({userId => 3});
|
||||
ok $wiki->canView(), 'checking permission handling in www_byKeyword: Admin can view the wiki';
|
||||
$wiki->www_byKeyword;
|
||||
is $session->response->status, 201, '... HTTP status set to 201';
|
||||
|
||||
$session->user({userId => 1});
|
||||
ok !$wiki->canView(), '... visitor cannot view the wiki';
|
||||
$wiki->www_byKeyword;
|
||||
is $session->response->status, 401, '... HTTP status set to 401, no access';
|
||||
|
||||
|
||||
#vim:ft=perl
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ my $wiki
|
|||
= $import->addChild( {
|
||||
className => 'WebGUI::Asset::Wobject::WikiMaster',
|
||||
searchTemplateId => $templateId,
|
||||
groupIdView => '2',
|
||||
} );
|
||||
|
||||
WebGUI::Test->addToCleanup($wiki);
|
||||
|
|
@ -46,12 +47,14 @@ WebGUI::Test->addToCleanup($wiki);
|
|||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
plan tests => 1; # Increment this number for each test you create
|
||||
plan tests => 4; # Increment this number for each test you create
|
||||
|
||||
$session->request->setup_body({
|
||||
query => 'Red&Andy',
|
||||
});
|
||||
|
||||
$session->user({userId => 3});
|
||||
|
||||
{
|
||||
$wiki->www_search();
|
||||
}
|
||||
|
|
@ -60,6 +63,15 @@ is $templateVars->{addPageUrl},
|
|||
$wiki->getUrl('func=add;className=WebGUI::Asset::WikiPage;title=Red%26Andy'),
|
||||
'search encodes unsafe characters in addPageUrl';
|
||||
|
||||
$session->user({userId => 1});
|
||||
ok !$wiki->canView(), 'checking permission handling in www_search: visitor cannot view the wiki';
|
||||
|
||||
$templateVars = {};
|
||||
|
||||
$wiki->www_search;
|
||||
is_deeply $templateVars, {}, '... no template variables set';
|
||||
is $session->response->status, 401, '... HTTP status set to 401, no access';
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
#
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue