Bug 7688: (follow-up) add unit tests for C4::Serials::GetNextSeq()
[koha.git] / t / SocialData.t
blob06705a5f223aaacd98a6bd566f1e3d5de1e4ff16
1 #!/usr/bin/perl
3 #Testing C4 SocialData
5 use strict;
6 use warnings;
7 use Test::More tests => 5;
8 use Test::MockModule;
10 BEGIN {
11 use_ok('C4::SocialData');
14 my $module = new Test::MockModule('C4::Context');
15 $module->mock(
16 '_new_dbh',
17 sub {
18 my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
19 || die "Cannot create handle: $DBI::errstr\n";
20 return $dbh;
23 my $socialdata = [
25 'isbn', 'num_critics',
26 'num_critics_pro', 'num_quotations',
27 'num_videos', 'score_avg',
28 'num_scores'
30 [ '0-596-52674-1', 1, 2, 3, 4, 5.2, 6 ],
31 [ '0-596-00289-0', 2, 3, 4, 5, 6.2, 7 ]
33 my $dbh = C4::Context->dbh();
35 $dbh->{mock_add_resultset} = $socialdata;
37 my $data = C4::SocialData::get_data();
39 is( $data->{'isbn'}, '0-596-52674-1', 'First isbn is 0-596-52674-1' );
41 my $reportdata =
42 [ [ 'biblionumber', 'isbn' ], [ 1, '0-596-52674-1' ],
43 [ 2, '0-596-00289-0' ] ];
45 use Data::Dumper;
47 $dbh->{mock_add_resultset} = $reportdata;
49 ok( my $report = C4::SocialData::get_report() );
51 is( $report->{'without'}->[0]->{'original'},
52 '0-596-52674-1', 'testing get_report gives isbn' );
54 is( $report->{'without'}->[0]->{'isbn'}, '9780596526740',
55 'testing get_report' );