X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Flib%2Fstemmaweb%2FTest%2FDB.pm;fp=t%2Flib%2Fstemmaweb%2FTest%2FDB.pm;h=6bad65984410bc97c0caf982440e944e2025873f;hb=325d9f4176bba1c6811c031a75be3ef5eced7c94;hp=0000000000000000000000000000000000000000;hpb=fb45a11f36674bff7cdff20f383fddfdfc4298b7;p=scpubgit%2Fstemmaweb.git diff --git a/t/lib/stemmaweb/Test/DB.pm b/t/lib/stemmaweb/Test/DB.pm new file mode 100644 index 0000000..6bad659 --- /dev/null +++ b/t/lib/stemmaweb/Test/DB.pm @@ -0,0 +1,50 @@ +package stemmaweb::Test::DB; + +use warnings; +use strict; + +use FindBin; + +sub new_db { + my $DBDIR = "$FindBin::Bin/db"; + my $DBNAME = 'traditions.db'; + my $DBEXT = 'test'; + + # Make the directory on the filesystem if necessary + unless( -d $DBDIR ) { + mkdir $DBDIR + or die "Could not make database director $DBDIR"; + } + # Delete the old db if it exists + if( -f "$DBDIR/$DBNAME.$DBEXT" ) { + unlink( "$DBDIR/$DBNAME.$DBEXT" ); + } + if( -l "$DBDIR/$DBNAME" ) { + unlink( "$DBDIR/$DBNAME" ); + } elsif( -e "$DBDIR/$DBNAME" ) { + unlink( "$DBDIR/$DBNAME.bak" ) if -f "$DBDIR/$DBNAME.bak"; + rename( "$DBDIR/$DBNAME", "$DBDIR/$DBNAME.bak" ) + or die "Could not rename existing $DBNAME"; + } + + # Set up the test directory + symlink( "$DBNAME.$DBEXT", "$DBDIR/$DBNAME" ) or die "Could not set up testing db symlink"; + + my $dir = Text::Tradition::Directory->new( + dsn => "dbi:SQLite:dbname=$DBDIR/$DBNAME", + extra_args => { create => 1 } + ); + my $scope = $dir->new_scope(); + + # Create users + my $user = $dir->add_user({ username => 'user@example.org', password => 'UserPass' }); + + + my $t2 = Text::Tradition->new( input => 'Tabular', sep_char => ',', + file => 't/data/florilegium.csv' ); + $t2->add_stemma( dotfile => 't/data/florilegium.dot' ); + + $user->add_tradition($t2); +} + +1;