Bug 16330: Add routes to add, update and delete patrons
[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
39 fixtures_ok [
40     Biblioitem => [
41         ['biblionumber', 'isbn'],
42         [1, '0-596-52674-1'],
43         [2, '0-596-00289-0'],
44     ],
45     SocialData => [
46         [
47             'isbn',            'num_critics',
48             'num_critics_pro', 'num_quotations',
49             'num_videos',      'score_avg',
50             'num_scores'
51         ],
52         [ '0-596-52674-1', 1, 2, 3, 4, 5.2, 6 ],
53         [ '0-596-00289-0', 2, 3, 4, 5, 6.2, 7 ]
54     ],
55 ], 'add fixtures';
56
57 my $db = Test::MockModule->new('Koha::Database');
58 $db->mock( _new_schema => sub { return Schema(); } );
59 Koha::Database::flush_schema_cache();
60
61 my $data = C4::SocialData::get_data();
62 is( $data, undef, 'get_data should return undef if no param given');
63
64 $data = C4::SocialData::get_data('0-596-52674-1');
65 is( $data->{isbn}, '0-596-52674-1', 'get_data should return the matching row');
66
67 my $report =  C4::SocialData::get_report('0-596-52674-1');
68
69 is( $report->{'without'}->[0]->{'original'},
70     '0-596-52674-1', 'testing get_report gives isbn' );
71
72 is( $report->{'without'}->[0]->{'isbn'}, '9780596526740',
73     'testing get_report' );
74