Update AssetExportHtml test to match new API for 7.7

This commit is contained in:
Colin Kuskie 2009-05-21 16:02:37 +00:00
parent 1e52f21fcb
commit d3a874dd36

View file

@ -41,7 +41,7 @@ my $originalExportPath = $session->config->get('exportPath');
my $testRan = 1;
plan tests => 144; # Increment this number for each test you create
plan tests => 126; # Increment this number for each test you create
#----------------------------------------------------------------------------
# exportCheckPath()
@ -262,7 +262,7 @@ isa_ok($gcAsPath, 'Path::Class::File', 'exportGetUrlAsPath for grandchild return
is($gcAsPath->absolute($exportPath)->stringify, $litmus->absolute($exportPath)->stringify, "exportGetUrlAsPath for grandchild works for root directory");
# without index.html
my $gcAsPath = $grandChild->exportGetUrlAsPath();
$gcAsPath = $grandChild->exportGetUrlAsPath();
$litmus = Path::Class::File->new($exportPath, $grandChild->getUrl, 'index.html');
isa_ok($gcAsPath, 'Path::Class::File', 'exportGetUrlAsPath for grandchild without index file returns a Path::Class::File object');
is($gcAsPath->absolute($exportPath)->stringify, $litmus->absolute($exportPath)->stringify, "exportGetUrlAsPath for grandchild without index file works for root directory");
@ -672,7 +672,7 @@ $session->user( { userId => 3 } );
# in other words, we need to test that the ultimate results of calling
# exportAsHtml are what they should be, given the inputs we provide.
my (@createdFiles, @shouldExist, $success, $message);
my $exportPath = Path::Class::Dir->new($session->config->get('exportPath'));
$exportPath = Path::Class::Dir->new($session->config->get('exportPath'));
# first things first. let's make sure the code checks for the proper arguments.
# quiet is optional, so don't test that. userId is a bit smart and will take
@ -699,24 +699,22 @@ eval { $message = $home->exportAsHtml( { userId => 3, depth => 99, extrasUploadA
is($@, "'o hai' is not a valid extrasUploadAction", "exportAsHtml throws correct error when given bogus, memetic extrasUploadAction parameter");
# rootUrlAction
($success, $message) = $home->exportAsHtml( { userId => 3, depth => 99, rootUrlAction => 'NO U' } );
is($success, 0, "exportAsHtml returns 0 when given bogus, memetic rootUrlAction parameter");
is($message, "'NO U' is not a valid rootUrlAction", "exportAsHtml returns correct message when given bogus, memetic extrasUploadAction parameter");
eval { $message = $home->exportAsHtml( { userId => 3, depth => 99, rootUrlAction => 'NO U' } ) };
is($@, "'NO U' is not a valid rootUrlAction", "exportAsHtml throws correct error when given bogus, memetic extrasUploadAction parameter");
# finally, depth
($success, $message) = $home->exportAsHtml( { userId => 3 } );
is($success, 0, "exportAsHtml returns 0 when not given depth");
is($message, "need a depth", "exportAsHtml returns correct message when not given a depth");
eval { $message = $home->exportAsHtml( { userId => 3 } ) };
is($@, "need a depth", "exportAsHtml throws correct error when not given a depth");
($success, $message) = $home->exportAsHtml( { userId => 3, depth => 'orly? yarly!' } );
is($success, 0, "exportAsHtml returns 0 when given bogus, memetic depth");
is($message, "orly? yarly! is not a valid depth", "exportAsHtml returns correct message when given bogus, memetic depth");
eval { $message = $home->exportAsHtml( { userId => 3, depth => 'orly? yarly!' } ) };
is($@, "orly? yarly! is not a valid depth", "exportAsHtml throws correct error when given bogus, memetic depth");
# next, let's make sure some simple exports work. export 'home', but clean up
# the exportPath first to make sure there are no residuals from the tests
# above.
$exportPath->rmtree;
($success, $message) = $home->exportAsHtml( { userId => 3, depth => 99, quiet => 1 } );
eval { $message = $home->exportAsHtml( { userId => 3, depth => 99, quiet => 1 } ) };
is($@, '', "exportAsHtml on home does not throw an error"); ##Note, string comparison
# list of files that should exist. obtained by running previous known working
# export function on a full stock asset tree
@ -750,6 +748,7 @@ $exportPath->rmtree;
);
my $numberCreatedAll = scalar @createdFiles;
like($message, qr/Exported $numberCreatedAll pages/, "exportAsHtml on home returns correct message");
push @createdFiles,
[ qw/ the_latest_news the_latest_news.atom /],
[ qw/ the_latest_news the_latest_news.rss /],
@ -757,21 +756,19 @@ push @createdFiles,
;
# turn them into Path::Class::File objects
my @shouldExist = map { Path::Class::File->new($exportPath, @{$_})->absolute->stringify } @createdFiles;
@shouldExist = map { Path::Class::File->new($exportPath, @{$_})->absolute->stringify } @createdFiles;
# ensure that the files that should exist do exist
my @doExist;
$exportPath->recurse( callback => sub { my $o = shift; $o->is_dir ? return : push @doExist, $o->absolute->stringify } );
cmp_bag(\@doExist, \@shouldExist, "exportAsHtml on home writes correct files");
is($success, 1, "exportAsHtml on home returns true");
like($message, qr/Exported $numberCreatedAll pages/, "exportAsHtml on home returns correct message");
$exportPath->rmtree;
@doExist = ();
# previous tests ensure that the contents of the exported files are right. so
# let's go a level deeper and ensure that the right files are present.
($success, $message) = $gettingStarted->exportAsHtml( { userId => 3, depth => 99, quiet => 1 } );
eval { ($message) = $gettingStarted->exportAsHtml( { userId => 3, depth => 99, quiet => 1 } ) };
@createdFiles = (
[ qw/ getting_started getting-started index.html /],
[ qw/ getting_started getting-started-part2 index.html /],
@ -781,15 +778,15 @@ $exportPath->rmtree;
@shouldExist = map { Path::Class::File->new($exportPath, @{$_})->absolute->stringify } @createdFiles;
$exportPath->recurse( callback => sub { my $o = shift; $o->is_dir ? return : push @doExist, $o->absolute->stringify } );
cmp_deeply([sort @doExist], [sort @shouldExist], "exportAsHtml on getting-started writes correct files");
is($success, 1, "exportAsHtml on getting-started returns true");
like($message, qr/Exported 4 pages/, "exportAsHtml on getting-started returns correct message");
is($@, '', 'exportAsHtml on getting-started page does not throw an exception');
cmp_bag(\@doExist, \@shouldExist, "... writes correct files");
like($message, qr/Exported 4 pages/, "... returns correct message");
$exportPath->rmtree;
@doExist = ();
# test the grandchild.
($success, $message) = $grandChild->exportAsHtml( { userId => 3, depth => 99, quiet => 1 } );
eval { ($message) = $grandChild->exportAsHtml( { userId => 3, depth => 99, quiet => 1 } ) };
@createdFiles = (
[ qw/ getting_started getting-started index.html /],
);
@ -797,9 +794,9 @@ $exportPath->rmtree;
@shouldExist = map { Path::Class::File->new($exportPath, @{$_})->absolute->stringify } @createdFiles;
$exportPath->recurse( callback => sub { my $o = shift; $o->is_dir ? return : push @doExist, $o->absolute->stringify } );
cmp_deeply(sort @shouldExist, sort @doExist, "exportAsHtml on grandchild writes correct files");
is($success, 1, "exportAsHtml on grandchild returns true");
like($message, qr/Exported 1 pages/, "exportAsHtml on grandchild returns correct message");
is($@, '', 'exportAsHtml on grandchild does not throw an exception');
cmp_bag(\@shouldExist, \@doExist, "... writes correct files");
like($message, qr/Exported 1 pages/, "... returns correct message");
$exportPath->rmtree;
@doExist = ();
@ -807,12 +804,12 @@ $exportPath->rmtree;
# fiddle with the isExportable setting and make sure appropriate files are
# written
$home->update({ isExportable => 0 });
($success, $message) = $home->exportAsHtml( { userId => 3, depth => 99, quiet => 1 } );
eval { ($message) = $home->exportAsHtml( { userId => 3, depth => 99, quiet => 1 } ) };
@shouldExist = ();
is(@shouldExist, @doExist, "exportAsHtml on nonexportable home doesn't write anything");
is($success, 1, "exportAsHtml on nonexportable home returns true (but doesn't do anything)");
like($message, qr/Exported 0 pages/, "exportAsHtml on nonexportable home returns correct message");
is($@, '', 'exportAsHtml on nonexportable home does not throw an exception');
is(@shouldExist, @doExist, "... doesn't write anything");
like($message, qr/Exported 0 pages/, "... returns correct message");
# restore the original setting
$home->update({ isExportable => 1 });
@ -825,7 +822,7 @@ $exportPath->rmtree;
@doExist = ();
$gettingStarted->update({ isExportable => 0 });
($success, $message) = $home->exportAsHtml( { userId => 3, depth => 99, quiet => 1 } );
eval { ($message) = $home->exportAsHtml( { userId => 3, depth => 99, quiet => 1 } ) };
# since getting-started isn't exportable, it shouldn't be written. remove it
# and its descendants from the list.
@ -864,9 +861,9 @@ push @createdFiles,
@shouldExist = map { Path::Class::File->new($exportPath, @{$_})->absolute->stringify } @createdFiles;
$exportPath->recurse( callback => sub { my $o = shift; $o->is_dir ? return : push @doExist, $o->absolute->stringify } );
cmp_bag(\@doExist, \@shouldExist, "exportAsHtml on home with non-exportable getting-started writes correct files");
is($success, 1, "exportAsHtml on home with non-exportable getting-started returns true");
like($message, qr/Exported $numberCreated pages/, "exportAsHtml on home with non-exportable getting-started returns correct message");
is($@, '', 'exportAsHtml on home with non-exportable getting-started writes correct files');
cmp_bag(\@doExist, \@shouldExist, "... writes correct files");
like($message, qr/Exported $numberCreated pages/, "... returns correct message");
# restore the original setting
$gettingStarted->update({ isExportable => 1 });
@ -904,10 +901,8 @@ $exportPath->rmtree;
$config->delete('exportPath');
# undefined exportPath
eval { ($success, $message) = $home->exportAsHtml( { userId => 3, depth => 99 } ) };
is($@, '', "exportAsHtml catches undefined exportPath exception");
is($success, 0, "exportAsHtml returns 0 for undefined exportPath");
is($message, 'exportPath must be defined and not ""', "exportAsHtml returns correct message for undefined exportPath");
eval { ($message) = $home->exportAsHtml( { userId => 3, depth => 99 } ) };
is($@, 'exportPath must be defined and not ""', "exportAsHtml catches undefined exportPath exception");
SKIP: {
skip 'Root will cause this test to fail since it does not obey file permissions', 3
@ -917,19 +912,15 @@ SKIP: {
chmod 0000, $tempDirectory;
$config->set('exportPath', $inaccessibleDirectory->stringify);
eval { ($success, $message) = $home->exportAsHtml( { userId => 3, depth => 99 } ) };
is($@, '', "exportAsHtml catches inaccessible exportPath ");
is($success, 0, "exportAsHtml returns 0 for inaccessible exportPath");
is($message, "can't create exportPath " . $inaccessibleDirectory->stringify, "exportAsHtml returns correct message for inaccessible exportPath");
eval { ($message) = $home->exportAsHtml( { userId => 3, depth => 99 } ) };
is($@, "can't create exportPath " . $inaccessibleDirectory->stringify, "exportAsHtml catches inaccessible exportPath ");
}
# exportPath is a file, not a directory
$config->set('exportPath', $exportPathFile);
eval { ($success, $message) = $home->exportAsHtml( { userId => 3, depth => 99 } ) };
is($@, '', "exportAsHtml catches exportPath is file exception");
is($success, 0, "exportAsHtml returns 0 if exportPath is a file");
is($message, "$exportPathFile isn't a directory", "exportAsHtml returns correct message if exportPath is a file");
eval { ($message) = $home->exportAsHtml( { userId => 3, depth => 99 } ) };
is($@, "$exportPathFile isn't a directory", "exportAsHtml catches exportPath is file exception");
$config->set('exportPath', $inaccessibleDirectory->stringify);
SKIP: {
@ -939,10 +930,8 @@ SKIP: {
# can't create export path
chmod 0000, $tempDirectory;
eval { ($success, $message) = $home->exportAsHtml( { userId => 3, depth => 99 } ) };
is($@, '', "exportAsHtml catches uncreatable exportPath exception");
is($success, 0, "exportAsHtml returns 0 for uncreatable exportPath");
is($message, "can't create exportPath $inaccessibleDirectory", "exportAsHtml returns correct message for uncreatable exportPath");
eval { ($message) = $home->exportAsHtml( { userId => 3, depth => 99 } ) };
is($@, "can't create exportPath $inaccessibleDirectory", "exportAsHtml catches uncreatable exportPath exception");
}
# user can't view asset
@ -950,10 +939,8 @@ $home->update( { groupIdView => 3 } );
$session->http->setNoHeader(1);
chmod 0755, $tempDirectory;
eval { ($success, $message) = $home->exportAsHtml( { userId => 1, depth => 99 } ) };
is($@, '', "exportAsHtml catches unviewable asset exception");
is($success, 0, "exportAsHtml returns 0 for unviewable asset");
is($message, "can't view asset at URL /home", "exportAsHtml returns correct message for unviewable asset");
eval { ($message) = $home->exportAsHtml( { userId => 1, depth => 99 } ) };
is($@, "can't view asset at URL /home", "exportAsHtml catches unviewable asset exception");
# fix viewing the asset
$home->update( { groupIdView => 7 } );
@ -973,10 +960,10 @@ $uploadsUrl = $config->get('uploadsURL');
$exportPath->rmtree;
($success, $message) = $home->exportAsHtml( { userId => 3, depth => 99, extrasUploadAction => 'symlink', quiet => 1 } );
eval { ($message) = $home->exportAsHtml( { userId => 3, depth => 99, extrasUploadAction => 'symlink', quiet => 1 } ) };
is($success, 1, "exportAsHtml when linking extras and uploads returns true");
like($message, qr/Exported $numberCreatedAll pages/, "exportAsHtml when linking extras and uploads returns correct message");
is($@, '', "exportAsHtml when linking extras and uploads does not throw an exception");
like($message, qr/Exported $numberCreatedAll pages/, "... returns correct message");
$extrasSymlink = Path::Class::File->new($exportPath, $extrasUrl);
$uploadsSymlink = Path::Class::File->new($exportPath, $uploadsUrl);
@ -988,12 +975,12 @@ ok(-e $uploadsSymlink->absolute->stringify, "exportAsHtml wr
is($uploadsPath, readlink $uploadsSymlink->absolute->stringify, "exportAsHtml uploads symlink points to right place");
# next, make sure the root URL symlinking works.
($success, $message) = $home->exportAsHtml( { userId => 3, depth => 99, rootUrlAction => 'symlink', quiet => 1 } );
eval { ($message) = $home->exportAsHtml( { userId => 3, depth => 99, rootUrlAction => 'symlink', quiet => 1 } ) };
my $rootUrlSymlink = Path::Class::File->new($exportPath, 'index.html');
is($success, 1, 'exportAsHtml when linking root URL returns true');
like($message, qr/Exported $numberCreatedAll pages/, "exportAsHtml when linking root URL returns correct message");
ok(-e $rootUrlSymlink->absolute->stringify, "exportAsHtml writes root URL symlink");
is($home->exportGetUrlAsPath->absolute->stringify, readlink $rootUrlSymlink->absolute->stringify, "exportAsHtml root URL symlink points to right place");
is($@, '', 'exportAsHtml does not throw an error when linking root URL');
like($message, qr/Exported $numberCreatedAll pages/, "... returns correct message");
ok(-e $rootUrlSymlink->absolute->stringify, "... writes root URL symlink");
is($home->exportGetUrlAsPath->absolute->stringify, readlink $rootUrlSymlink->absolute->stringify, "... root URL symlink points to right place");
#----------------------------------------------------------------------------