Skip to content

Commit

Permalink
Item9322: Unit Tests for UpdateAttachmentsPlugin
Browse files Browse the repository at this point in the history
 - Added copyright for Foswiki core code
 - Updated Author information

git-svn-id: http://svn.foswiki.org/trunk/UpdateAttachmentsPlugin@10309 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
GeorgeClark authored and GeorgeClark committed Dec 14, 2010
1 parent 9bc41b9 commit ec94f8e
Show file tree
Hide file tree
Showing 4 changed files with 195 additions and 17 deletions.
4 changes: 2 additions & 2 deletions data/System/UpdateAttachmentsPlugin.txt
Expand Up @@ -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 <br/> Foswiki:Main.GeorgeClark - revised for Foswiki 1.1 |
| Copyright: | &copy; 2008-2009 SvenDowideit@fosiki.com <br/> &copy; 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% |
Expand Down
43 changes: 28 additions & 15 deletions 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;

Expand Down Expand Up @@ -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.
1 change: 1 addition & 0 deletions lib/Foswiki/Plugins/UpdateAttachmentsPlugin/MANIFEST
Expand Up @@ -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

164 changes: 164 additions & 0 deletions 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', <<HERE );
Topic Text
HERE

_writeFile( $web, 'AnotherTopic', 'SomeFile');

$this->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.

0 comments on commit ec94f8e

Please sign in to comment.