Bug 16829: Add 'interface' to the log viewer
[koha.git] / t / SocialData.t
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19
20 use Test::More;
21 use Test::MockModule;
22
23 use Module::Load::Conditional qw/check_install/;
24
25 BEGIN {
26     if ( check_install( module => 'Test::DBIx::Class' ) ) {
27         plan tests => 6;
28     } else {
29         plan skip_all => "Need Test::DBIx::Class"
30     }
31 }
32
33 BEGIN {
34     use_ok('C4::SocialData');
35 }
36
37 use Test::DBIx::Class {
38     schema_class => 'Koha::Schema',
39     connect_info => ['dbi:SQLite:dbname=:memory:','',''],
40     connect_opts => { name_sep => '.', quote_char => '`', },
41     fixture_class => '::Populate',
42 }, 'SocialData', 'Biblioitem' ;
43
44 fixtures_ok [
45     Biblioitem => [
46         ['biblionumber', 'isbn'],
47         [1, '0-596-52674-1'],
48         [2, '0-596-00289-0'],
49     ],
50     SocialData => [
51         [
52             'isbn',            'num_critics',
53             'num_critics_pro', 'num_quotations',
54             'num_videos',      'score_avg',
55             'num_scores'
56         ],
57         [ '0-596-52674-1', 1, 2, 3, 4, 5.2, 6 ],
58         [ '0-596-00289-0', 2, 3, 4, 5, 6.2, 7 ]
59     ],
60 ], 'add fixtures';
61
62 my $db = Test::MockModule->new('Koha::Database');
63 $db->mock( _new_schema => sub { return Schema(); } );
64
65 my $data = C4::SocialData::get_data();
66 is( $data, undef, 'get_data should return undef if no param given');
67
68 $data = C4::SocialData::get_data('0-596-52674-1');
69 is( $data->{isbn}, '0-596-52674-1', 'get_data should return the matching row');
70
71 my $report =  C4::SocialData::get_report('0-596-52674-1');
72
73 is( $report->{'without'}->[0]->{'original'},
74     '0-596-52674-1', 'testing get_report gives isbn' );
75
76 is( $report->{'without'}->[0]->{'isbn'}, '9780596526740',
77     'testing get_report' );
78
79 1;