Merge branch 'WebGUI8' of github.com:plainblack/webgui into 8

Conflicts:
	lib/WebGUI.pm
	lib/WebGUI/Auth/WebGUI.pm
	sbin/findBrokenAssets.pl
	sbin/testEnvironment.pl
This commit is contained in:
Doug Bell 2011-05-13 18:20:52 -05:00
commit 677ac978b6
89 changed files with 1064 additions and 448 deletions

View file

@ -378,7 +378,7 @@ is($fileAsPath->absolute($exportPath)->stringify, $litmus->absolute($exportPath)
# we need to be tricky here and call code in wG proper which calls www_ methods
# even though we don't have access to modperl. the following hack lets us do
# that.
#$session->http->setNoHeader(1);
#$session->response->setNoHeader(1);
$session->user( { userId => 1 } );
my $content;
@ -392,7 +392,10 @@ is($@, '', "exportWriteFile works when creating exportPath");
ok(-e $parent->exportGetUrlAsPath->absolute->stringify, "exportWriteFile actually writes the file when creating exportPath");
# now make sure that it contains the correct content
eval { $content = WebGUI::Test->getPage($parent, 'exportHtml_view', { user => WebGUI::User->new($session, 1) } ) };
$content = WebGUI::Test->getPage2(
$parent->get('url').'?func=exportHtml_view',
{ user => WebGUI::User->new($session, 1) },
);
is(scalar $parent->exportGetUrlAsPath->slurp, $content, "exportWriteFile puts the correct contents in exported parent");
@ -405,7 +408,7 @@ my $unwritablePath = Path::Class::Dir->new($config->get('uploadsPath'), 'temp',
chmod 0000, $guidPath->stringify;
$config->set('exportPath', $unwritablePath->absolute->stringify);
$session->http->setNoHeader(1);
$session->response->setNoHeader(1);
SKIP: {
skip 'Root will cause this test to fail since it does not obey file permissions', 2
if $< == 0;
@ -436,7 +439,7 @@ $config->set('exportPath', $guidPath->absolute->stringify);
chmod 0755, $guidPath->stringify;
$unwritablePath->remove;
$session->http->setNoHeader(1);
$session->response->setNoHeader(1);
eval { $firstChild->exportWriteFile() };
is($@, '', "exportWriteFile works for first_child");
@ -444,14 +447,14 @@ is($@, '', "exportWriteFile works for first_child");
ok(-e $firstChild->exportGetUrlAsPath->absolute->stringify, "exportWriteFile actually writes the first_child file");
# verify it has the correct contents
eval { $content = WebGUI::Test->getPage($firstChild, 'exportHtml_view') };
eval { $content = WebGUI::Test->getPage2( $firstChild->get('url').'?func=exportHtml_view', ) };
is(scalar $firstChild->exportGetUrlAsPath->absolute->slurp, $content, "exportWriteFile puts the correct contents in exported first_child");
# and one more level. remove the export path to ensure directory creation keeps
# working.
$guidPath->rmtree;
$session->http->setNoHeader(1);
$session->response->setNoHeader(1);
$session->user( { userId => 1 } );
eval { $grandChild->exportWriteFile() };
is($@, '', "exportWriteFile works for grandchild");
@ -461,13 +464,13 @@ ok(-e $grandChild->exportGetUrlAsPath->absolute->stringify, "exportWriteFile act
# finally, check its contents
$session->style->sent(0);
eval { $content = WebGUI::Test->getPage($grandChild, 'exportHtml_view') };
eval { $content = WebGUI::Test->getPage2( $grandChild->get('url').'?func=exportHtml_view', ) };
is(scalar $grandChild->exportGetUrlAsPath->absolute->slurp, $content, "exportWriteFile puts correct content in exported grandchild");
# test different extensions
$guidPath->rmtree;
$asset = WebGUI::Asset->newById($session, 'ExportTest000000000001');
$session->http->setNoHeader(1);
$session->response->setNoHeader(1);
eval { $asset->exportWriteFile() };
is($@, '', 'exportWriteFile for perl file works');
@ -488,7 +491,7 @@ $guidPath->rmtree;
# isn't allowed to see. this means that we'll need to temporarily change the
# permissions on something.
$parent->update( { groupIdView => 3 } ); # admins
$session->http->setNoHeader(1);
$session->response->setNoHeader(1);
eval { $parent->exportWriteFile() };
$e = Exception::Class->caught();
isa_ok($e, 'WebGUI::Error', "exportWriteFile throws when user can't view asset");
@ -950,7 +953,7 @@ SKIP: {
# user can't view asset
$parent->update( { groupIdView => 3 } );
$session->http->setNoHeader(1);
$session->response->setNoHeader(1);
chmod 0755, $tempDirectory;
eval { ($message) = $parent->exportAsHtml( { userId => 1, depth => 99 } ) };

View file

@ -148,7 +148,7 @@ $mech->submit_form_ok({
},
'Submit Photo edit form' );
# Re-create instance of Photo asset
$photo = WebGUI::Asset->newByDynamicClass($session, $photo->getId);
$photo = WebGUI::Asset->newById($session, $photo->getId);
# Check whether properties were changed correctly
cmp_deeply($photo->get, superhashof(\%properties), 'All changes applied');

46
t/PSGI/ConfigMiddleware.t Normal file
View file

@ -0,0 +1,46 @@
use strict;
use warnings;
use Test::More tests => 3;
use Plack::Test;
use Plack::Util;
use HTTP::Request::Common;
use WebGUI::Paths;
use WebGUI::Test;
SKIP: {
skip 'set WEBGUI_LIVE to enable these tests', 3 unless $ENV{WEBGUI_LIVE};
my $session = WebGUI::Test->session;
$session->config->addToArray( 'plackMiddleware', '+WebGUI::Middleware::SHOUTING' );
local $ENV{WEBGUI_CONFIG} = WebGUI::Test->file; # tell the share/site.psgi which site to load
my $app = Plack::Util::load_psgi( WebGUI::Paths->defaultPSGI );
ok( $app, "created a PSGI app from app.psgi" );
test_psgi $app, sub {
my $cb = shift;
my $res = $cb->( GET "/home" );
is $res->code, 200, 'able to fetch pages with WebGUI::Middleware::SHOUTING installed';
like $res->content, qr/EASY TO USE WEB APPLICATION FRAMEWORK/, 'contains the text "EASY TO USE WEB APPLICATION FRAMEWORK"';
};
$session->config->deleteFromArray( 'plackMiddleware', '+WebGUI::Middleware::SHOUTING' );
}
package WebGUI::Middleware::SHOUTING;
BEGIN { $INC{'WebGUI/Middleware/SHOUTING.pm'} = __FILE__; };
use parent 'Plack::Middleware';
sub call {
my($self, $env) = @_;
my $res = $self->app->($env);
for ( ref $res->[2] ? @{ $res->[2] } : ( $res->[2] ) ) {
s{>(.*?)<}{'>' . uc($1) . '<'}gse;
}
return $res;
}

68
t/PSGI/Http.t Normal file
View file

@ -0,0 +1,68 @@
use strict;
use warnings;
use Test::More tests => 7;
use Plack::Test;
use Plack::Util;
use HTTP::Request::Common;
use WebGUI::Paths;
use WebGUI::Test;
# test things about responses
# this is like t/Session/Http.t but Plack specific
SKIP: {
skip 'set WEBGUI_LIVE to enable these tests', 7 unless $ENV{WEBGUI_LIVE};
my $session = WebGUI::Test->session;
my $prev_streaming_uploads = $session->config->get('enableStreamingUploads');
local $ENV{WEBGUI_CONFIG} = WebGUI::Test->file; # tell the share/site.psgi which site to load
#
# fire up a Plack to test streaming
#
$session->config->set('enableStreamingUploads', 1);
my $app = Plack::Util::load_psgi( WebGUI::Paths->defaultPSGI );
ok( $app, "created a PSGI app from app.psgi" );
test_psgi $app, sub {
my $cb = shift;
my $res = $cb->( GET "/root/import/gallery-templates/images/previous.gif" );
is $res->code, 200, 'enableStreamingUploads: 200 response';
is $res->header('Content-Type'), 'image/gif', '... content type is image/gif';
ok substr($res->content, 0, 100) =~ m/GIF89/, '... data contains the string GIF89';
};
#
# fire up another Plack to test non-streaming
#
$session->config->set('enableStreamingUploads', 0);
$app = Plack::Util::load_psgi( WebGUI::Paths->defaultPSGI );
my $redirect_url;
test_psgi $app, sub {
my $cb = shift;
my $res = $cb->( GET "/root/import/gallery-templates/images/previous.gif" );
is $res->code, 302, 'enableStreamingUploads: 302 response';
ok $res->header('Location'), '... Location header in response';
$res = $cb->(GET $res->header('Location') );
is $res->code, 200, '... following location, we get a 200 response code';
};
#
# put things back how they were
#
$session->config->set('enableStreamingUploads', $prev_streaming_uploads);
};

View file

@ -8,6 +8,11 @@
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
# this test file is now slightly badly named since the functions in
# WebGUI::Session::HTTML have all been migrated to
# WebGUI::Session::Request and ::Response. still, these tests need
# to continue to pass.
use strict;
use WebGUI::Test;
@ -61,11 +66,22 @@ $response->status('200');
$http->setStreamedFile('');
is($http->getStreamedFile, undef, 'set/get StreamedFile: false values return undef, empty string');
$http->setStreamedFile(0);
$http->setStreamedFile(undef);
is($http->getStreamedFile, undef, 'set/get StreamedFile: false values return undef, empty string');
$http->setStreamedFile('/home/streaming');
is($http->getStreamedFile, '/home/streaming', 'set/get StreamedFile: set specific location and get it');
my $actual_file = $session->config->get('uploadsPath') . '/9e/a3/9ea37e148e517d4ae3d6326f691d848f/previous.gif'; # arbitrary file that exactually exists and hopefully will continue for a while
$http->setStreamedFile( $actual_file );
is($http->getStreamedFile, $actual_file, 'set/get StreamedFile: set specific location and get it');
do {
eval {
$http->setStreamedFile( $actual_file . '_but_actually_not_an_actual_file_because_someone_appended_a_bunch_of_bloody_garbage_to_it' );
};
my $e = WebGUI::Error->caught("WebGUI::Error::InvalidFile");
my $errorMessage = $e->error;
ok($errorMessage =~ m/No such file or directory/, "set/get StreamedFile: setting a non-existant file blows stuff up but that's okay because it's handled gracefully" );
};
$http->setStreamedFile('');
####################################################

View file

@ -195,7 +195,7 @@ $session->setting->set('userFunctionStyleId', $templates->{user}->getId);
is($style->userStyle('userStyle'), 'USER PRINTABLE STYLE TEMPLATE:userStyle',
'userStyle returns templated output according to userFunctionStyleId in settings');
is($session->http->{_http}{cacheControl}, 'none', 'userStyle(via process): HTTP cacheControl set to none to prevent proxying');
is($session->http->getCacheControl, 'none', 'userStyle(via process): HTTP cacheControl set to none to prevent proxying');
is($style->userStyle('userStyle'), 'USER PRINTABLE STYLE TEMPLATE:userStyle',
'userStyle returns templated output according to userFunctionStyleId in settings');
@ -306,8 +306,7 @@ $head =~ s/(^HEAD=.+$)/$1/s;
cmp_bag(\@metas, $expectedMetas, 'process:default meta tags with no caching head tags, preventProxyCache setting');
$session->setting->set('preventProxyCache', $origPreventProxyCache);
##No accessor
is($session->http->{_http}{cacheControl}, 'none', 'process: HTTP cacheControl set to none to prevent proxying');
is($session->http->getCacheControl, 'none', 'process: HTTP cacheControl set to none to prevent proxying');
####################################################
#