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