Bug 14778: Install fixtures for t/SocialData.t
[koha.git] / t / SocialData.t
1 #!/usr/bin/perl
2 #
3 #Testing C4 SocialData
4
5 use Modern::Perl;
6 use Test::More tests => 6;
7 use Test::MockModule;
8
9 BEGIN {
10     use_ok('C4::SocialData');
11 }
12
13 use Test::DBIx::Class {
14     schema_class => 'Koha::Schema',
15     connect_info => ['dbi:SQLite:dbname=:memory:','',''],
16     connect_opts => { name_sep => '.', quote_char => '`', },
17     fixture_class => '::Populate',
18 }, 'SocialData', 'Biblioitem' ;
19
20 fixtures_ok [
21     Biblioitem => [
22         ['biblionumber', 'isbn'],
23         [1, '0-596-52674-1'],
24         [2, '0-596-00289-0'],
25     ],
26     SocialData => [
27         [
28             'isbn',            'num_critics',
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';
37
38 my $db = Test::MockModule->new('Koha::Database');
39 $db->mock( _new_schema => sub { return Schema(); } );
40
41 my $data = C4::SocialData::get_data();
42 is( $data, undef, 'get_data should return undef if no param given');
43
44 $data = C4::SocialData::get_data('0-596-52674-1');
45 is( $data->{isbn}, '0-596-52674-1', 'get_data should return the matching row');
46
47 my $report =  C4::SocialData::get_report('0-596-52674-1');
48
49 is( $report->{'without'}->[0]->{'original'},
50     '0-596-52674-1', 'testing get_report gives isbn' );
51
52 is( $report->{'without'}->[0]->{'isbn'}, '9780596526740',
53     'testing get_report' );