From f897357dccbc2cca9124eac5238ee5937e361f17 Mon Sep 17 00:00:00 2001 From: Bart Jorgensen Date: Thu, 9 Aug 2012 17:01:56 +1200 Subject: [PATCH 4/4] Added a mock-db table and tested a line --- t/Letters.t | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/t/Letters.t b/t/Letters.t index 603e37e..99f65ec 100755 --- a/t/Letters.t +++ b/t/Letters.t @@ -5,10 +5,28 @@ use strict; use warnings; - -use Test::More tests => 1; +use Test::MockModule; +use Test::More tests => 2; BEGIN { use_ok('C4::Letters'); } +my $module = new Test::MockModule('C4::Context'); +$module->mock('_new_dbh', sub { + my $dbh = DBI->connect( 'DBI:Mock:', '', '' ) + || die "Cannot create handle: $DBI::errstr\n"; + return $dbh }); +my $mock_letters = [ + ['module','code','branchcode','name','is_html','title','content'], + ['blah','ISBN','NBSI','book',1,'green','blahblah'], + ['bleh','ISSN','NSSI','page',0,'blue','blehbleh'] + ]; + +my $dbh = C4::Context->dbh(); + +$dbh->{mock_add_resultset} = $mock_letters; + +my $letters=C4::Letters::GetLetters(); + +is($letters->{ISBN},'book', 'HASH ref of ISBN is book'); -- 1.7.9.5