Added a mock-db table and tested a line
authorBart Jorgensen <bart.tj@gmail.com>
Thu, 9 Aug 2012 05:01:56 +0000 (17:01 +1200)
committerPaul Poulain <paul.poulain@biblibre.com>
Fri, 7 Sep 2012 12:31:55 +0000 (14:31 +0200)
http://bugs.koha-community.org/show_bug.cgi?id=5327
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
All tests pass!

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
t/Letters.t

index 603e37e..b269e86 100755 (executable)
@@ -1,14 +1,36 @@
 #!/usr/bin/perl
 #
-# This Koha test module is a stub!  
+# This Koha test module is a stub!
 # Add more tests here!!!
 
 use strict;
 use warnings;
-
-use Test::More tests => 1;
+use Test::MockModule;
+use Test::More tests => 2;
 
 BEGIN {
-        use_ok('C4::Letters');
+    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' );