Commit | Line | Data |
12523041 |
1 | #!/usr/bin/perl -w |
2 | |
3 | use strict; |
4 | use Test::More 'no_plan'; |
5 | $| = 1; |
6 | |
7 | |
8 | |
9 | # =begin testing |
10 | { |
56cf65bd |
11 | use Test::Warn; |
12523041 |
12 | use File::Temp; |
13 | use Text::Tradition; |
12523041 |
14 | use_ok 'Text::Tradition::Directory'; |
15 | |
16 | my $fh = File::Temp->new(); |
17 | my $file = $fh->filename; |
18 | $fh->close; |
19 | my $dsn = "dbi:SQLite:dbname=$file"; |
20 | |
21 | my $d = Text::Tradition::Directory->new( 'dsn' => $dsn, |
56cf65bd |
22 | 'extra_args' => { 'create' => 1 } ); |
12523041 |
23 | is( ref $d, 'Text::Tradition::Directory', "Got directory object" ); |
24 | |
56cf65bd |
25 | my $scope = $d->new_scope; |
12523041 |
26 | my $t = Text::Tradition->new( |
56cf65bd |
27 | 'name' => 'inline', |
28 | 'input' => 'Tabular', |
29 | 'file' => 't/data/simple.txt', |
30 | ); |
31 | my $uuid = $d->save( $t ); |
12523041 |
32 | ok( $uuid, "Saved test tradition" ); |
33 | |
56cf65bd |
34 | my $s = $t->add_stemma( 't/data/simple.dot' ); |
35 | ok( $d->save( $t ), "Updated tradition with stemma" ); |
12523041 |
36 | is( $d->tradition( $uuid ), $t, "Correct tradition returned for id" ); |
56cf65bd |
37 | is( $d->tradition( $uuid )->stemma, $s, "...and it has the correct stemma" ); |
38 | warning_like { $d->save( $s ) } qr/not a Text::Tradition/, "Correctly failed to save stemma directly"; |
12523041 |
39 | |
12523041 |
40 | my $e = Text::Tradition::Directory->new( 'dsn' => $dsn ); |
56cf65bd |
41 | $scope = $e->new_scope; |
42 | is( scalar $e->tradition_ids, 1, "Directory index has our tradition" ); |
12523041 |
43 | my $te = $e->tradition( $uuid ); |
56cf65bd |
44 | is( $te->name, $t->name, "Retrieved the tradition from a new directory" ); |
45 | my $sid = $e->object_to_id( $te->stemma ); |
46 | warning_like { $e->tradition( $sid ) } qr/not a Text::Tradition/, "Did not retrieve stemma via tradition call"; |
47 | warning_like { $e->delete( $sid ) } qr/Cannot directly delete non-Tradition object/, "Stemma object not deleted from DB"; |
48 | $e->delete( $uuid ); |
49 | ok( !$e->exists( $uuid ), "Object is deleted from DB" ); |
ad1291ee |
50 | ok( !$e->exists( $sid ), "Object stemma also deleted from DB" ); |
56cf65bd |
51 | is( scalar $e->tradition_ids, 0, "Object is deleted from index" ); |
12523041 |
52 | } |
53 | |
54 | |
55 | |
56 | |
57 | 1; |