Koha/t/Letters.t
Jared Camins-Esakov 2189b88bb1 Bug 9486: t/Letters.t loads modules in wrong order
Because the unit test t/Letters.t loads C4::Letters before C4::Context,
and C4::Letters is not even vaguely thread-safe, the test tends to fail.
Usually. Moving the dbh mocking to before the use_ok('C4::Letters') test
fixes the problem.

To test:
1) Before applying patch, run `prove t/Letters.t` a few times. Note that
   it fails most of the time, if not all the time.
2) Apply patch.
3) Repeat step (1), noting that now it passes every time.

Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Works as advertised.
Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com>
2013-01-24 14:44:59 -05:00

34 lines
852 B
Perl
Executable file

#!/usr/bin/perl
#
# This Koha test module is a stub!
# Add more tests here!!!
use strict;
use warnings;
use Test::MockModule;
use Test::More tests => 2;
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' ]
];
use_ok('C4::Letters');
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' );