README -> README.pod, add some content
[p5sagit/Promulger.git] / t / list.t
CommitLineData
418e2ac2 1#!/usr/bin/perl
2use strictures 1;
3use autodie;
2a007b5a 4use Test::Most;
418e2ac2 5
6use File::Temp ();
7use Path::Class;
418e2ac2 8
9use aliased 'Promulger::List';
10# no alias here so we don't risk colliding with perl's own Config.pm -- apeiron,
11# 2011-09-04
12use Promulger::Config;
13
14{
15 my $raw_pmg_home = File::Temp->newdir;
16 my $pmg_home = dir($raw_pmg_home);
17
18 my $aliases = $pmg_home->file('aliases');
19 my $aliases_fh = $aliases->openw;
20 close $aliases_fh;
21
22 my $list_home = $pmg_home->subdir('lists');
23 $list_home->mkpath;
24
25 my $config_file = $pmg_home->file('pmg.conf');
26 my $config_fh = $config_file->openw;
27 print $config_fh <<"CONFIG";
28mailer = Test
29aliases = $aliases
30list_home = $list_home
31CONFIG
32
33 close $config_fh;
34 my $config = Promulger::Config->load_config($config_file);
35 my $list;
36 lives_ok { $list = List->new(
37 listname => 'foo',
38 active => 1,
39 subscribers => {},
40 ) } "can create a list";
41 lives_ok { $list->setup } "can setup a list";
42
43 cmp_ok(
44 $list->listname,
45 'eq',
46 'foo',
47 "list has same listname as one we specified",
48 );
49 cmp_ok(
50 $list->active,
51 '==',
52 1,
53 "list is active, like the one we specified",
54 );
55 cmp_deeply(
56 $list->subscribers,
57 {},
58 "list has no subscribers for now, like the one we specified",
59 );
60
61 my $resolved_list = List->resolve('foo');
62 cmp_ok(
63 $resolved_list->listname,
64 'eq',
65 'foo',
66 "resolved list has same listname as one we created",
67 );
68 cmp_ok(
69 $resolved_list->active,
70 '==',
71 1,
72 "resolved list is active, like the one we created",
73 );
74 cmp_deeply(
75 $resolved_list->subscribers,
76 {},
77 "resolved list has no subscribers for now, like the one we created",
78 );
79
80 lives_ok { $list->subscribe('foo@example.com') } "can subscribe someone";
5e1977ec 81 $list = List->resolve('foo');
82 cmp_deeply(
83 $list->subscribers,
84 {
85 'foo@example.com' => 1,
86 },
87 "subscribing a user adds them to the serialized data",
88 );
89 lives_ok { $list->unsubscribe('foo@example.com') } "can unsubscribe someone";
90 $list = List->resolve('foo');
91 cmp_deeply(
92 $list->subscribers,
93 { },
94 "unsubscribing a user removes them from the serialized data",
95 );
418e2ac2 96}
97
98done_testing;