|
Lines 1-5
Link Here
|
| 1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
| 2 |
|
2 |
|
|
|
3 |
# Copyright 2012, 2023 Koha development team |
| 4 |
# |
| 3 |
# This file is part of Koha. |
5 |
# This file is part of Koha. |
| 4 |
# |
6 |
# |
| 5 |
# Koha is free software; you can redistribute it and/or modify it |
7 |
# Koha is free software; you can redistribute it and/or modify it |
|
Lines 16-74
Link Here
|
| 16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 17 |
|
19 |
|
| 18 |
use Modern::Perl; |
20 |
use Modern::Perl; |
|
|
21 |
use Test::More tests => 2; |
| 19 |
|
22 |
|
| 20 |
use Test::More; |
23 |
use t::lib::TestBuilder; |
| 21 |
use Test::MockModule; |
|
|
| 22 |
|
| 23 |
use Module::Load::Conditional qw/check_install/; |
| 24 |
|
24 |
|
| 25 |
BEGIN { |
25 |
use Koha::Database; |
| 26 |
if ( check_install( module => 'Test::DBIx::Class' ) ) { |
26 |
use C4::SocialData qw( get_data get_report ); |
| 27 |
plan tests => 6; |
|
|
| 28 |
} else { |
| 29 |
plan skip_all => "Need Test::DBIx::Class" |
| 30 |
} |
| 31 |
} |
| 32 |
|
27 |
|
| 33 |
BEGIN { |
28 |
my $schema = Koha::Database->new->schema; |
| 34 |
use_ok('C4::SocialData', qw( get_data get_report )); |
29 |
my $builder = t::lib::TestBuilder->new; |
| 35 |
} |
|
|
| 36 |
|
30 |
|
| 37 |
use Test::DBIx::Class; |
31 |
$schema->storage->txn_begin; |
| 38 |
|
32 |
|
| 39 |
fixtures_ok [ |
33 |
# trivial data for trivial tests |
| 40 |
Biblioitem => [ |
34 |
Koha::Biblioitems->search->update({ isbn => undef }); |
| 41 |
['biblionumber', 'isbn'], |
35 |
$builder->build({ source => 'Biblioitem', value => { isbn => '0-596-52674-1' } }); |
| 42 |
[1, '0-596-52674-1'], |
36 |
$builder->build({ source => 'Biblioitem', value => { isbn => '0-596-00289-0' } }); |
| 43 |
[2, '0-596-00289-0'], |
37 |
$builder->build({ source => 'SocialData', value => { isbn => '0-596-52674-1', score_avg => 6.5 } }); |
| 44 |
], |
38 |
$builder->build({ source => 'SocialData', value => { isbn => '0-596-00289-0', score_avg => 7 } }); |
| 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 |
|
39 |
|
| 57 |
my $db = Test::MockModule->new('Koha::Database'); |
40 |
subtest 'get_data' => sub { |
| 58 |
$db->mock( _new_schema => sub { return Schema(); } ); |
41 |
plan tests => 3; |
| 59 |
Koha::Database::flush_schema_cache(); |
|
|
| 60 |
|
42 |
|
| 61 |
my $data = C4::SocialData::get_data(); |
43 |
my $data = C4::SocialData::get_data(); |
| 62 |
is( $data, undef, 'get_data should return undef if no param given'); |
44 |
is( $data, undef, 'get_data should return undef if no param given'); |
| 63 |
|
45 |
|
| 64 |
$data = C4::SocialData::get_data('0-596-52674-1'); |
46 |
$data = C4::SocialData::get_data('0-596-52674-1'); |
| 65 |
is( $data->{isbn}, '0-596-52674-1', 'get_data should return the matching row'); |
47 |
is( $data->{isbn}, '0-596-52674-1', 'get_data should return the matching row'); |
|
|
48 |
is( sprintf("%3.1f", $data->{score_avg}), 6.5, 'check score_avg'); |
| 49 |
}; |
| 66 |
|
50 |
|
| 67 |
my $report = C4::SocialData::get_report('0-596-52674-1'); |
51 |
subtest 'get_report' => sub { |
|
|
52 |
plan tests => 3; |
| 68 |
|
53 |
|
| 69 |
is( $report->{'without'}->[0]->{'original'}, |
54 |
my $report = C4::SocialData::get_report(); |
| 70 |
'0-596-52674-1', 'testing get_report gives isbn' ); |
55 |
# if isbn not normalized, social data not found, resulting in without key |
|
|
56 |
is( $report->{'without'}->[0]->{'original'}, '0-596-52674-1', 'testing get_report gives isbn' ); |
| 57 |
is( $report->{'without'}->[0]->{'isbn'}, '9780596526740', 'testing get_report' ); |
| 71 |
|
58 |
|
| 72 |
is( $report->{'without'}->[0]->{'isbn'}, '9780596526740', |
59 |
# test if we can get with key instead |
| 73 |
'testing get_report' ); |
60 |
$schema->resultset('SocialData')->search({ isbn => '0-596-52674-1' })->next->update({ isbn => '9780596526740' }); |
|
|
61 |
$report = C4::SocialData::get_report(); |
| 62 |
is( $report->{with}->[0]->{isbn}, '9780596526740', 'this isbn has social data' ); |
| 63 |
}; |
| 74 |
|
64 |
|
| 75 |
- |
65 |
$schema->storage->txn_rollback; |