use strict; use warnings; use Test::More; # $Id$ my $test_polls = [ # Structure: # { # poll => { var => $val }, # choices => [ qw() ], # voting => [ qw(mail) ], # ballot => { # # signing from voting list # signing => { sbal => [], fsbal => [] } # list of items # }, # map => { from => to }, # results => { var => $val }, # wanted results # } { # an empty poll poll => { label => 'empty poll' }, choices => [ qw(ch1 ch2) ], results => { ballot_count => 0, absolute_majority => 1, } }, ]; plan tests => 3 # Fixed test + scalar(@$test_polls) * # number of tested polls scenario 6; # per poll number of tests use_ok 'Vote', 'Vote'; use_ok 'Vote::DB'; $ENV{EPOLL_NO_COMMIT} = 1; isa_ok(my $vote = Vote::DB->new(Vote->config->{db}), 'Vote::DB'); my $count = 0; foreach my $tpoll (@$test_polls) { $count++; diag("Testing vote #$count: " . ($tpoll->{poll}{label} || 'No name')); ok(my $pollid = $vote->create_poll('test@', "Vote test $count", "password"), "can create a new poll"); isa_ok(my $poll = $vote->poll($pollid), 'Vote::DB::Poll'); foreach (keys %{ $tpoll->{poll} || {}}) { $poll->param($_ => $tpoll->{poll}{$_}); } $poll->addupd_voting($_) foreach (@{ $tpoll->{voting} || [] }); foreach (@{ $tpoll->{choices} || [] }) { $poll->add_choice($_); } ok(eq_set( [ map { $poll->choice($_)->info->{label} } $poll->choices ], $tpoll->{choices} || []), "choices were added"); foreach my $name (keys %{ $tpoll->{ballot} || {} }) { $poll->register_ballot( $name, $tpoll->{ballot}{$name}{sbal}, $tpoll->{ballot}{$name}{sbal}, "localtest" ); } isa_ok(my $results = $vote->results($pollid), 'Vote::DB::Poll'); is($results->ballot_count, $tpoll->{results}{ballot_count} || 0, "can get ballot count"); is($results->absolute_majority, $tpoll->{results}{absolute_majority}, "can get absolute majority"); my $res = $results->results_count; $vote->rollback; }