diff --git a/t/Asset/Post.t b/t/Asset/Post.t index 039b1ea28..868158d3c 100644 --- a/t/Asset/Post.t +++ b/t/Asset/Post.t @@ -19,7 +19,7 @@ use strict; use lib "$FindBin::Bin/../lib"; use WebGUI::Test; use WebGUI::Session; -use Test::More tests => 23; # increment this value for each test you create +use Test::More tests => 20; # increment this value for each test you create use Test::Deep; use WebGUI::Asset::Wobject::Collaboration; use WebGUI::Asset::Post; @@ -175,12 +175,10 @@ $storage->addFileFromFilesystem(WebGUI::Test->getTestCollateralPath('lamp.jpg')) $storage->addFileFromFilesystem(WebGUI::Test->getTestCollateralPath('littleTextFile')); my $attachment_loop = $post1->getTemplateVars()->{attachment_loop}; +use Data::Dumper; +diag Dumper($attachment_loop); -ok ( $attachment_loop->[0]->{'extension'} eq 'jpg','Yup, extension template variable in attachment loop working for jpg'); -ok ( $attachment_loop->[1]->{'extension'} eq 'jpg','Yup, extension template variable in attachment loop working for jpg'); -ok ( $attachment_loop->[2]->{'extension'} eq '','Yup, extension template variable in attachment loop working for file with no extension'); - - +my @extensions = map { [ $_->{filename}, $_->{extension} ] } @{ $attachment_loop }; cmp_bag( $attachment_loop, @@ -190,7 +188,7 @@ cmp_bag( url => $storage->getUrl('gooey.jpg'), icon => $session->url->extras('fileIcons/jpg.gif'), thumbnail => $storage->getThumbnailUrl('gooey.jpg'), - extension => 'jpg', + extension => 'jpg', isImage => bool(1), }, { @@ -198,7 +196,7 @@ cmp_bag( url => $storage->getUrl('lamp.jpg'), icon => $session->url->extras('fileIcons/jpg.gif'), thumbnail => $storage->getThumbnailUrl('lamp.jpg'), - extension => 'jpg', + extension => 'jpg', isImage => bool(1), }, { @@ -206,7 +204,7 @@ cmp_bag( url => $storage->getUrl('littleTextFile'), icon => $session->url->extras('fileIcons/unknown.gif'), thumbnail => '', - extension => '', + extension => undef, isImage => bool(0), }, ], diff --git a/t/Asset/Wobject/Article.t b/t/Asset/Wobject/Article.t index acc778845..ebf5eb80a 100644 --- a/t/Asset/Wobject/Article.t +++ b/t/Asset/Wobject/Article.t @@ -17,7 +17,10 @@ use lib "$FindBin::Bin/../../lib"; use WebGUI::Test; use WebGUI::Session; -use Test::More tests => 28; # increment this value for each test you create +use Test::More tests => 24; # increment this value for each test you create +use Test::Deep; +use Test::MockObject; +use Data::Dumper; use WebGUI::Asset::Wobject::Article; my $session = WebGUI::Test->session; @@ -131,16 +134,14 @@ isnt ($output, $cachedOutput, 'purgeCache method deletes cache'); # right values for the new field in the attached files loop: # first we create a new template with only the field in it # -------------------------------------------------------------------------------------------------- +my $templateId = 'DUMMY_TEMPLATE________'; -my $viewTemplate = $node->addChild({className=>'WebGUI::Asset::Template'}); - -my $tmplContent = "|"; - -my $newTemplateSettings = { - namespace => 'Article', - template => $tmplContent, -}; - +my $templateMock = Test::MockObject->new({}); +$templateMock->set_isa('WebGUI::Asset::Template'); +$templateMock->set_always('getId', $templateId); +my $templateVars; +$templateMock->set_true('prepare', sub { } ); +$templateMock->mock('process', sub { $templateVars = $_[1]; } ); my @extTestFiles = ("rotation_test.png","littleTextFile","jquery.js","tooWide.gif"); @@ -149,23 +150,39 @@ foreach my $f (@extTestFiles) { my $storedFilename = $storage->addFileFromFilesystem($pathedFile); } -$viewTemplate->update($newTemplateSettings); -$article->update({templateId=>$viewTemplate->getId}); -$article->prepareView; - -my $newFieldoutput = $article->view; -$newFieldoutput =~ s/\|$//; - -my @tmplExtensions = split /\|/,$newFieldoutput; - - -# rememer there is a tar file already stored from earlier test, we reuse this. -ok ( $tmplExtensions[0] eq "tar", 'Yup, extension template variable in fileLoop working for tar'); -ok ( $tmplExtensions[1] eq "png", 'Yup, extension template variable in fileLoop working for png'); -ok ( $tmplExtensions[2] eq "", 'Yup, extension template variable in fileLoop working for file with no extension'); -ok ( $tmplExtensions[3] eq "js", 'Yup, extension template variable in fileLoop working for js'); -ok ( $tmplExtensions[4] eq "gif", 'Yup, extension template variable in fileLoop working for gif'); +$article->update({templateId=>$templateId}); +{ + WebGUI::Test->mockAssetId($templateId, $templateMock); + $article->prepareView; + $article->view; + WebGUI::Test->unmockAssetId($templateId); +} +cmp_bag( + $templateVars->{attachment_loop}, + [ + superhashof({ + filename => 'rotation_test.png', + extension => 'png', + }), + superhashof({ + filename => 'littleTextFile', + extension => undef, + }), + superhashof({ + filename => 'jquery.js', + extension => 'js', + }), + superhashof({ + filename => 'tooWide.gif', + extension => 'gif', + }), + superhashof({ + filename => 'extensions.tar', + extension => 'tar', + }), + ], +) or diag Dumper($templateVars->{attachment_loop}); TODO: { local $TODO = "Tests to make later"; diff --git a/t/Asset/editFormOverride.t b/t/Asset/editFormOverride.t index 1edecdbcf..e9b34dfec 100644 --- a/t/Asset/editFormOverride.t +++ b/t/Asset/editFormOverride.t @@ -17,6 +17,7 @@ my $asset = WebGUI::Asset->getTempspace($session)->addChild( className => 'WebGUI::Asset::Wobject::Layout', } ); +WebGUI::Test->addToCleanup($asset); sub capture { my $save; @@ -36,7 +37,7 @@ sub capture { my $config = $session->config; my $pfx = 'assets/WebGUI::Asset::Wobject::Layout/fields/assetsToHide'; $config->set("$pfx/uiLevel", 1); -is capture->get('uiLevel'), 1; +is capture->get('uiLevel'), 1, 'uiLevel override to 1'; $config->set("$pfx/uiLevel", "2"); -is capture->get('uiLevel'), 2; +is capture->get('uiLevel'), 2, 'uiLEvel override to 2';