Tests for templateId and URL handling, some i18n for the RenderThingData macro.
This commit is contained in:
parent
8bc944d526
commit
595660e9e4
3 changed files with 130 additions and 2 deletions
|
|
@ -11,8 +11,8 @@ package WebGUI::Macro::RenderThingData;
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use WebGUI::Group;
|
|
||||||
use WebGUI::Asset::Template;
|
use WebGUI::Asset::Template;
|
||||||
|
use WebGUI::International;
|
||||||
use WebGUI::Asset::Wobject::Thingy;
|
use WebGUI::Asset::Wobject::Thingy;
|
||||||
|
|
||||||
=head1 NAME
|
=head1 NAME
|
||||||
|
|
@ -39,6 +39,8 @@ Optional. Specifies the templateId or template url to use. If omitted, the def
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
sub process {
|
sub process {
|
||||||
my ($session, $thingDataUrl, $templateHint ) = @_;
|
my ($session, $thingDataUrl, $templateHint ) = @_;
|
||||||
|
my $i18n = WebGUI::International->new($session, 'Macro_RenderThingData');
|
||||||
|
return $i18n->get('no template') if !$templateHint;
|
||||||
|
|
||||||
my $uri = URI->new( $thingDataUrl );
|
my $uri = URI->new( $thingDataUrl );
|
||||||
|
|
||||||
|
|
@ -55,7 +57,6 @@ sub process {
|
||||||
my $output = $thing->www_viewThingData( $thingId, $thingDataId, $templateHint );
|
my $output = $thing->www_viewThingData( $thingId, $thingDataId, $templateHint );
|
||||||
|
|
||||||
# FIX: Temporary solution (broken map due to template rendering <script> tags)
|
# FIX: Temporary solution (broken map due to template rendering <script> tags)
|
||||||
return "RenderThingData: Please specify a template." if !$templateHint;
|
|
||||||
return "RenderThingData: Contained bad tags!" if $output =~ /script>/;
|
return "RenderThingData: Contained bad tags!" if $output =~ /script>/;
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
|
|
|
||||||
18
lib/WebGUI/i18n/English/Macro_RenderThingData.pm
Normal file
18
lib/WebGUI/i18n/English/Macro_RenderThingData.pm
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
package WebGUI::i18n::English::Macro_RenderThingData;
|
||||||
|
use strict;
|
||||||
|
|
||||||
|
our $I18N = {
|
||||||
|
|
||||||
|
'bad tags' => {
|
||||||
|
message => q||,
|
||||||
|
lastUpdated => 1306275259,
|
||||||
|
},
|
||||||
|
|
||||||
|
'no template' => {
|
||||||
|
message => q|RenderThingData: Please specify a template.|,
|
||||||
|
lastUpdated => 1149177662,
|
||||||
|
},
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
1;
|
||||||
109
t/Macro/RenderThingData.t
Normal file
109
t/Macro/RenderThingData.t
Normal file
|
|
@ -0,0 +1,109 @@
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
# 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";
|
||||||
|
|
||||||
|
use WebGUI::Test;
|
||||||
|
use WebGUI::Session;
|
||||||
|
use WebGUI::Asset::Template;
|
||||||
|
use WebGUI::Macro::RenderThingData;
|
||||||
|
use WebGUI::Asset::Wobject::Thingy;
|
||||||
|
|
||||||
|
use Test::More; # increment this value for each test you create
|
||||||
|
use Test::MockObject;
|
||||||
|
use Test::Deep;
|
||||||
|
|
||||||
|
my $templateId = 'PICKLANGUAGE_TEMPLATE_';
|
||||||
|
my $templateId = 'VIEW_THING_DATA_TEMPL8T';
|
||||||
|
my $templateUrl = 'view_thing_data_template';
|
||||||
|
my $templateMock = Test::MockObject->new({});
|
||||||
|
$templateMock->set_isa('WebGUI::Asset::Template');
|
||||||
|
$templateMock->set_always('getId', $templateId);
|
||||||
|
my $templateVars;
|
||||||
|
my $templateProcessed = 0;
|
||||||
|
$templateMock->mock('process', sub { $templateVars = $_[1]; $templateProcessed = 1; } );
|
||||||
|
my $session = WebGUI::Test->session;
|
||||||
|
WebGUI::Test->mockAssetId($templateId, $templateMock);
|
||||||
|
WebGUI::Test->mockAssetUrl($templateUrl, $templateMock);
|
||||||
|
|
||||||
|
WebGUI::Test->addToCleanup(sub {
|
||||||
|
WebGUI::Test->unmockAssetId($templateId);
|
||||||
|
WebGUI::Test->unmockAssetUrl($templateUrl);
|
||||||
|
});
|
||||||
|
|
||||||
|
plan tests => 4;
|
||||||
|
|
||||||
|
my $node = WebGUI::Asset->getImportNode($session);
|
||||||
|
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',
|
||||||
|
});
|
||||||
|
$versionTag->commit;
|
||||||
|
$thingy = $thingy->cloneFromDb;
|
||||||
|
|
||||||
|
my %thingProperties = (
|
||||||
|
thingId => "THING_RECORD",
|
||||||
|
label => 'Label',
|
||||||
|
editScreenTitle => 'Edit',
|
||||||
|
editInstructions => 'instruction_edit',
|
||||||
|
groupIdAdd => '3',
|
||||||
|
groupIdEdit => '3',
|
||||||
|
saveButtonLabel => 'save',
|
||||||
|
afterSave => 'searchThisThing',
|
||||||
|
editTemplateId => "ThingyTmpl000000000003",
|
||||||
|
groupIdView => '7',
|
||||||
|
viewTemplateId => "ThingyTmpl000000000002",
|
||||||
|
defaultView => 'searchThing',
|
||||||
|
searchScreenTitle => 'Search',
|
||||||
|
searchDescription => 'description_search',
|
||||||
|
groupIdSearch => '7',
|
||||||
|
groupIdExport => '7',
|
||||||
|
groupIdImport => '7',
|
||||||
|
searchTemplateId => "ThingyTmpl000000000004",
|
||||||
|
thingsPerPage => 25,
|
||||||
|
);
|
||||||
|
my $thingId = $thingy->addThing(\%thingProperties);
|
||||||
|
my $field1Id = $thingy->addField({
|
||||||
|
thingId => $thingId,
|
||||||
|
fieldId => "new",
|
||||||
|
label => "textual",
|
||||||
|
dateCreated => time(),
|
||||||
|
fieldType => "text",
|
||||||
|
status => "editable",
|
||||||
|
display => 1,
|
||||||
|
displayInSearch => 1,
|
||||||
|
}, 0);
|
||||||
|
|
||||||
|
my ($thingDataId) = $thingy->editThingDataSave($thingId, 'new', {
|
||||||
|
thingDataId => 'new',
|
||||||
|
"field_$field1Id" => 'texty',
|
||||||
|
});
|
||||||
|
|
||||||
|
my $thing_url = $thingy->getUrl('thingId='.$thingId.';thingDataId='.$thingDataId);
|
||||||
|
my $output;
|
||||||
|
|
||||||
|
$output = WebGUI::Macro::RenderThingData::process($session, $thing_url);
|
||||||
|
like $output, qr/specify a template/, 'returns an error message if no template is offered';
|
||||||
|
ok !$templateProcessed, 'template not processed';
|
||||||
|
$templateProcessed = 0;
|
||||||
|
|
||||||
|
$output = WebGUI::Macro::RenderThingData::process($session, $thing_url, $templateId);
|
||||||
|
ok $templateProcessed, 'passed templateId, template processed';
|
||||||
|
$templateProcessed = 0;
|
||||||
|
|
||||||
|
$output = WebGUI::Macro::RenderThingData::process($session, $thing_url, $templateUrl);
|
||||||
|
ok $templateProcessed, 'passed template url, template processed';
|
||||||
|
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue