4 use Test::More 'no_plan';
16 binmode STDOUT, ":utf8";
17 binmode STDERR, ":utf8";
18 eval { no warnings; binmode $DB::OUT, ":utf8"; };
20 my $tradition = 't/data/florilegium_graphml.xml';
21 my $t = Text::Tradition->new(
27 ok( $t->$_isa('Text::Tradition'), "Parsed GraphML version 2" );
29 is( scalar $t->collation->readings, 319, "Collation has all readings" );
30 is( scalar $t->collation->paths, 376, "Collation has all paths" );
31 is( scalar $t->witnesses, 13, "Collation has all witnesses" );
34 # TODO add a relationship, add a stemma, write graphml, reparse it, check that
35 # the new data is there
36 $t->language('Greek');
39 $stemma_enabled = $t->enable_stemmata;
41 ok( 1, "Skipping stemma tests without Analysis module" );
43 if( $stemma_enabled ) {
44 $t->add_stemma( 'dotfile' => 't/data/florilegium.dot' );
46 $t->collation->add_relationship( 'w12', 'w13',
47 { 'type' => 'grammatical', 'scope' => 'global',
48 'annotation' => 'This is some note' } );
49 ok( $t->collation->get_relationship( 'w12', 'w13' ), "Relationship set" );
50 my $graphml_str = $t->collation->as_graphml;
52 my $newt = Text::Tradition->new( 'input' => 'Self', 'string' => $graphml_str );
53 ok( $newt->$_isa('Text::Tradition'), "Parsed current GraphML version" );
55 is( scalar $newt->collation->readings, 319, "Collation has all readings" );
56 is( scalar $newt->collation->paths, 376, "Collation has all paths" );
57 is( scalar $newt->witnesses, 13, "Collation has all witnesses" );
58 is( scalar $newt->collation->relationships, 1, "Collation has added relationship" );
59 is( $newt->language, 'Greek', "Tradition has correct language setting" );
60 my $rel = $newt->collation->get_relationship( 'w12', 'w13' );
61 ok( $rel, "Found set relationship" );
62 is( $rel->annotation, 'This is some note', "Relationship has its properties" );
63 if( $stemma_enabled ) {
64 is( scalar $newt->stemmata, 1, "Tradition has its stemma" );
65 is( $newt->stemma(0)->witnesses, $t->stemma(0)->witnesses, "Stemma has correct length witness list" );
69 # Test user save / restore
70 my $fh = File::Temp->new();
71 my $file = $fh->filename;
73 my $dsn = "dbi:SQLite:dbname=$file";
74 my $userstore = Text::Tradition::Directory->new( { dsn => $dsn,
75 extra_args => { create => 1 } } );
76 my $scope = $userstore->new_scope();
77 my $testuser = $userstore->create_user( { url => 'http://example.com' } );
78 ok( $testuser->$_isa('Text::Tradition::User'), "Created test user via userstore" );
79 $testuser->add_tradition( $newt );
80 is( $newt->user->id, $testuser->id, "Assigned tradition to test user" );
81 $graphml_str = $newt->collation->as_graphml;
84 $usert = Text::Tradition->new( 'input' => 'Self', 'string' => $graphml_str );
85 } 'DROPPING user assignment without a specified userstore',
86 "Got expected user drop warning on parse";
87 $usert = Text::Tradition->new( 'input' => 'Self', 'string' => $graphml_str,
88 'userstore' => $userstore );
89 is( $usert->user->id, $testuser->id, "Parsed tradition with userstore points to correct user" );
91 # Test warning if we can
92 unless( $stemma_enabled ) {
95 $nst = Text::Tradition->new( 'input' => 'Self', 'file' => 't/data/lexformat.xml' );
96 } [qr/DROPPING stemmata/],
97 "Got expected stemma drop warning on parse";