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