more tests plus a framework for making test generators

This commit is contained in:
Doug Bell 2007-10-12 20:44:38 +00:00
parent 983a725558
commit 320c2c07b0
5 changed files with 752 additions and 8 deletions

View file

@ -0,0 +1,94 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2007 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
#-------------------------------------------------------------------
# The goal of this test is to test the editSave and
# processPropertiesFromFormPost methods.
use FindBin;
use strict;
use lib "$FindBin::Bin/../../../../lib";
use Scalar::Util qw( blessed );
use WebGUI::Test;
use WebGUI::Session;
use Test::More;
use WebGUI::Test::Maker::HTML;
use WebGUI::Asset::File::Image::Photo;
#----------------------------------------------------------------------------
# Init
my $session = WebGUI::Test->session;
my $node = WebGUI::Asset->getImportNode($session);
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"Photo Test"});
my $maker = WebGUI::Test::Maker::HTML->new;
my $gallery
= $node->addChild({
className => "WebGUI::Asset::Wobject::PhotoGallery",
});
my $album
= $gallery->addChild({
className => "WebGUI::Asset::Wobject::PhotoAlbum",
});
my $photo
= $gallery->addChild({
className => "WebGUI::Asset::File::Image::Photo",
});
#----------------------------------------------------------------------------
# Cleanup
END {
$versionTag->rollback();
}
#----------------------------------------------------------------------------
# Tests
plan tests => 0;
#----------------------------------------------------------------------------
# Test permissions
# Edit an existing photo
$maker->prepare({
object => $photo,
method => "www_edit",
userId => "1",
test_privilege => "insufficient",
})->run;
# Save a new photo
$maker->prepare({
object => $photo,
method => "www_editSave",
userId => "1",
test_privilege => "insufficient",
})->run;
#----------------------------------------------------------------------------
# Test processPropertiesFromFormPost errors
# TODO: This test should use i18n.
# TODO: This error / test should occur in File, not Photo
$maker->prepare({
object => $album
method => "www_editSave",
formParams => {
},
test_regex => [
qr/You must select a file/,
qr/You must enter a title/,
],
})->run;
#----------------------------------------------------------------------------
# Test editSave success result
#----------------------------------------------------------------------------

View file

@ -19,6 +19,7 @@ use Scalar::Util qw( blessed );
use WebGUI::Test;
use WebGUI::Session;
use Test::More;
use WebGUI::Test::Maker::HTML;
use WebGUI::Asset::File::Image::Photo;
#----------------------------------------------------------------------------
@ -27,6 +28,7 @@ my $session = WebGUI::Test->session;
my $node = WebGUI::Asset->getImportNode($session);
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"Photo Test"});
my $maker = WebGUI::Test::Maker::HTML->new;
my $otherParent
= $node->addChild({
className => "WebGUI::Asset::Wobject::Layout",
@ -109,14 +111,13 @@ is_deeply(
#----------------------------------------------------------------------------
# www_makeShortcut is only available to those who can edit the photo
my $html = WebGUI::Test->getPage($photo, "www_makeShortcut", {
userId => 1,
});
like(
$html, qr/permission denied/i,
"www_makeShortcut is not allowed to those who can't edit the photo",
);
$maker->prepare({
object => $photo,
method => "www_makeShortcut",
userId => 1,
test_privilege => "insufficient",
});
$maker->run;
#----------------------------------------------------------------------------
# www_makeShortcut