rt 4.0.23
[freeside.git] / rt / t / articles / uri-a.t
1
2 use strict;
3 use warnings;
4
5 use RT::Test tests => 15;
6
7 use_ok("RT::URI::a");
8 my $uri = RT::URI::a->new($RT::SystemUser);
9 ok(ref($uri), "URI object exists");
10
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',
18     Class => $class->Id
19 );
20 ok($id,$msg);
21
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");
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 }