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