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