Jonathan Druart
9f0e2c59b8
C4::Context::_new_dbh does not exist anymore. Koha::Database::_new_schema should be mocked instead. Will fix: - t/00-load.t - t/Breeding.t - t/ImportBatch.t - t/Message.t - t/Overdues.t - t/Prices.t - t/RotatingCollections.t - t/Search.t - t/SuggestionEngine_AuthorityFile.t - t/XSLT.t Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
50 lines
1.2 KiB
Perl
50 lines
1.2 KiB
Perl
package t::lib::Mocks;
|
|
|
|
use Modern::Perl;
|
|
use C4::Context;
|
|
|
|
use Koha::Schema;
|
|
use Test::MockModule;
|
|
|
|
my %configs;
|
|
sub mock_config {
|
|
my $context = new Test::MockModule('C4::Context');
|
|
my ( $conf, $value ) = @_;
|
|
$configs{$conf} = $value;
|
|
$context->mock('config', sub {
|
|
my ( $self, $conf ) = @_;
|
|
if ( exists $configs{$conf} ) {
|
|
return $configs{$conf}
|
|
} else {
|
|
my $method = $context->original('config');
|
|
return $method->($self, $conf);
|
|
}
|
|
});
|
|
}
|
|
|
|
my %preferences;
|
|
sub mock_preference {
|
|
my $context = new Test::MockModule('C4::Context');
|
|
my ( $pref, $value ) = @_;
|
|
$preferences{$pref} = $value;
|
|
$context->mock('preference', sub {
|
|
my ( $self, $pref ) = @_;
|
|
if ( exists $preferences{$pref} ) {
|
|
return $preferences{$pref}
|
|
} else {
|
|
my $method = $context->original('preference');
|
|
return $method->($self, $pref);
|
|
}
|
|
});
|
|
}
|
|
|
|
sub mock_dbh {
|
|
our $context = new Test::MockModule('Koha::Database');
|
|
$context->mock( '_new_schema', sub {
|
|
my $dbh = Koha::Schema->connect( 'DBI:Mock:', '', '' );
|
|
return $dbh;
|
|
} );
|
|
return $context;
|
|
}
|
|
|
|
1;
|