split off stemma analysis modules from base Tradition layer
[scpubgit/stemmatology.git] / base / t / text_tradition_parser_self.t
CommitLineData
e867486f 1#!/usr/bin/perl -w
2
3use strict;
4use Test::More 'no_plan';
5$| = 1;
6
7
8
9# =begin testing
10{
9fef629b 11use File::Temp;
951ddfe8 12use Safe::Isa;
9fef629b 13use Test::Warn;
e867486f 14use Text::Tradition;
951ddfe8 15use TryCatch;
e867486f 16binmode STDOUT, ":utf8";
17binmode STDERR, ":utf8";
18eval { no warnings; binmode $DB::OUT, ":utf8"; };
19
20my $tradition = 't/data/florilegium_graphml.xml';
21my $t = Text::Tradition->new(
22 'name' => 'inline',
23 'input' => 'Self',
24 'file' => $tradition,
25 );
26
951ddfe8 27ok( $t->$_isa('Text::Tradition'), "Parsed GraphML version 2" );
e867486f 28if( $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 37my $stemma_enabled;
38try {
39 $stemma_enabled = $t->enable_stemmata;
40} catch {
41 ok( 1, "Skipping stemma tests without Analysis module" );
42}
43if( $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' } );
49ok( $t->collation->get_relationship( 'w12', 'w13' ), "Relationship set" );
50my $graphml_str = $t->collation->as_graphml;
51
52my $newt = Text::Tradition->new( 'input' => 'Self', 'string' => $graphml_str );
951ddfe8 53ok( $newt->$_isa('Text::Tradition'), "Parsed current GraphML version" );
bbd064a9 54if( $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
70my $fh = File::Temp->new();
71my $file = $fh->filename;
72$fh->close;
73my $dsn = "dbi:SQLite:dbname=$file";
1df4baa9 74my $userstore = Text::Tradition::Directory->new( { dsn => $dsn,
9fef629b 75 extra_args => { create => 1 } } );
76my $scope = $userstore->new_scope();
1df4baa9 77my $testuser = $userstore->create_user( { url => 'http://example.com' } );
951ddfe8 78ok( $testuser->$_isa('Text::Tradition::User'), "Created test user via userstore" );
9fef629b 79$testuser->add_tradition( $newt );
80is( $newt->user->id, $testuser->id, "Assigned tradition to test user" );
81$graphml_str = $newt->collation->as_graphml;
82my $usert;
83warning_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 89is( $usert->user->id, $testuser->id, "Parsed tradition with userstore points to correct user" );
951ddfe8 90
91# Test warning if we can
92unless( $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
1041;