annotate mod_lib_ldap/dev/t/02-vcard.t @ 813:2469f779b3f7

mod_storage_*: Update to use module:provides().
author Waqas Hussain <waqas20@gmail.com>
date Wed, 12 Sep 2012 23:58:01 +0500
parents 1d51c5e38faa
children 8971110c0a61
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
809
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
1 use strict;
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
2 use warnings;
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
3 use lib 't';
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
4
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
5 use TestConnection;
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
6 use AnyEvent::XMPP::Ext::VCard;
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
7 use Test::More;
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
8
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
9 sub test_vcard {
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
10 my ( $username, $expected_fields ) = @_;
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
11
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
12 $expected_fields->{'JABBERID'} = $username . '@' . $TestConnection::HOST;
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
13 $expected_fields->{'VERSION'} = '2.0';
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
14
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
15 my $conn = TestConnection->new($username);
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
16 my $vcard = AnyEvent::XMPP::Ext::VCard->new;
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
17
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
18 local $Test::Builder::Level = $Test::Builder::Level + 1;
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
19
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
20 $conn->reg_cb(stream_ready => sub {
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
21 $vcard->hook_on($conn);
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
22 });
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
23
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
24 $conn->reg_cb(session_ready => sub {
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
25 $vcard->retrieve($conn, undef, sub {
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
26 my ( $jid, $vcard, $error ) = @_;
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
27
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
28 if(eval { $vcard->isa('AnyEvent::XMPP::Error') }) {
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
29 $error = $vcard;
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
30 }
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
31
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
32 if($error) {
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
33 $conn->cond->send($error->string);
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
34 return;
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
35 }
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
36
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
37 foreach my $key (keys %$vcard) {
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
38 my $value = $vcard->{$key};
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
39
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
40 $value = $value->[0];
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
41
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
42 if($value eq '') {
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
43 delete $vcard->{$key};
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
44 } else {
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
45 $vcard->{$key} = $value;
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
46 }
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
47 }
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
48
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
49 is_deeply $expected_fields, $vcard or diag(explain($vcard));
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
50 $conn->cond->send;
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
51 });
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
52 });
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
53
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
54 my $error = $conn->cond->recv;
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
55
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
56 if($error) {
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
57 fail($error);
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
58 return;
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
59 }
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
60 }
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
61
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
62 plan tests => 5;
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
63
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
64 test_vcard(one => {
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
65 FN => 'John Testerson',
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
66 NICKNAME => 'one',
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
67 });
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
68
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
69 test_vcard(two => {
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
70 FN => 'Jane Testerson',
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
71 NICKNAME => 'two',
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
72 });
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
73
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
74 test_vcard(three => {
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
75 FN => 'Jerry Testerson',
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
76 NICKNAME => 'three',
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
77 });
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
78
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
79 test_vcard(four => {
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
80 FN => 'Jack Testerson',
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
81 NICKNAME => 'four',
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
82 });
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
83
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
84 test_vcard(five => {
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
85 FN => 'Jimmy Testerson',
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
86 NICKNAME => 'five',
1d51c5e38faa Add LDAP plugin suite
rob@hoelz.ro
parents:
diff changeset
87 });