first pass RT4 merge, RT#13852
[freeside.git] / rt / t / web / ticket_seen.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use RT::Test nodata => 1, tests => 23, config => 'Set($ShowUnreadMessageNotifications, 1);';
7
8 my $queue = RT::Test->load_or_create_queue( Name => 'Regression' );
9 ok $queue && $queue->id, 'loaded or created queue';
10
11 my $user_a = RT::Test->load_or_create_user(
12     Name => 'user_a', Password => 'password',
13 );
14 ok $user_a && $user_a->id, 'loaded or created user';
15
16 my $user_b = RT::Test->load_or_create_user(
17     Name => 'user_b', Password => 'password',
18 );
19 ok $user_b && $user_b->id, 'loaded or created user';
20
21 ok( RT::Test->set_rights(
22     { Principal => $user_a, Right => [qw(SeeQueue ShowTicket CreateTicket OwnTicket ModifyTicket)] },
23     { Principal => $user_b, Right => [qw(SeeQueue ShowTicket ReplyToTicket)] },
24 ), 'set rights');
25 RT::Test->started_ok;
26
27 my $agent_a = RT::Test::Web->new;
28 ok $agent_a->login('user_a', 'password'), 'logged in as user A';
29
30 my $agent_b = RT::Test::Web->new;
31 ok $agent_b->login('user_b', 'password'), 'logged in as user B';
32
33 diag "create a ticket for testing";
34 my $tid;
35 {
36     my $ticket = RT::Ticket->new( $user_a );
37     my ($txn, $msg);
38     ($tid, $txn, $msg) = $ticket->Create(
39         Queue => $queue->id,
40         Owner => $user_a->id,
41         Subject => 'test',
42     );
43     ok $tid, 'created a ticket #'. $tid or diag "error: $msg";
44     is $ticket->Owner, $user_a->id, 'correct owner';
45 }
46
47 diag "user B adds a message, we check that user A see notification and can clear it";
48 {
49     my $ticket = RT::Ticket->new( $user_b );
50     $ticket->Load( $tid );
51     ok $ticket->id, 'loaded the ticket';
52
53     my ($status, $msg) = $ticket->Correspond( Content => 'bla-bla' );
54     ok $status, 'added reply' or diag "error: $msg";
55     my $txns = $ticket->Transactions;
56     $txns->Limit(
57         FIELD           => 'Type',
58         VALUE           => "Correspond",
59     );
60     my $txn = $txns->Last;
61     my $reply_id = $txn->id;
62     ok( $reply_id, 'got correspond txn id' );
63
64     $agent_a->goto_ticket($tid);
65     $agent_a->content_contains('bla-bla', 'the message on the page');
66
67     $agent_a->content_contains(
68         'unread message',
69         'we have not seen something'
70     );
71
72     $agent_a->follow_link_ok(
73         { text => 'jump to the first unread message' },
74         'try to jump to first unread message'
75     );
76     like( $agent_a->base, qr/#txn-$reply_id$/, 'contains anchor' );
77
78     $agent_a->follow_link_ok({text => 'jump to the first unread message and mark all messages as seen'}, 'try to mark all as seen');
79     $agent_a->content_contains(
80         'Marked all messages as seen',
81         'see success message'
82     );
83     like( $agent_a->base, qr/#txn-$reply_id$/, 'contains anchor' );
84
85     $agent_a->content_contains(
86         'Marked all messages as seen',
87         'see success message'
88     );
89
90     $agent_a->goto_ticket($tid);
91     $agent_a->content_lacks(
92         'unread message',
93         'we have seen everything, so no messages'
94     );
95 }
96