1 2use strict; 3use warnings; 4 5use RT::Test tests => 15; 6 7use_ok("RT::URI::a"); 8my $uri = RT::URI::a->new($RT::SystemUser); 9ok(ref($uri), "URI object exists"); 10 11my $class = RT::Class->new( $RT::SystemUser ); 12$class->Create( Name => 'URItest - '. $$ ); 13ok $class->id, 'created a class'; 14my $article = RT::Article->new( $RT::SystemUser ); 15my ($id, $msg) = $article->Create( 16 Name => 'Testing URI parsing - '. $$, 17 Summary => 'In which this should load', 18 Class => $class->Id 19); 20ok($id,$msg); 21 22my $uristr = "a:" . $article->Id; 23$uri->ParseURI($uristr); 24is(ref($uri->Object), "RT::Article", "Object loaded is an article"); 25is($uri->Object->Id, $article->Id, "Object loaded has correct ID"); 26is($article->URI, 'fsck.com-article://example.com/article/'.$article->Id, 27 "URI object has correct URI string"); 28 29{ 30 my $aid = $article->id; 31 my $ticket = RT::Ticket->new( RT->SystemUser ); 32 my ($id, $msg) = $ticket->Create( 33 Queue => 1, 34 Subject => 'test ticket', 35 ); 36 ok $id, "Created a test ticket"; 37 38 # Try searching 39 my $tickets = RT::Tickets->new( RT->SystemUser ); 40 $tickets->FromSQL(" RefersTo = 'a:$aid' "); 41 is $tickets->Count, 0, "No results yet"; 42 43 # try with the full uri 44 $tickets->FromSQL(" RefersTo = '@{[ $article->URI ]}' "); 45 is $tickets->Count, 0, "Still no results"; 46 47 # add the link 48 $ticket->AddLink( Type => 'RefersTo', Target => "a:$aid" ); 49 50 # verify the ticket has it 51 my @links = @{$ticket->RefersTo->ItemsArrayRef}; 52 is scalar @links, 1, "Has one RefersTo link"; 53 is ref $links[0]->TargetObj, "RT::Article", "Link points to an article"; 54 is $links[0]->TargetObj->id, $aid, "Link points to the article we specified"; 55 56 # search again 57 $tickets->FromSQL(" RefersTo = 'a:$aid' "); 58 is $tickets->Count, 1, "Found one ticket with short URI"; 59 60 # search with the full uri 61 $tickets->FromSQL(" RefersTo = '@{[ $article->URI ]}' "); 62 is $tickets->Count, 1, "Found one ticket with full URI"; 63} 64