X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F01app.t;h=ac0b4f2e6b388fe10c37013139424691f8569d9e;hb=6979999624e6502df3590a0047c20e9158237742;hp=5d544b955adfaa3fbeae8c3460889ed3009caee2;hpb=69ac99fc59102911a65d9b21391af7fca3eada00;p=scpubgit%2Fstemmaweb.git diff --git a/t/01app.t b/t/01app.t index 5d544b9..ac0b4f2 100644 --- a/t/01app.t +++ b/t/01app.t @@ -1,10 +1,73 @@ #!/usr/bin/env perl use strict; use warnings; +use File::Temp; use Test::More; +use Text::Tradition::Directory; use Catalyst::Test 'stemmaweb'; -ok( request('/')->is_success, 'Request should succeed' ); +use vars qw( $orig_db, $was_link ); +my $textids; +my $dbfile = 'db/traditions.db'; +( $orig_db, $was_link, $textids ) = _make_testing_database(); + +ok( request('/')->is_success, 'Got root HTML' ); +ok( request('/directory')->is_success, 'Got the text directory' ); +ok( request('/text/' . $textids->{'public'} . '/info')->is_success, + 'Got information listing for public text' ); +is( request('/text/' . $textids->{'public'} . '/info')->code, 403, + 'Denied information listing for public text' ); + done_testing(); + + +sub _make_testing_database { + my $fh = File::Temp->new(); + my $file = $fh->filename; + $fh->unlink_on_destroy( 0 ); + $fh->close; + my $dsn = 'dbi:SQLite:dbname=' . $file; + my $dir = Text::Tradition::Directory->new( 'dsn' => $dsn, + 'extra_args' => { 'create' => 1 } ); + my $scope = $dir->new_scope; + + my $textids = {}; + # Create a (public) tradition + my $pubtrad = Text::Tradition->new( input => 'Self', file => 't/data/john.xml' ); + $textids->{'public'} = $dir->store( $pubtrad ); + + # Create a user + my $userobj = $dir->add_user( { username => 'swtest', password => 'swtestpass' } ); + # Create a tradition for the user + my $privtrad = Text::Tradition->new( input => 'Tabular', sep_char => ',' + file => 't/data/florilegium.csv', user => $userobj ); + $privtrad->add_stemma( dotfile => 't/data/florilegium.dot' ); + $textids->{'private'} = $dir->store( $privtrad ); + + ## Now replace the existing traditions database with the test one + my( $orig, $was_link ); + if( -l $dbfile ) { + $was_link = 1; + $orig = readlink( $dbfile ); + unlink( $dbfile ) or die "Could not replace database file $dbfile"; + } else { + my $suffix = '.backup.' . time(); + $orig = $dbfile.$suffix; + rename( $dbfile, $orig ) or die "Could not move database file $dbfile"; + } + link( $file, $dbfile ); + return( $orig, $was_link, $textids ); +} + +END { + # Restore the original database + unlink( readlink( $dbfile ) ); + unlink( $dbfile ); + if( $was_link ) { + link( $orig_db, $dbfile ); + } else { + rename( $orig_db, $dbfile ); + } +}