|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
# |
| 3 |
#Testing C4 SocialData |
| 4 |
|
| 5 |
use strict; |
| 6 |
use warnings; |
| 7 |
use Test::More tests => 5; |
| 8 |
use Test::MockModule; |
| 9 |
|
| 10 |
BEGIN { |
| 11 |
use_ok('C4::SocialData'); |
| 12 |
} |
| 13 |
|
| 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; |
| 21 |
} |
| 22 |
); |
| 23 |
my $socialdata = [ |
| 24 |
[ |
| 25 |
'isbn', 'num_critics', |
| 26 |
'num_critics_pro', 'num_quotations', |
| 27 |
'num_videos', 'score_avg', |
| 28 |
'num_scores' |
| 29 |
], |
| 30 |
[ '0-596-52674-1', 1, 2, 3, 4, 5.2, 6 ], |
| 31 |
[ '0-596-00289-0', 2, 3, 4, 5, 6.2, 7 ] |
| 32 |
]; |
| 33 |
my $dbh = C4::Context->dbh(); |
| 34 |
|
| 35 |
$dbh->{mock_add_resultset} = $socialdata; |
| 36 |
|
| 37 |
my $data = C4::SocialData::get_data(); |
| 38 |
|
| 39 |
is( $data->{'isbn'}, '0-596-52674-1', 'First isbn is 0-596-52674-1' ); |
| 40 |
|
| 41 |
my $reportdata = |
| 42 |
[ [ 'biblionumber', 'isbn' ], [ 1, '0-596-52674-1' ], |
| 43 |
[ 2, '0-596-00289-0' ] ]; |
| 44 |
|
| 45 |
use Data::Dumper; |
| 46 |
|
| 47 |
$dbh->{mock_add_resultset} = $reportdata; |
| 48 |
|
| 49 |
ok( my $report = C4::SocialData::get_report() ); |
| 50 |
|
| 51 |
is( $report->{'without'}->[0]->{'original'}, |
| 52 |
'0-596-52674-1', 'testing get_report gives isbn' ); |
| 53 |
|
| 54 |
is( $report->{'without'}->[0]->{'isbn'}, '9780596526740', |
| 55 |
'testing get_report' ); |