6 # Test the roster implementation in the Test backend works. Note
7 # that it is the Test in Thrasher::Backend::Test that is referred
8 # to in the name of this script. (That is, it's not just a
9 # redundant statement that this is a test; you may test other
12 use Test
::More
'no_plan';
16 use Thrasher
::Test
qw(:all);
19 use_ok
'Thrasher::Test', qw(:all);
20 use_ok
'Thrasher::Backend';
21 use_ok
'Thrasher::Backend::Test';
22 use_ok
'Thrasher::Component';
23 use_ok
'Thrasher::Roster', qw(:all);
24 use_ok
'Thrasher::Protocol::Test';
27 my $backend = new Thrasher
::Backend
::Test
;
29 my $jid = 'romeo@montague.lit';
30 my $legacy = 'juliet';
32 cmp_deeply
($backend->get_roster($jid), {},
33 'initially we have an empty roster');
34 $backend->set_roster($jid, {$legacy => $backend->subscribed});
35 cmp_deeply
($backend->get_roster($jid), {$legacy => $backend->subscribed},
37 $backend->set_roster_user_state($jid, $legacy,
38 $backend->unsubscribed);
39 cmp_deeply
($backend->get_roster($jid), {},
40 'unsubscribing correctly manifests as a removal');
41 $backend->set_roster_user_state($jid, $legacy,
42 $backend->subscribed);
43 cmp_deeply
($backend->get_roster($jid), {$legacy => $backend->subscribed},
44 'correctly remembers that the legacy user is subscribed.');
46 cmp_deeply
(roster_diff
({}, {}), {},
47 'roster diff compares empties correctly');
48 cmp_deeply
(roster_diff
({$legacy => subscribed
}, {}),
49 {$legacy => [subscribed
, unsubscribed
]},
50 'roster diff handles people no longer being subscribed');
51 cmp_deeply
(roster_diff
({}, {$legacy => subscribed
}),
52 {$legacy => [unsubscribed
, subscribed
]},
53 'roster diff handles people now subscribed');
54 cmp_deeply
(roster_diff
({$legacy => want_subscribe
},
55 {$legacy => subscribed
}),
56 {$legacy => [want_subscribe
, subscribed
]},
57 'roster diff handles people with changed status');
59 # This tests the set_current_legacy_roster by forging an old
60 # roster, then forging a new one, to ensure that we get the
63 # Six cases, used in user names for identification:
64 # 1. subscribed -> unsubscribed
65 # 2. subscribed -> want_subscribe
66 # 3. unsubscribed -> subscribed
67 # 4. unsubscribed -> want_subscribe
68 # 5. want_subscribe -> unsubscribed
69 # 6. want_subscribe -> subscribed
71 my $component = logged_in_comp
;
76 # unsubscribed is "not present"
78 j6
=> want_subscribe
};
81 { j2
=> want_subscribe
,
86 $component->{protocol
}->{backend
}->set_roster('romeo@montague.lit',
89 $component->{protocol
}->set_current_legacy_roster
90 ($component->session_for('romeo@montague.lit'), $new_roster);
92 my $expected = clean_xml
(<<'EXPECTED');
93 <presence from='j1@test.transport'
94 to='romeo@montague.lit'
96 <presence from='j1@test.transport'
97 to='romeo@montague.lit'
99 <presence from='j2@test.transport'
100 to='romeo@montague.lit'
102 <presence from='j2@test.transport'
103 to='romeo@montague.lit'
104 type='unsubscribed'/>
105 <presence from='j2@test.transport'
106 to='romeo@montague.lit'
108 <presence from='j3@test.transport'
109 to='romeo@montague.lit'
111 <presence from='j3@test.transport'
112 to='romeo@montague.lit'
114 <presence from='j4@test.transport'
115 to='romeo@montague.lit'
117 <presence from='j5@test.transport'
118 to='romeo@montague.lit'
120 <presence from='j5@test.transport'
121 to='romeo@montague.lit'
122 type='unsubscribed'/>
123 <presence from='j6@test.transport'
124 to='romeo@montague.lit'
126 <presence from='j6@test.transport'
127 to='romeo@montague.lit'
131 is
(output
, $expected,
132 'set_current_legacy_roster works as expected.');
136 my $component = logged_in_comp
;
137 $component->set_roster_name('horatio@denmark.lit',
138 'rosencrantz@denmark.lit',
141 my $expected = clean_xml
(<<EXPECTED);
142 <iq from='test.transport'
144 to='horatio\@denmark.lit'
146 <x xmlns='http://jabber.org/protocol/rosterx'>
147 <item action='modify'
148 jid='rosencrantz\@denmark.lit'
154 is
($expected, output
, 'set roster name appears to work.');