5 use RT::Test tests => 15;
8 my $uri = RT::URI::a->new($RT::SystemUser);
9 ok(ref($uri), "URI object exists");
11 my $class = RT::Class->new( $RT::SystemUser );
12 $class->Create( Name => 'URItest - '. $$ );
13 ok $class->id, 'created a class';
14 my $article = RT::Article->new( $RT::SystemUser );
15 my ($id, $msg) = $article->Create(
16 Name => 'Testing URI parsing - '. $$,
17 Summary => 'In which this should load',
22 my $uristr = "a:" . $article->Id;
23 $uri->ParseURI($uristr);
24 is(ref($uri->Object), "RT::Article", "Object loaded is an article");
25 is($uri->Object->Id, $article->Id, "Object loaded has correct ID");
26 is($article->URI, 'fsck.com-article://example.com/article/'.$article->Id,
27 "URI object has correct URI string");
30 my $aid = $article->id;
31 my $ticket = RT::Ticket->new( RT->SystemUser );
32 my ($id, $msg) = $ticket->Create(
34 Subject => 'test ticket',
36 ok $id, "Created a test ticket";
39 my $tickets = RT::Tickets->new( RT->SystemUser );
40 $tickets->FromSQL(" RefersTo = 'a:$aid' ");
41 is $tickets->Count, 0, "No results yet";
43 # try with the full uri
44 $tickets->FromSQL(" RefersTo = '@{[ $article->URI ]}' ");
45 is $tickets->Count, 0, "Still no results";
48 $ticket->AddLink( Type => 'RefersTo', Target => "a:$aid" );
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";
57 $tickets->FromSQL(" RefersTo = 'a:$aid' ");
58 is $tickets->Count, 1, "Found one ticket with short URI";
60 # search with the full uri
61 $tickets->FromSQL(" RefersTo = '@{[ $article->URI ]}' ");
62 is $tickets->Count, 1, "Found one ticket with full URI";