RT 4.0.22
[freeside.git] / rt / t / api / uri-canonicalize.t
1 use strict;
2 use warnings;
3 use RT::Test tests => undef;
4
5 my @warnings;
6 local $SIG{__WARN__} = sub {
7     push @warnings, "@_";
8 };
9
10 # Create ticket
11 my $ticket = RT::Test->create_ticket( Queue => 1, Subject => 'test ticket' );
12 ok $ticket->id, 'created ticket';
13
14 # Create article class
15 my $class = RT::Class->new( $RT::SystemUser );
16 $class->Create( Name => 'URItest - '. $$ );
17 ok $class->id, 'created a class';
18
19 # Create article
20 my $article = RT::Article->new( $RT::SystemUser );
21 $article->Create(
22     Name    => 'Testing URI parsing - '. $$,
23     Summary => 'In which this should load',
24     Class   => $class->Id
25 );
26 ok $article->id, 'create article';
27
28 # Test permutations of URIs
29 my $ORG = RT->Config->Get('Organization');
30 my $URI = RT::URI->new( RT->SystemUser );
31 my %expected = (
32     # tickets
33     "1"                                 => "fsck.com-rt://$ORG/ticket/1",
34     "t:1"                               => "fsck.com-rt://$ORG/ticket/1",
35     "fsck.com-rt://$ORG/ticket/1"       => "fsck.com-rt://$ORG/ticket/1",
36
37     # articles
38     "a:1"                               => "fsck.com-article://$ORG/article/1",
39     "fsck.com-article://$ORG/article/1" => "fsck.com-article://$ORG/article/1",
40
41     # random stuff
42     "http://$ORG"                       => "http://$ORG",
43     "mailto:foo\@example.com"           => "mailto:foo\@example.com",
44     "invalid"                           => "invalid",   # doesn't trigger die
45 );
46 for my $uri (sort keys %expected) {
47     is $URI->CanonicalizeURI($uri), $expected{$uri}, "canonicalized as expected";
48 }
49
50 is_deeply \@warnings, [
51     "Could not determine a URI scheme for invalid\n",
52 ], "expected warnings";
53
54 done_testing;