1 | use strict; |
---|
2 | use warnings; |
---|
3 | use Test::More tests => 13; |
---|
4 | |
---|
5 | # $Id$ |
---|
6 | |
---|
7 | use_ok 'Epoll', 'Epoll'; |
---|
8 | use_ok 'Epoll::DB'; |
---|
9 | $ENV{EPOLL_NO_COMMIT} = 1; |
---|
10 | isa_ok(my $vote = Epoll::DB->new(Epoll->config->{db}), 'Epoll::DB'); |
---|
11 | |
---|
12 | ok(my $pollid = $vote->create_poll('test@', "Vote test", "password"), |
---|
13 | "can create a new poll"); |
---|
14 | |
---|
15 | isa_ok(my $poll = $vote->poll($pollid), 'Epoll::DB::Poll'); |
---|
16 | |
---|
17 | ok($poll->gen_poll_keys('keypass'), 'can generate poll keys'); |
---|
18 | |
---|
19 | $poll->addupd_voting($_) foreach (qw(a b c)); |
---|
20 | |
---|
21 | $poll->register_ballot('a', ['ch', 'ch2'], 'localhost'); |
---|
22 | $poll->register_ballot('b', ['ch'], 'localhost'); |
---|
23 | $poll->register_ballot('c', [], 'localhost'); |
---|
24 | |
---|
25 | isa_ok(my $results = $vote->results($pollid), 'Epoll::DB::Poll'); |
---|
26 | |
---|
27 | ok($results->decrypted_ballots('keypass'), "Can decrypt ballot"); |
---|
28 | |
---|
29 | is($results->ballot_count_crypt, 3, "ballot count is 3"); |
---|
30 | is($results->ballot_count_clear, 3, "ballot count is 3"); |
---|
31 | |
---|
32 | ok(my $res = $results->results, "can get results"); |
---|
33 | is($res->[0]->{value}, 'ch', "winner is ch"); |
---|
34 | is($res->[0]->{count}, 2, "winner has two voices"); |
---|
35 | |
---|
36 | $vote->db->rollback; # really rollback |
---|