fix ticketing system error on bootstrap of new install
[freeside.git] / rt / t / web / search_rss.t
1 use strict;
2 use warnings;
3
4 use RT::Test tests => 38;
5 my ($baseurl, $agent) = RT::Test->started_ok;
6
7 my $ticket = RT::Ticket->new(RT->SystemUser);
8 for ( 1 .. 5 ) {
9     $ticket->Create(
10         Subject   => 'Ticket ' . $_,
11         Queue     => 'General',
12         Owner     => 'root',
13         Requestor => 'rss@localhost',
14     );
15 }
16
17 ok $agent->login('root', 'password'), 'logged in as root';
18
19 $agent->get_ok('/Search/Build.html');
20 $agent->form_name('BuildQuery');
21 $agent->field('idOp', '>');
22 $agent->field('ValueOfid', '0');
23 $agent->submit('DoSearch');
24 $agent->follow_link_ok({id => 'page-results'});
25
26 for ( 1 .. 5 ) {
27     $agent->content_contains('Ticket ' . $_);
28 }
29 my $rdf_path = $agent->uri->path_query;
30 $rdf_path =~ s!Results\.html!Results.rdf!;
31
32 $agent->follow_link_ok( { text => 'RSS' } );
33 my $noauth_uri = $agent->uri;
34 is( $agent->content_type, 'application/rss+xml', 'content type' );
35 for ( 1 .. 5 ) {
36     $agent->content_contains('Ticket ' . $_);
37 }
38 my $rss_content = $agent->content;
39 $agent->get_ok($rdf_path);
40 is($agent->content, $rss_content, 'old Results.rdf still works');
41
42 use XML::Simple;
43 my $rss = XML::Simple::XMLin( $rss_content );
44 is( scalar @{ $rss->{item} }, 5, 'item number' );
45 for ( 1 .. 5 ) {
46     is( $rss->{item}[$_-1]{title}, 'Ticket ' . $_, 'title' . $_ );
47 }
48
49 # not login at all
50 my $agent_b = RT::Test::Web->new;
51 $agent_b->get_ok($noauth_uri);
52 is( $agent_b->content_type, 'application/rss+xml', 'content type' );
53 is( $agent_b->content, $rss_content, 'content' );
54 $agent_b->get_ok('/', 'back to homepage');
55 $agent_b->content_lacks( 'Logout', 'still not login' );
56
57 # lets login as another user
58 my $user_b = RT::Test->load_or_create_user(
59     Name => 'user_b', Password => 'password',
60 );
61 ok $user_b && $user_b->id, 'loaded or created user';
62 $agent_b->login('user_b', 'password');
63 $agent_b->get_ok($noauth_uri);
64 is( $agent_b->content_type, 'application/rss+xml', 'content type' );
65 is( $agent_b->content, $rss_content, 'content' );
66 $agent_b->get_ok('/', 'back to homepage');
67 $agent_b->content_contains( 'Logout', 'still loggedin' );
68 $agent_b->content_contains( 'user_b', 'still loggedin as user_b' );
69