From ec94f8e9f9fe34078c1891cf5da1103ed341df87 Mon Sep 17 00:00:00 2001 From: GeorgeClark Date: Tue, 14 Dec 2010 03:29:17 +0000 Subject: [PATCH] Item9322: Unit Tests for UpdateAttachmentsPlugin - Added copyright for Foswiki core code - Updated Author information git-svn-id: http://svn.foswiki.org/trunk/UpdateAttachmentsPlugin@10309 0b4bb1d4-4e5a-0410-9cc4-b2b747904278 --- data/System/UpdateAttachmentsPlugin.txt | 4 +- .../Plugins/UpdateAttachmentsPlugin.pm | 43 +++-- .../Plugins/UpdateAttachmentsPlugin/MANIFEST | 1 + .../UpdateAttachmentsPluginTests.pm | 164 ++++++++++++++++++ 4 files changed, 195 insertions(+), 17 deletions(-) create mode 100755 test/unit/UpdateAttachmentsPlugin/UpdateAttachmentsPluginTests.pm diff --git a/data/System/UpdateAttachmentsPlugin.txt b/data/System/UpdateAttachmentsPlugin.txt index 11ec61d..4cc0366 100644 --- a/data/System/UpdateAttachmentsPlugin.txt +++ b/data/System/UpdateAttachmentsPlugin.txt @@ -51,8 +51,8 @@ This plugin _may_ not function correctly if =$Foswiki::cfg{AutoAttachPubFiles}= ---++ Plugin Info -| Plugin Author(s): | Foswiki:Main.SvenDowideit - http://fosiki.com a %PUBURL%/%WEB%/%TOPIC%/wikiringlogo20x20.png [[http://WikiRing.com][WikiRing]] founding partner | -| Copyright: | © SvenDowideit@fosiki.com | +| Plugin Author(s): | Foswiki:Main.SvenDowideit - http://fosiki.com a %PUBURL%/%WEB%/%TOPIC%/wikiringlogo20x20.png [[http://WikiRing.com][WikiRing]] founding partner
Foswiki:Main.GeorgeClark - revised for Foswiki 1.1 | +| Copyright: | © 2008-2009 SvenDowideit@fosiki.com
© 2010 Foswiki Contributors | | Attachment Icon | based on eXperience Crystal, by David Christian Berg | | License: | [[http://www.gnu.org/licenses/gpl.html][GPL 3 (Gnu General Public License)]] | | Plugin Version: | %$VERSION% | diff --git a/lib/Foswiki/Plugins/UpdateAttachmentsPlugin.pm b/lib/Foswiki/Plugins/UpdateAttachmentsPlugin.pm index d0e58d2..562d2d7 100644 --- a/lib/Foswiki/Plugins/UpdateAttachmentsPlugin.pm +++ b/lib/Foswiki/Plugins/UpdateAttachmentsPlugin.pm @@ -1,18 +1,3 @@ -# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/ -# -# copyright 2007-2009 SvenDowideit@fosiki.com -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 3 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details, published at -# http://www.gnu.org/copyleft/gpl.html - package Foswiki::Plugins::UpdateAttachmentsPlugin; use strict; @@ -358,3 +343,31 @@ sub _constructAttributesForAutoAttached { } 1; +__END__ +Foswiki - The Free and Open Source Wiki, http://foswiki.org/ + +Copyright (C) 2007-2009 SvenDowideit@fosiki.com + +Copyright (C) 2010 Foswiki Contributors. Foswiki Contributors +are listed in the AUTHORS file in the root of this distribution. +NOTE: Please extend that file, not this notice. + +Additional copyrights apply to some or all of the code in this +file as follows: +Copyright (C) 2001-2006 TWiki Contributors. All Rights Reserved. +TWiki Contributors are listed in the AUTHORS file in the root +of this distribution. NOTE: Please extend that file, not this notice. +Copyright (C) 2004-2008 Crawford Currie + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. For +more details read LICENSE in the root of this distribution. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +As per the GPL, removal of this notice is prohibited. + diff --git a/lib/Foswiki/Plugins/UpdateAttachmentsPlugin/MANIFEST b/lib/Foswiki/Plugins/UpdateAttachmentsPlugin/MANIFEST index 06377a5..66ce493 100644 --- a/lib/Foswiki/Plugins/UpdateAttachmentsPlugin/MANIFEST +++ b/lib/Foswiki/Plugins/UpdateAttachmentsPlugin/MANIFEST @@ -4,4 +4,5 @@ lib/Foswiki/Plugins/UpdateAttachmentsPlugin.pm 0644 Perl module lib/Foswiki/Plugins/UpdateAttachmentsPlugin/Config.spec pub/System/UpdateAttachmentsPlugin/wikiringlogo20x20.png pub/System/UpdateAttachmentsPlugin/wikiring-attach.png +test/unit/UpdateAttachmentsPlugin/UpdateAttachmentsPluginTests.pm diff --git a/test/unit/UpdateAttachmentsPlugin/UpdateAttachmentsPluginTests.pm b/test/unit/UpdateAttachmentsPlugin/UpdateAttachmentsPluginTests.pm new file mode 100755 index 0000000..16b7644 --- /dev/null +++ b/test/unit/UpdateAttachmentsPlugin/UpdateAttachmentsPluginTests.pm @@ -0,0 +1,164 @@ +# See bottom of file for license and copyright information + +package UpdateAttachmentsPluginTests; + +use strict; +use warnings; +use FoswikiFnTestCase; +our @ISA = qw( FoswikiFnTestCase ); +use Error ':try'; + +use Unit::Request; +use Unit::Response; +use Foswiki; +use Foswiki::UI::Save; +use Foswiki::Plugins::UpdateAttachmentsPlugin; +use CGI; +use File::Path qw(mkpath); + +# Set up the test fixture +sub set_up { + my $this = shift; + + $this->SUPER::set_up(); + + $this->{attach_web} = "$this->{test_web}Attach"; + my $webObject = Foswiki::Meta->new( $this->{session}, $this->{attach_web} ); + $webObject->populateNewWeb(); + +# Foswiki::Func::getContext()->{view} = 1; + $Foswiki::cfg{Plugins}{UpdateAttachmentsPlugin}{Enabled} = 1; + $Foswiki::cfg{Plugins}{UpdateAttachmentsPlugin}{Debug} = 0; + $Foswiki::cfg{Plugins}{UpdateAttachmentsPlugin}{Module} = 'Foswiki::Plugins::UpdateAttachmentsPlugin'; + $Foswiki::cfg{Plugins}{UpdateAttachmentsPlugin}{AttachAsUser} = ''; + $Foswiki::cfg{Plugins}{UpdateAttachmentsPlugin}{RemoveMissing} = 1; + $Foswiki::cfg{Plugins}{UpdateAttachmentsPlugin}{CheckUPDATEATACHPermission} = 1; + + $this->{tmpdatafile8} = $Foswiki::cfg{TempfileDir} . '/eight.bytes'; + $this->{tmpdatafile16} = $Foswiki::cfg{TempfileDir} . '/sixteen.bytes'; + $this->{tmpdatafile32} = $Foswiki::cfg{TempfileDir} . '/thirtytwo.bytes'; + $this->{tmpdatafilex} = $Foswiki::cfg{TempfileDir} . '/bad # file @ name'; + + return; +} + +sub tear_down { + my $this = shift; + $this->removeWeb( $this->{attach_web} ); + + unlink $this->{tmpdatafile8}; + unlink $this->{tmpdatafile16}; + unlink $this->{tmpdatafile32}; + unlink $this->{tmpdatafilex}; + + $this->SUPER::tear_down(); + + return; +} + +# Save a topic into the web. +sub _writeTopic { + my ( $this, $web, $topic, $text ) = @_; + my $meta = Foswiki::Meta->new( $this->{session}, $web, $topic, $text ); + $meta->save(); + + return; +} + +# Save an attachment into the web/topic +sub _writeFile { + my ($web, $topic, $attach, $content) = @_; + + $content = "datadata/n" unless ($content); + + my $path = "$Foswiki::cfg{PubDir}/$web/$topic"; + + mkpath($path); + open( my $fh, '>', "$path/$attach" ) + or die "Unable to open $path/$attach for writing: $!\n"; + print $fh "$content \n"; + close($fh); + return; +} + +# Attach a file to the web/topic +sub _attachFile { + my ( $this, $web, $topic, $file, $text ) = @_; + + return; +} + +sub _trim { + my $s = shift; + $s =~ s/^\s*(.*?)\s*$/$1/sgo; + return $s; +} + + +# Not a test, a helper. +sub runREST { + my ( $this, $web, $topic ) = @_; + + $web ||= $this->{attach_web}; + $topic ||= 'WebHome'; + + my $url = Foswiki::Func::getScriptUrl( 'UpdateAttachmentsPlugin', 'update', 'rest' ); + + + # Compose the query + my $query = Unit::Request->new( + { + 'topic' => "$web.$topic", + } + ); + $query->path_info("/UpdateAttachmentsPlugin/update"); + + my $session = Foswiki->new( $Foswiki::cfg{DefaultUserLogin}, $query ); + my $text = "Ignore this text"; + + # invoke the save handler + my ($resp) = $this->captureWithKey( rest => $this->getUIFn('rest'), $session ); + + print STDERR "RESPONSE: $resp"; + +} + +sub test_SimpleRest { + my $this = shift; + + my $web = $this->{attach_web}; + + _writeTopic( $this, $web, 'AnotherTopic', <runREST( undef, undef); + $this->runREST( undef, undef); + + return; +} + + + + +1; +__END__ +Foswiki - The Free and Open Source Wiki, http://foswiki.org/ + +Copyright (C) 2008-2010 Foswiki Contributors. Foswiki Contributors +are listed in the AUTHORS file in the root of this distribution. +NOTE: Please extend that file, not this notice. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. For +more details read LICENSE in the root of this distribution. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +As per the GPL, removal of this notice is prohibited.