"Fossies" - the Fresh Open Source Software Archive

Member "sendpage-1.001001/t/07_Sendpage-Recipient.t" (3 Jan 2008, 2823 Bytes) of package /linux/privat/old/sendpage-1.001001.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 # -*- Mode: CPerl -*-
    2 # Sendpage-Recipient.t -- unit test for Sendpage::Recipient
    3 # $Id: 07_Sendpage-Recipient.t 223 2006-08-24 16:01:31Z keescook $
    4 #
    5 # Copyright (C)  2006  Zak B. Elep
    6 # zakame@spunge.org, http://zakame.spunge.org
    7 #
    8 # This program is free software; you can redistribute it and/or modify
    9 # it under the terms of the GNU General Public License as published by
   10 # the Free Software Foundation; either version 2 of the License,
   11 # or (at your option) any later version.
   12 #
   13 # This program is distributed in the hope that it will be useful, but
   14 # WITHOUT ANY WARRANTY; without even the implied warranty of
   15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16 # GNU General Public License for more details.
   17 #
   18 # You should have received a copy of the GNU General Public License
   19 # along with this program; if not, write to the Free Software Foundation, Inc.,
   20 # 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
   21 #
   22 # After installation, run as `perl Sendpage-Recipient.t'
   23 
   24 use strict;
   25 use warnings;
   26 
   27 use Test::MockObject;
   28 use Test::More tests => 21;
   29 BEGIN {
   30     my %conf_mock_methods =
   31 	(
   32 	 get		 => sub {
   33 	     shift;		# discard
   34 	     if ($_[0] =~ /email-cc/) { return 'zakame' }
   35 	     elsif ($_[0] =~ /recip/) { return [ qw(foo bar baz) ] }
   36 	     elsif ($_[0] =~ /debug/) { return 0 }
   37 	 },
   38 	 instance_exists => sub {
   39 	     shift;		# discard
   40 	     if ($_[0] =~ /pc/) { return 1 }
   41 	 },
   42 	);
   43 
   44     my $mock_conf = new Test::MockObject;
   45     isa_ok( $mock_conf, 'Test::MockObject', "mock conf object" );
   46     $mock_conf->fake_module( 'Sendpage::KeesConf' );
   47     $mock_conf->fake_new( 'Sendpage::KeesConf' );
   48     $mock_conf->set_isa( 'Sendpage::KeesConf' );
   49 
   50     foreach (keys %conf_mock_methods) {
   51 	$mock_conf->mock( $_ => $conf_mock_methods{ $_ } );
   52 	can_ok( $mock_conf, $_ );
   53     }
   54     use_ok( 'Sendpage::KeesConf' );
   55 
   56     use_ok( 'Sendpage::Recipient' ) or die;
   57 }
   58 
   59 CONSTRUCTOR: {
   60     my $config = Sendpage::KeesConf->new();
   61     isa_ok( $config, 'Sendpage::KeesConf' );
   62 
   63     my $db;
   64     my $name = "test";
   65     my %data =
   66 	(
   67 	 'email-cc' => 'zakame',
   68 	);
   69 
   70     my $recip = Sendpage::Recipient->new( $config, $db, $name, \%data );
   71     isa_ok( $recip, 'Sendpage::Recipient' );
   72 
   73     my @functions = qw( alias dests data datum pin pc name );
   74     can_ok( $recip, $_ ) foreach @functions;
   75 
   76     ok( $recip->alias, "have a valid alias" );
   77     is_deeply( $recip->dests,
   78 	       [ qw(foo bar baz) ],
   79 	       "found dests" );
   80     is_deeply( $recip->data,
   81 	       \%data,
   82 	       "found data" );
   83     is( $recip->datum('email-cc'),
   84 	'zakame',
   85 	"found datum" );
   86     is( $recip->name,
   87 	'test',
   88 	"found name" );
   89 
   90  TODO: {
   91 	local $TODO = "PINs and PC not yet defined";
   92 	isnt( $recip->pin,
   93 	    undef,
   94 	    "found PIN" );
   95 	isnt( $recip->pc,
   96 	    undef,
   97 	    "found paging central");
   98     }
   99 }
  100 
  101 # /* vim: set filetype=perl : */