summaryrefslogtreecommitdiff
path: root/rt/t/api/uri-canonicalize.t
blob: 288569c7f9a5ed5f3b7a9f11ea8a357287bedfa9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use strict;
use warnings;
use RT::Test tests => undef;

my @warnings;
local $SIG{__WARN__} = sub {
    push @warnings, "@_";
};

# Create ticket
my $ticket = RT::Test->create_ticket( Queue => 1, Subject => 'test ticket' );
ok $ticket->id, 'created ticket';

# Create article class
my $class = RT::Class->new( $RT::SystemUser );
$class->Create( Name => 'URItest - '. $$ );
ok $class->id, 'created a class';

# Create article
my $article = RT::Article->new( $RT::SystemUser );
$article->Create(
    Name    => 'Testing URI parsing - '. $$,
    Summary => 'In which this should load',
    Class   => $class->Id
);
ok $article->id, 'create article';

# Test permutations of URIs
my $ORG = RT->Config->Get('Organization');
my $URI = RT::URI->new( RT->SystemUser );
my %expected = (
    # tickets
    "1"                                 => "fsck.com-rt://$ORG/ticket/1",
    "t:1"                               => "fsck.com-rt://$ORG/ticket/1",
    "fsck.com-rt://$ORG/ticket/1"       => "fsck.com-rt://$ORG/ticket/1",

    # articles
    "a:1"                               => "fsck.com-article://$ORG/article/1",
    "fsck.com-article://$ORG/article/1" => "fsck.com-article://$ORG/article/1",

    # random stuff
    "http://$ORG"                       => "http://$ORG",
    "mailto:foo\@example.com"           => "mailto:foo\@example.com",
    "invalid"                           => "invalid",   # doesn't trigger die
);
for my $uri (sort keys %expected) {
    is $URI->CanonicalizeURI($uri), $expected{$uri}, "canonicalized as expected";
}

is_deeply \@warnings, [
    "Could not determine a URI scheme for invalid\n",
], "expected warnings";

done_testing;