import and export users in GraphML
[scpubgit/stemmatology.git] / 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;
12use Test::Warn;
e867486f 13use Text::Tradition;
14binmode STDOUT, ":utf8";
15binmode STDERR, ":utf8";
16eval { no warnings; binmode $DB::OUT, ":utf8"; };
17
18my $tradition = 't/data/florilegium_graphml.xml';
19my $t = Text::Tradition->new(
20 'name' => 'inline',
21 'input' => 'Self',
22 'file' => $tradition,
23 );
24
bbd064a9 25is( ref( $t ), 'Text::Tradition', "Parsed GraphML version 2" );
e867486f 26if( $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' } );
39ok( $t->collation->get_relationship( 'w12', 'w13' ), "Relationship set" );
40my $graphml_str = $t->collation->as_graphml;
41
42my $newt = Text::Tradition->new( 'input' => 'Self', 'string' => $graphml_str );
43is( ref( $newt ), 'Text::Tradition', "Parsed current GraphML version" );
44if( $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
58my $fh = File::Temp->new();
59my $file = $fh->filename;
60$fh->close;
61my $dsn = "dbi:SQLite:dbname=$file";
62my $userstore = Text::Tradition::UserStore->new( { dsn => $dsn,
63 extra_args => { create => 1 } } );
64my $scope = $userstore->new_scope();
65my $testuser = $userstore->add_user( { url => 'http://example.com' } );
66is( ref( $testuser ), 'Text::Tradition::User', "Created test user via userstore" );
67$testuser->add_tradition( $newt );
68is( $newt->user->id, $testuser->id, "Assigned tradition to test user" );
69$graphml_str = $newt->collation->as_graphml;
70my $usert;
71warning_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 } );
77is( $usert->user->id, $testuser->id, "Parsed tradition with userstore points to correct user" );
e867486f 78}
79
80
81
82
831;