Comparison

mod_lib_ldap/dev/t/01-rosters.t @ 809:1d51c5e38faa

Add LDAP plugin suite
author rob@hoelz.ro
date Sun, 02 Sep 2012 15:35:50 +0200
comparison
equal deleted inserted replaced
808:ba2e207e1fb7 809:1d51c5e38faa
1 use strict;
2 use warnings;
3 use lib 't';
4
5 use AnyEvent::XMPP::Util qw(split_jid);
6 use TestConnection;
7 use Test::More;
8
9 sub test_roster {
10 my ( $username, $expected_contacts ) = @_;
11
12 local $Test::Builder::Level = $Test::Builder::Level + 1;
13 my @contacts;
14
15 my $conn = TestConnection->new($username);
16
17 $conn->reg_cb(roster_update => sub {
18 my ( undef, $roster ) = @_;
19
20 @contacts = sort { $a->{'username'} cmp $b->{'username'} } map {
21 +{
22 username => (split_jid($_->jid))[0],
23 name => $_->name,
24 groups => [ sort $_->groups ],
25 subscription => $_->subscription,
26 }
27 } $roster->get_contacts;
28 $conn->cond->send;
29 });
30
31 my $error = $conn->cond->recv;
32
33 if($error) {
34 fail($error);
35 return;
36 }
37 @$expected_contacts = sort { $a->{'username'} cmp $b->{'username'} }
38 @$expected_contacts;
39 foreach my $contact (@$expected_contacts) {
40 $contact->{'subscription'} = 'both';
41 @{ $contact->{'groups'} } = sort @{ $contact->{'groups'} };
42 }
43 is_deeply(\@contacts, $expected_contacts);
44 }
45
46 plan tests => 5;
47
48 test_roster(one => [{
49 username => 'two',
50 name => 'Jane Testerson',
51 groups => ['everyone', 'admin'],
52 }, {
53 username => 'three',
54 name => 'Jerry Testerson',
55 groups => ['everyone'],
56 }, {
57 username => 'four',
58 name => 'Jack Testerson',
59 groups => ['everyone'],
60 }, {
61 username => 'five',
62 name => 'Jimmy Testerson',
63 groups => ['everyone'],
64 }]);
65
66 test_roster(two => [{
67 username => 'one',
68 name => 'John Testerson',
69 groups => ['everyone', 'admin'],
70 }, {
71 username => 'three',
72 name => 'Jerry Testerson',
73 groups => ['everyone'],
74 }, {
75 username => 'four',
76 name => 'Jack Testerson',
77 groups => ['everyone'],
78 }, {
79 username => 'five',
80 name => 'Jimmy Testerson',
81 groups => ['everyone'],
82 }]);
83
84 test_roster(three => [{
85 username => 'one',
86 name => 'John Testerson',
87 groups => ['everyone'],
88 }, {
89 username => 'two',
90 name => 'Jane Testerson',
91 groups => ['everyone'],
92 }, {
93 username => 'four',
94 name => 'Jack Testerson',
95 groups => ['everyone'],
96 }, {
97 username => 'five',
98 name => 'Jimmy Testerson',
99 groups => ['everyone'],
100 }]);
101
102 test_roster(four => [{
103 username => 'one',
104 name => 'John Testerson',
105 groups => ['everyone'],
106 }, {
107 username => 'two',
108 name => 'Jane Testerson',
109 groups => ['everyone'],
110 }, {
111 username => 'three',
112 name => 'Jerry Testerson',
113 groups => ['everyone'],
114 }, {
115 username => 'five',
116 name => 'Jimmy Testerson',
117 groups => ['everyone'],
118 }]);
119
120 test_roster(five => [{
121 username => 'one',
122 name => 'John Testerson',
123 groups => ['everyone'],
124 }, {
125 username => 'two',
126 name => 'Jane Testerson',
127 groups => ['everyone'],
128 }, {
129 username => 'three',
130 name => 'Jerry Testerson',
131 groups => ['everyone'],
132 }, {
133 username => 'four',
134 name => 'Jack Testerson',
135 groups => ['everyone'],
136 }]);