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; |
951ddfe8 |
12 | use Safe::Isa; |
9fef629b |
13 | use Test::Warn; |
e867486f |
14 | use Text::Tradition; |
951ddfe8 |
15 | use TryCatch; |
e867486f |
16 | binmode STDOUT, ":utf8"; |
17 | binmode STDERR, ":utf8"; |
18 | eval { no warnings; binmode $DB::OUT, ":utf8"; }; |
19 | |
20 | my $tradition = 't/data/florilegium_graphml.xml'; |
21 | my $t = Text::Tradition->new( |
22 | 'name' => 'inline', |
23 | 'input' => 'Self', |
24 | 'file' => $tradition, |
25 | ); |
26 | |
951ddfe8 |
27 | ok( $t->$_isa('Text::Tradition'), "Parsed GraphML version 2" ); |
e867486f |
28 | if( $t ) { |
29 | is( scalar $t->collation->readings, 319, "Collation has all readings" ); |
255875b8 |
30 | is( scalar $t->collation->paths, 376, "Collation has all paths" ); |
e867486f |
31 | is( scalar $t->witnesses, 13, "Collation has all witnesses" ); |
32 | } |
bbd064a9 |
33 | |
2a812726 |
34 | # TODO add a relationship, add a stemma, write graphml, reparse it, check that |
35 | # the new data is there |
bbd064a9 |
36 | $t->language('Greek'); |
951ddfe8 |
37 | my $stemma_enabled; |
38 | try { |
39 | $stemma_enabled = $t->enable_stemmata; |
40 | } catch { |
41 | ok( 1, "Skipping stemma tests without Analysis module" ); |
42 | } |
43 | if( $stemma_enabled ) { |
44 | $t->add_stemma( 'dotfile' => 't/data/florilegium.dot' ); |
45 | } |
bbd064a9 |
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; |
51 | |
52 | my $newt = Text::Tradition->new( 'input' => 'Self', 'string' => $graphml_str ); |
951ddfe8 |
53 | ok( $newt->$_isa('Text::Tradition'), "Parsed current GraphML version" ); |
bbd064a9 |
54 | if( $newt ) { |
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" ); |
951ddfe8 |
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" ); |
66 | } |
bbd064a9 |
67 | } |
9fef629b |
68 | |
69 | # Test user save / restore |
70 | my $fh = File::Temp->new(); |
71 | my $file = $fh->filename; |
72 | $fh->close; |
73 | my $dsn = "dbi:SQLite:dbname=$file"; |
1df4baa9 |
74 | my $userstore = Text::Tradition::Directory->new( { dsn => $dsn, |
9fef629b |
75 | extra_args => { create => 1 } } ); |
76 | my $scope = $userstore->new_scope(); |
1df4baa9 |
77 | my $testuser = $userstore->create_user( { url => 'http://example.com' } ); |
951ddfe8 |
78 | ok( $testuser->$_isa('Text::Tradition::User'), "Created test user via userstore" ); |
9fef629b |
79 | $testuser->add_tradition( $newt ); |
80 | is( $newt->user->id, $testuser->id, "Assigned tradition to test user" ); |
81 | $graphml_str = $newt->collation->as_graphml; |
82 | my $usert; |
83 | warning_is { |
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, |
1df4baa9 |
88 | 'userstore' => $userstore ); |
9fef629b |
89 | is( $usert->user->id, $testuser->id, "Parsed tradition with userstore points to correct user" ); |
951ddfe8 |
90 | |
91 | # Test warning if we can |
92 | unless( $stemma_enabled ) { |
93 | my $nst; |
94 | warnings_exist { |
95 | $nst = Text::Tradition->new( 'input' => 'Self', 'file' => 't/data/lexformat.xml' ); |
96 | } [qr/DROPPING stemmata/], |
97 | "Got expected stemma drop warning on parse"; |
98 | } |
e867486f |
99 | } |
100 | |
101 | |
102 | |
103 | |
104 | 1; |