Commit | Line | Data |
e867486f |
1 | #!/usr/bin/perl -w |
2 | |
3 | use strict; |
4 | use Test::More 'no_plan'; |
5 | $| = 1; |
6 | |
7 | |
8 | |
9 | # =begin testing |
10 | { |
9fef629b |
11 | use File::Temp; |
12 | use Test::Warn; |
e867486f |
13 | use Text::Tradition; |
14 | binmode STDOUT, ":utf8"; |
15 | binmode STDERR, ":utf8"; |
16 | eval { no warnings; binmode $DB::OUT, ":utf8"; }; |
17 | |
18 | my $tradition = 't/data/florilegium_graphml.xml'; |
19 | my $t = Text::Tradition->new( |
20 | 'name' => 'inline', |
21 | 'input' => 'Self', |
22 | 'file' => $tradition, |
23 | ); |
24 | |
bbd064a9 |
25 | is( ref( $t ), 'Text::Tradition', "Parsed GraphML version 2" ); |
e867486f |
26 | if( $t ) { |
27 | is( scalar $t->collation->readings, 319, "Collation has all readings" ); |
255875b8 |
28 | is( scalar $t->collation->paths, 376, "Collation has all paths" ); |
e867486f |
29 | is( scalar $t->witnesses, 13, "Collation has all witnesses" ); |
30 | } |
bbd064a9 |
31 | |
2a812726 |
32 | # TODO add a relationship, add a stemma, write graphml, reparse it, check that |
33 | # the new data is there |
bbd064a9 |
34 | $t->language('Greek'); |
2a812726 |
35 | $t->add_stemma( 'dotfile' => 't/data/florilegium.dot' ); |
bbd064a9 |
36 | $t->collation->add_relationship( 'w12', 'w13', |
37 | { 'type' => 'grammatical', 'scope' => 'global', |
38 | 'annotation' => 'This is some note' } ); |
39 | ok( $t->collation->get_relationship( 'w12', 'w13' ), "Relationship set" ); |
40 | my $graphml_str = $t->collation->as_graphml; |
41 | |
42 | my $newt = Text::Tradition->new( 'input' => 'Self', 'string' => $graphml_str ); |
43 | is( ref( $newt ), 'Text::Tradition', "Parsed current GraphML version" ); |
44 | if( $newt ) { |
45 | is( scalar $newt->collation->readings, 319, "Collation has all readings" ); |
46 | is( scalar $newt->collation->paths, 376, "Collation has all paths" ); |
47 | is( scalar $newt->witnesses, 13, "Collation has all witnesses" ); |
48 | is( scalar $newt->collation->relationships, 1, "Collation has added relationship" ); |
49 | is( $newt->language, 'Greek', "Tradition has correct language setting" ); |
50 | my $rel = $newt->collation->get_relationship( 'w12', 'w13' ); |
51 | ok( $rel, "Found set relationship" ); |
52 | is( $rel->annotation, 'This is some note', "Relationship has its properties" ); |
2a812726 |
53 | is( scalar $newt->stemmata, 1, "Tradition has its stemma" ); |
54 | is( $newt->stemma(0)->witnesses, $t->stemma(0)->witnesses, "Stemma has correct length witness list" ); |
bbd064a9 |
55 | } |
9fef629b |
56 | |
57 | # Test user save / restore |
58 | my $fh = File::Temp->new(); |
59 | my $file = $fh->filename; |
60 | $fh->close; |
61 | my $dsn = "dbi:SQLite:dbname=$file"; |
62 | my $userstore = Text::Tradition::UserStore->new( { dsn => $dsn, |
63 | extra_args => { create => 1 } } ); |
64 | my $scope = $userstore->new_scope(); |
65 | my $testuser = $userstore->add_user( { url => 'http://example.com' } ); |
66 | is( ref( $testuser ), 'Text::Tradition::User', "Created test user via userstore" ); |
67 | $testuser->add_tradition( $newt ); |
68 | is( $newt->user->id, $testuser->id, "Assigned tradition to test user" ); |
69 | $graphml_str = $newt->collation->as_graphml; |
70 | my $usert; |
71 | warning_is { |
72 | $usert = Text::Tradition->new( 'input' => 'Self', 'string' => $graphml_str ); |
73 | } 'DROPPING user assignment without a specified userstore', |
74 | "Got expected user drop warning on parse"; |
75 | $usert = Text::Tradition->new( 'input' => 'Self', 'string' => $graphml_str, |
76 | 'userstore' => { 'dsn' => $dsn } ); |
77 | is( $usert->user->id, $testuser->id, "Parsed tradition with userstore points to correct user" ); |
e867486f |
78 | } |
79 | |
80 | |
81 | |
82 | |
83 | 1; |