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