3c734b18e8facfbd6a4d470e318171e32ba94d87
[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 $fh = File::Temp->new();
16 my $file = $fh->filename;
17 $fh->close;
18 my $dsn = "dbi:SQLite:dbname=$file";
19 my $userstore = Text::Tradition::Directory->new( { dsn => $dsn,
20         extra_args => { create => 1 } } );
21 my $scope = $userstore->new_scope();
22 my $testuser = $userstore->create_user( { url => 'http://example.com' } );
23 ok( $testuser->$_isa('Text::Tradition::User'), "Created test user via userstore" );
24 $testuser->add_tradition( $newt );
25 is( $newt->user->id, $testuser->id, "Assigned tradition to test user" );
26 my $graphml_str = $newt->collation->as_graphml;
27 my $usert;
28 warning_is {
29         $usert = Text::Tradition->new( 'input' => 'Self', 'string' => $graphml_str );
30 } 'DROPPING user assignment without a specified userstore',
31         "Got expected user drop warning on parse";
32 $usert = Text::Tradition->new( 'input' => 'Self', 'string' => $graphml_str,
33         'userstore' => $userstore );
34 is( $usert->user->id, $testuser->id, "Parsed tradition with userstore points to correct user" );
35
36 done_testing();