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