Software /
code /
prosody-modules
Comparison
mod_lib_ldap/dev/t/02-vcard.t @ 809:1d51c5e38faa
Add LDAP plugin suite
author | rob@hoelz.ro |
---|---|
date | Sun, 02 Sep 2012 15:35:50 +0200 |
child | 823:8971110c0a61 |
comparison
equal
deleted
inserted
replaced
808:ba2e207e1fb7 | 809:1d51c5e38faa |
---|---|
1 use strict; | |
2 use warnings; | |
3 use lib 't'; | |
4 | |
5 use TestConnection; | |
6 use AnyEvent::XMPP::Ext::VCard; | |
7 use Test::More; | |
8 | |
9 sub test_vcard { | |
10 my ( $username, $expected_fields ) = @_; | |
11 | |
12 $expected_fields->{'JABBERID'} = $username . '@' . $TestConnection::HOST; | |
13 $expected_fields->{'VERSION'} = '2.0'; | |
14 | |
15 my $conn = TestConnection->new($username); | |
16 my $vcard = AnyEvent::XMPP::Ext::VCard->new; | |
17 | |
18 local $Test::Builder::Level = $Test::Builder::Level + 1; | |
19 | |
20 $conn->reg_cb(stream_ready => sub { | |
21 $vcard->hook_on($conn); | |
22 }); | |
23 | |
24 $conn->reg_cb(session_ready => sub { | |
25 $vcard->retrieve($conn, undef, sub { | |
26 my ( $jid, $vcard, $error ) = @_; | |
27 | |
28 if(eval { $vcard->isa('AnyEvent::XMPP::Error') }) { | |
29 $error = $vcard; | |
30 } | |
31 | |
32 if($error) { | |
33 $conn->cond->send($error->string); | |
34 return; | |
35 } | |
36 | |
37 foreach my $key (keys %$vcard) { | |
38 my $value = $vcard->{$key}; | |
39 | |
40 $value = $value->[0]; | |
41 | |
42 if($value eq '') { | |
43 delete $vcard->{$key}; | |
44 } else { | |
45 $vcard->{$key} = $value; | |
46 } | |
47 } | |
48 | |
49 is_deeply $expected_fields, $vcard or diag(explain($vcard)); | |
50 $conn->cond->send; | |
51 }); | |
52 }); | |
53 | |
54 my $error = $conn->cond->recv; | |
55 | |
56 if($error) { | |
57 fail($error); | |
58 return; | |
59 } | |
60 } | |
61 | |
62 plan tests => 5; | |
63 | |
64 test_vcard(one => { | |
65 FN => 'John Testerson', | |
66 NICKNAME => 'one', | |
67 }); | |
68 | |
69 test_vcard(two => { | |
70 FN => 'Jane Testerson', | |
71 NICKNAME => 'two', | |
72 }); | |
73 | |
74 test_vcard(three => { | |
75 FN => 'Jerry Testerson', | |
76 NICKNAME => 'three', | |
77 }); | |
78 | |
79 test_vcard(four => { | |
80 FN => 'Jack Testerson', | |
81 NICKNAME => 'four', | |
82 }); | |
83 | |
84 test_vcard(five => { | |
85 FN => 'Jimmy Testerson', | |
86 NICKNAME => 'five', | |
87 }); |