From f2a35e5cc9e38f830459c4b07858de69166c4623 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 20 Oct 2015 14:21:45 +0100 Subject: [PATCH] Bug 14778: Install fixtures for t/SocialData.t Signed-off-by: Martin Renvoize --- t/SocialData.t | 64 ++++++++++++++++++++++++++++------------------------------ 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/t/SocialData.t b/t/SocialData.t index 06705a5..3d6cd1a 100644 --- a/t/SocialData.t +++ b/t/SocialData.t @@ -2,51 +2,49 @@ # #Testing C4 SocialData -use strict; -use warnings; -use Test::More tests => 5; +use Modern::Perl; +use Test::More tests => 6; use Test::MockModule; BEGIN { use_ok('C4::SocialData'); } -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 $socialdata = [ - [ - 'isbn', 'num_critics', - 'num_critics_pro', 'num_quotations', - 'num_videos', 'score_avg', - 'num_scores' +use Test::DBIx::Class { + schema_class => 'Koha::Schema', + connect_info => ['dbi:SQLite:dbname=:memory:','',''], + connect_opts => { name_sep => '.', quote_char => '`', }, + fixture_class => '::Populate', +}, 'SocialData', 'Biblioitem' ; + +fixtures_ok [ + Biblioitem => [ + ['biblionumber', 'isbn'], + [1, '0-596-52674-1'], + [2, '0-596-00289-0'], ], - [ '0-596-52674-1', 1, 2, 3, 4, 5.2, 6 ], - [ '0-596-00289-0', 2, 3, 4, 5, 6.2, 7 ] -]; -my $dbh = C4::Context->dbh(); + SocialData => [ + [ + 'isbn', 'num_critics', + 'num_critics_pro', 'num_quotations', + 'num_videos', 'score_avg', + 'num_scores' + ], + [ '0-596-52674-1', 1, 2, 3, 4, 5.2, 6 ], + [ '0-596-00289-0', 2, 3, 4, 5, 6.2, 7 ] + ], +], 'add fixtures'; -$dbh->{mock_add_resultset} = $socialdata; +my $db = Test::MockModule->new('Koha::Database'); +$db->mock( _new_schema => sub { return Schema(); } ); my $data = C4::SocialData::get_data(); +is( $data, undef, 'get_data should return undef if no param given'); -is( $data->{'isbn'}, '0-596-52674-1', 'First isbn is 0-596-52674-1' ); - -my $reportdata = - [ [ 'biblionumber', 'isbn' ], [ 1, '0-596-52674-1' ], - [ 2, '0-596-00289-0' ] ]; - -use Data::Dumper; - -$dbh->{mock_add_resultset} = $reportdata; +$data = C4::SocialData::get_data('0-596-52674-1'); +is( $data->{isbn}, '0-596-52674-1', 'get_data should return the matching row'); -ok( my $report = C4::SocialData::get_report() ); +my $report = C4::SocialData::get_report('0-596-52674-1'); is( $report->{'without'}->[0]->{'original'}, '0-596-52674-1', 'testing get_report gives isbn' ); -- 2.1.4