Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / rt / t / articles / uri-a.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use RT::Test tests => 15;
7
8 use_ok("RT::URI::a");
9 my $uri = RT::URI::a->new($RT::SystemUser);
10 ok(ref($uri), "URI object exists");
11
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',
19     Class => $class->Id
20 );
21 ok($id,$msg);
22
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");
29
30 {
31     my $aid = $article->id;
32     my $ticket = RT::Ticket->new( RT->SystemUser );
33     my ($id, $msg) = $ticket->Create(
34         Queue       => 1,
35         Subject     => 'test ticket',
36     );
37     ok $id, "Created a test ticket";
38
39     # Try searching
40     my $tickets = RT::Tickets->new( RT->SystemUser );
41     $tickets->FromSQL(" RefersTo = 'a:$aid' ");
42     is $tickets->Count, 0, "No results yet";
43
44     # try with the full uri
45     $tickets->FromSQL(" RefersTo = '@{[ $article->URI ]}' ");
46     is $tickets->Count, 0, "Still no results";
47
48     # add the link
49     $ticket->AddLink( Type => 'RefersTo', Target => "a:$aid" );
50
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";
56
57     # search again
58     $tickets->FromSQL(" RefersTo = 'a:$aid' ");
59     is $tickets->Count, 1, "Found one ticket with short URI";
60
61     # search with the full uri
62     $tickets->FromSQL(" RefersTo = '@{[ $article->URI ]}' ");
63     is $tickets->Count, 1, "Found one ticket with full URI";
64 }