ef5fc879480711486744e0df0363a014986c8784
[scpubgit/stemmatology.git] / persistence / t / userrestore.t
1 #!/usr/bin/env perl;
2
3 use strict;
4 use warnings;
5 use File::Temp;
6 use Safe::Isa;
7 use Test::More;
8 use Test::Warn;
9 use Text::Tradition;
10 use Text::Tradition::Directory;
11
12 my $newt = Text::Tradition->new( 'input' => 'Self', 
13         'file' => 't/data/florilegium_graphml.xml' );
14         
15 my $graphml = $newt->collation->as_graphml;
16 unlike( $graphml, qr/testuser/, "Test user name does not exist in GraphML yet" );
17
18 my $fh = File::Temp->new();
19 my $file = $fh->filename;
20 $fh->close;
21 my $dsn = "dbi:SQLite:dbname=$file";
22 my $userstore = Text::Tradition::Directory->new( { dsn => $dsn,
23         extra_args => { create => 1 } } );
24 my $scope = $userstore->new_scope();
25 my $testuser = $userstore->create_user( { url => 'http://example.com' } );
26 ok( $testuser->$_isa('Text::Tradition::User'), "Created test user via userstore" );
27 $testuser->add_tradition( $newt );
28 is( $newt->user->id, $testuser->id, "Assigned tradition to test user" );
29 my $graphml_str = $newt->collation->as_graphml;
30 my $usert;
31 warning_is {
32         $usert = Text::Tradition->new( 'input' => 'Self', 'string' => $graphml_str );
33 } 'DROPPING user assignment without a specified userstore',
34         "Got expected user drop warning on parse";
35 $usert = Text::Tradition->new( 'input' => 'Self', 'string' => $graphml_str,
36         'userstore' => $userstore );
37 is( $usert->user->id, $testuser->id, "Parsed tradition with userstore points to correct user" );
38
39 done_testing();