RT 4.2.11, ticket#13852
[freeside.git] / rt / t / articles / uri-articles.t
1
2 use strict;
3 use warnings;
4
5 use RT::Test tests => undef;
6 use Test::Warn;
7
8 use_ok "RT::URI::fsck_com_article";
9 my $uri = RT::URI::fsck_com_article->new( $RT::SystemUser );
10
11 ok $uri;
12 isa_ok $uri, 'RT::URI::fsck_com_article';
13 isa_ok $uri, 'RT::URI::base';
14 isa_ok $uri, 'RT::Base';
15
16 is $uri->LocalURIPrefix, 'fsck.com-article://example.com';
17
18 my $class = RT::Class->new( $RT::SystemUser );
19 $class->Create( Name => 'URItest - '. $$ );
20 ok $class->id, 'created a class';
21 my $article = RT::Article->new( $RT::SystemUser );
22 my ($id, $msg) = $article->Create(
23     Name    => 'Testing URI parsing - '. $$,
24     Summary => 'In which this should load',
25     Class => $class->Id
26 );
27 ok($id,$msg);
28
29 $uri = RT::URI::fsck_com_article->new( $article->CurrentUser );
30 is $uri->URIForObject( $article ),
31     'fsck.com-article://example.com/article/' . $article->id,
32         'Got correct URIForObject';
33 my $article_id = $article->Id;
34 ok ($uri->ParseURI("fsck.com-article://example.com/article/$article_id"),
35     'Parsed URI');
36
37 ok ($article->Delete(), 'Deleted article');
38
39 my $ret;
40 warning_like {
41     $ret = $uri->ParseURI("fsck.com-article://example.com/article/$article_id");
42 } qr/Unable to load article for id $article_id. It may have been deleted/,
43     "Warned about missing article";
44
45 ok (!$ret, 'Returned false on missing article');
46
47 ok (!$uri->ParseURI("fsck.com-article://foo.com/article/$article_id"),
48     'ParseURI returned false with incorrect Organization');
49
50 done_testing();