Commit | Line | Data |
9a3fb143 |
1 | #!/usr/bin/env perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | use feature 'say'; |
6 | use Text::Tradition; |
7 | use Text::Tradition::Directory; |
8 | |
9 | my $DBDIR = 'db'; |
10 | my $DBNAME = 'traditions.db'; |
11 | my $DBEXT = 'test'; |
bfaf51f3 |
12 | # Make the directory on the filesystem if necessary |
13 | unless( -d $DBDIR ) { |
14 | mkdir $DBDIR |
15 | or die "Could not make database director $DBDIR"; |
16 | say "Created directory for test database"; |
17 | } |
18 | # Delete the old db if it exists |
9a3fb143 |
19 | if( -f "$DBDIR/$DBNAME.$DBEXT" ) { |
20 | unlink( "$DBDIR/$DBNAME.$DBEXT" ); |
21 | } |
22 | if( -l "$DBDIR/$DBNAME" ) { |
23 | unlink( "$DBDIR/$DBNAME" ); |
24 | } elsif( -e "$DBDIR/$DBNAME" ) { |
25 | unlink( "$DBDIR/$DBNAME.bak" ) if -f "$DBDIR/$DBNAME.bak"; |
26 | rename( "$DBDIR/$DBNAME", "$DBDIR/$DBNAME.bak" ) |
27 | or die "Could not rename existing $DBNAME"; |
28 | } |
29 | # Set up the test directory |
30 | symlink( "$DBNAME.$DBEXT", "$DBDIR/$DBNAME" ) or die "Could not set up testing db symlink"; |
31 | |
32 | my $dir = Text::Tradition::Directory->new( |
33 | dsn => "dbi:SQLite:dbname=$DBDIR/$DBNAME", |
34 | extra_args => { create => 1 } |
35 | ); |
36 | my $scope = $dir->new_scope(); |
bfaf51f3 |
37 | say "Created test database"; |
9a3fb143 |
38 | |
39 | # Create users |
40 | my $user = $dir->add_user({ username => 'user@example.org', password => 'UserPass' }); |
41 | my $admin = $dir->add_user({ username => 'admin@example.org', |
42 | password => 'AdminPass', role => 'admin' }); |
43 | die "Failed to create test users" unless $user && $admin; |
44 | say "Created users"; |
45 | |
46 | my $t1 = Text::Tradition->new( input => 'Self', file => 't/data/besoin.xml' ); |
47 | die "Failed to create test tradition #1" unless $t1; |
532cc23b |
48 | $t1->add_stemma( dotfile => 't/data/besoin_stemweb.dot' ); |
9a3fb143 |
49 | $user->add_tradition( $t1 ); |
50 | $dir->store( $user ); |
51 | say "Created test user tradition"; |
52 | |
53 | my $t2 = Text::Tradition->new( input => 'Tabular', sep_char => ',', |
54 | file => 't/data/florilegium.csv' ); |
55 | $t2->add_stemma( dotfile => 't/data/florilegium.dot' ); |
56 | die "Failed to create test tradition #2" unless $t2; |
57 | $t2->public( 1 ); |
58 | $dir->store( $t2 ); |
56e3972e |
59 | my $t3 = Text::Tradition->new( input => 'Self', file => 't/data/john.xml' ); |
60 | $t3->public( 1 ); |
61 | $t3->name( 'John verse' ); |
62 | $dir->store( $t3 ); |
2d6431a4 |
63 | my $t4 = Text::Tradition->new( input => 'Self', file => 't/data/collatecorr.xml' ); |
64 | $t4->public( 1 ); |
65 | $user->add_tradition( $t4 ); |
66 | $dir->store( $t4 ); |
67 | $dir->store( $user ); |
68 | |
56e3972e |
69 | say "Created test public traditions"; |
9a3fb143 |
70 | |