Refactor & centralize mapping of incoming libpurple presence codes.
[thrasher.git] / perl / tests / vcard.pl
blobd4076dc9ca35b1fcd81024760630bcf35d9d8d18
1 #!/usr/bin/perl
3 use strict;
4 use warnings;
6 # Test that the vcard implementation works as expected. Only
7 # does avatars for now, but that's good.
9 use Test::More 'no_plan';
10 use Data::Dumper;
12 use Thrasher::Test qw(:all);
14 BEGIN {
15 use_ok 'Thrasher::Test', qw(:all);
16 use_ok 'Thrasher';
17 use_ok 'Thrasher::Plugin', qw(:all);
18 use_ok 'Thrasher::Plugin::Vcard', qw(:all);
19 use_ok 'Thrasher::Callbacks', qw(:all);
20 use_ok 'Thrasher::Avatar', qw(:all);
21 use_ok 'Thrasher::Constants', qw(:all);
24 my $JID = transport_jid();
26 VCARD_TESTS: {
27 my $comp = logged_in_comp();
29 # Send a presence tag for the transport itself, which should
30 # not get modified by this plugin.
31 $comp->send_presence_xml(undef, '', undef);
32 is(output, "<presence from='$JID'/>",
33 "correctly does not decorate the transport's presences");
35 # Send a presence tag for a user with no avatar yet.
36 $comp->send_presence_xml('romeo@montague.lit',
37 '', "juliet\@$JID");
38 is(output,
39 "<presence from='juliet\@test.transport' to='romeo\@montague.lit'><x xmlns='vcard-temp:x:update'/></presence>",
40 'correctly indicates support for vcard avatars, but that '
41 .'the user does not yet have one');
43 my $vcard_query = <<VCARD_QUERY;
44 <iq from='romeo\@montague.lit'
45 to='juliet\@$JID'
46 type='get'
47 id='test'>
48 <vCard xmlns='$NS_VCARD'/>
49 </iq>
50 VCARD_QUERY
52 $comp->xml_in($vcard_query);
53 my $expected = clean_xml(<<EXPECTED);
54 <iq from='juliet\@test.transport'
55 id='test'
56 to='romeo\@montague.lit'
57 type='result'>
58 <vCard xmlns='vcard-temp'/>
59 </iq>
60 EXPECTED
61 is(output, $expected, 'empty vCards correctly reply');
63 set_avatar($comp, 'romeo@montague.lit', "juliet\@$JID",
64 $small_png);
65 $expected = clean_xml(<<EXPECTED);
66 <presence from='juliet\@test.transport'
67 to='romeo\@montague.lit'>
68 <x xmlns='vcard-temp:x:update'>0765a59164829a0fe4eb243ffb14bdd64a3d8f5d</x>
69 </presence>
70 EXPECTED
71 # FIXME: Send this out or not?
72 output;
73 # is(output, $expected, 'we get the proper avatar hash on avatar setting');
74 # That sort of automatically tests the presence code path, too
76 # Ask for the vcard again now that we have an avatar.
77 $comp->xml_in($vcard_query);
78 $expected = clean_xml(<<EXPECTED);
79 <iq from='juliet\@test.transport'
80 id='test'
81 to='romeo\@montague.lit'
82 type='result'>
83 <vCard xmlns='vcard-temp'>
84 <PHOTO>
85 <TYPE>image/png</TYPE>
86 <BINVAL>$small_png_base64</BINVAL>
87 </PHOTO>
88 </vCard>
89 </iq>
90 EXPECTED
91 is(clean_xml(output()), $expected,
92 'get the expected vCard with the avatar in it.');