Lines 2-52
Link Here
|
2 |
# |
2 |
# |
3 |
#Testing C4 SocialData |
3 |
#Testing C4 SocialData |
4 |
|
4 |
|
5 |
use strict; |
5 |
use Modern::Perl; |
6 |
use warnings; |
6 |
use Test::More tests => 6; |
7 |
use Test::More tests => 5; |
|
|
8 |
use Test::MockModule; |
7 |
use Test::MockModule; |
9 |
|
8 |
|
10 |
BEGIN { |
9 |
BEGIN { |
11 |
use_ok('C4::SocialData'); |
10 |
use_ok('C4::SocialData'); |
12 |
} |
11 |
} |
13 |
|
12 |
|
14 |
my $module = new Test::MockModule('C4::Context'); |
13 |
use Test::DBIx::Class { |
15 |
$module->mock( |
14 |
schema_class => 'Koha::Schema', |
16 |
'_new_dbh', |
15 |
connect_info => ['dbi:SQLite:dbname=:memory:','',''], |
17 |
sub { |
16 |
connect_opts => { name_sep => '.', quote_char => '`', }, |
18 |
my $dbh = DBI->connect( 'DBI:Mock:', '', '' ) |
17 |
fixture_class => '::Populate', |
19 |
|| die "Cannot create handle: $DBI::errstr\n"; |
18 |
}, 'SocialData', 'Biblioitem' ; |
20 |
return $dbh; |
19 |
|
21 |
} |
20 |
fixtures_ok [ |
22 |
); |
21 |
Biblioitem => [ |
23 |
my $socialdata = [ |
22 |
['biblionumber', 'isbn'], |
24 |
[ |
23 |
[1, '0-596-52674-1'], |
25 |
'isbn', 'num_critics', |
24 |
[2, '0-596-00289-0'], |
26 |
'num_critics_pro', 'num_quotations', |
|
|
27 |
'num_videos', 'score_avg', |
28 |
'num_scores' |
29 |
], |
25 |
], |
30 |
[ '0-596-52674-1', 1, 2, 3, 4, 5.2, 6 ], |
26 |
SocialData => [ |
31 |
[ '0-596-00289-0', 2, 3, 4, 5, 6.2, 7 ] |
27 |
[ |
32 |
]; |
28 |
'isbn', 'num_critics', |
33 |
my $dbh = C4::Context->dbh(); |
29 |
'num_critics_pro', 'num_quotations', |
|
|
30 |
'num_videos', 'score_avg', |
31 |
'num_scores' |
32 |
], |
33 |
[ '0-596-52674-1', 1, 2, 3, 4, 5.2, 6 ], |
34 |
[ '0-596-00289-0', 2, 3, 4, 5, 6.2, 7 ] |
35 |
], |
36 |
], 'add fixtures'; |
34 |
|
37 |
|
35 |
$dbh->{mock_add_resultset} = $socialdata; |
38 |
my $db = Test::MockModule->new('Koha::Database'); |
|
|
39 |
$db->mock( _new_schema => sub { return Schema(); } ); |
36 |
|
40 |
|
37 |
my $data = C4::SocialData::get_data(); |
41 |
my $data = C4::SocialData::get_data(); |
|
|
42 |
is( $data, undef, 'get_data should return undef if no param given'); |
38 |
|
43 |
|
39 |
is( $data->{'isbn'}, '0-596-52674-1', 'First isbn is 0-596-52674-1' ); |
44 |
$data = C4::SocialData::get_data('0-596-52674-1'); |
40 |
|
45 |
is( $data->{isbn}, '0-596-52674-1', 'get_data should return the matching row'); |
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 |
|
46 |
|
49 |
ok( my $report = C4::SocialData::get_report() ); |
47 |
my $report = C4::SocialData::get_report('0-596-52674-1'); |
50 |
|
48 |
|
51 |
is( $report->{'without'}->[0]->{'original'}, |
49 |
is( $report->{'without'}->[0]->{'original'}, |
52 |
'0-596-52674-1', 'testing get_report gives isbn' ); |
50 |
'0-596-52674-1', 'testing get_report gives isbn' ); |
53 |
- |
|
|