load extensions statically to avoid bad object wrapping interactions
[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;
a445ce40 15use Text::Tradition::Directory;
951ddfe8 16use TryCatch;
e867486f 17binmode STDOUT, ":utf8";
18binmode STDERR, ":utf8";
19eval { no warnings; binmode $DB::OUT, ":utf8"; };
20
21my $tradition = 't/data/florilegium_graphml.xml';
22my $t = Text::Tradition->new(
23 'name' => 'inline',
24 'input' => 'Self',
25 'file' => $tradition,
26 );
27
951ddfe8 28ok( $t->$_isa('Text::Tradition'), "Parsed GraphML version 2" );
e867486f 29if( $t ) {
30 is( scalar $t->collation->readings, 319, "Collation has all readings" );
255875b8 31 is( scalar $t->collation->paths, 376, "Collation has all paths" );
e867486f 32 is( scalar $t->witnesses, 13, "Collation has all witnesses" );
33}
bbd064a9 34
2a812726 35# TODO add a relationship, add a stemma, write graphml, reparse it, check that
36# the new data is there
bbd064a9 37$t->language('Greek');
37bf09f4 38my $stemma_enabled = $t->can('add_stemma');
951ddfe8 39if( $stemma_enabled ) {
40 $t->add_stemma( 'dotfile' => 't/data/florilegium.dot' );
41}
bbd064a9 42$t->collation->add_relationship( 'w12', 'w13',
43 { 'type' => 'grammatical', 'scope' => 'global',
44 'annotation' => 'This is some note' } );
45ok( $t->collation->get_relationship( 'w12', 'w13' ), "Relationship set" );
46my $graphml_str = $t->collation->as_graphml;
47
48my $newt = Text::Tradition->new( 'input' => 'Self', 'string' => $graphml_str );
951ddfe8 49ok( $newt->$_isa('Text::Tradition'), "Parsed current GraphML version" );
bbd064a9 50if( $newt ) {
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" );
951ddfe8 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" );
62 }
bbd064a9 63}
9fef629b 64
65# Test user save / restore
66my $fh = File::Temp->new();
67my $file = $fh->filename;
68$fh->close;
69my $dsn = "dbi:SQLite:dbname=$file";
1df4baa9 70my $userstore = Text::Tradition::Directory->new( { dsn => $dsn,
9fef629b 71 extra_args => { create => 1 } } );
72my $scope = $userstore->new_scope();
1df4baa9 73my $testuser = $userstore->create_user( { url => 'http://example.com' } );
951ddfe8 74ok( $testuser->$_isa('Text::Tradition::User'), "Created test user via userstore" );
9fef629b 75$testuser->add_tradition( $newt );
76is( $newt->user->id, $testuser->id, "Assigned tradition to test user" );
77$graphml_str = $newt->collation->as_graphml;
78my $usert;
79warning_is {
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,
1df4baa9 84 'userstore' => $userstore );
9fef629b 85is( $usert->user->id, $testuser->id, "Parsed tradition with userstore points to correct user" );
951ddfe8 86
87# Test warning if we can
88unless( $stemma_enabled ) {
89 my $nst;
90 warnings_exist {
91 $nst = Text::Tradition->new( 'input' => 'Self', 'file' => 't/data/lexformat.xml' );
92 } [qr/DROPPING stemmata/],
93 "Got expected stemma drop warning on parse";
94}
e867486f 95}
96
97
98
99
1001;