summaryrefslogtreecommitdiff
path: root/rt/t/web/search_rss.t
blob: 454dc03699aae2d0eacea1bec5d941332fd11e37 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/perl

use strict;

use RT::Test tests => 36;
RT::Test->started_ok;

my $ticket = RT::Ticket->new($RT::SystemUser);
for ( 1 .. 5 ) {
    $ticket->Create(
        Subject   => 'Ticket ' . $_,
        Queue     => 'General',
        Owner     => 'root',
        Requestor => 'rss@localhost',
    );
}

my $agent = RT::Test::Web->new;
ok $agent->login('root', 'password'), 'logged in as root';

$agent->get_ok('/Search/Build.html');
$agent->form_name('BuildQuery');
$agent->field('idOp', '>');
$agent->field('ValueOfid', '0');
$agent->submit('DoSearch');
$agent->follow_link_ok({text=>'Show Results'});

for ( 1 .. 5 ) {
    $agent->content_contains('Ticket ' . $_);
}
my $rdf_path = $agent->uri->path_query;
$rdf_path =~ s!Results\.html!Results.rdf!;

$agent->follow_link_ok( { text => 'RSS' } );
my $noauth_uri = $agent->uri;
is( $agent->content_type, 'application/rss+xml', 'content type' );
for ( 1 .. 5 ) {
    $agent->content_contains('Ticket ' . $_);
}
my $rss_content = $agent->content;
$agent->get_ok($rdf_path);
is($agent->content, $rss_content, 'old Results.rdf still works');

SKIP: {
    eval { require XML::Simple; };
    skip 'no XML::Simple found', 6 if $@;
    my $rss = XML::Simple::XMLin( $rss_content );
    is( scalar @{ $rss->{item} }, 5, 'item number' );
    for ( 1 .. 5 ) {
        is( $rss->{item}[$_-1]{title}, 'Ticket ' . $_, 'title' . $_ );
    }
}

# not login at all
my $agent_b = RT::Test::Web->new;
$agent_b->get_ok($noauth_uri);
is( $agent_b->content_type, 'application/rss+xml', 'content type' );
is( $agent_b->content, $rss_content, 'content' );
$agent_b->get_ok('/', 'back to homepage');
$agent_b->content_lacks( 'Logout', 'still not login' );

# lets login as another user
my $user_b = RT::Test->load_or_create_user(
    Name => 'user_b', Password => 'password',
);
ok $user_b && $user_b->id, 'loaded or created user';
$agent_b->login('user_b', 'password'), 'logged in as user B';
$agent_b->get_ok($noauth_uri);
is( $agent_b->content_type, 'application/rss+xml', 'content type' );
is( $agent_b->content, $rss_content, 'content' );
$agent_b->get_ok('/', 'back to homepage');
$agent_b->content_contains( 'Logout', 'still loggedin' );
$agent_b->content_contains( 'user_b', 'still loggedin as user_b' );