Bugzilla – Attachment 155091 Details for
Bug 33833
Remove Test::DBIx::Class from t/SocialData.t
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33833: Use database in t/Socialdata.t
Bug-33833-Use-database-in-tSocialdatat.patch (text/plain), 4.32 KB, created by
Jonathan Druart
on 2023-09-01 10:07:13 UTC
(
hide
)
Description:
Bug 33833: Use database in t/Socialdata.t
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2023-09-01 10:07:13 UTC
Size:
4.32 KB
patch
obsolete
>From 4197dfdfd135514c38742fad0a0d328dd5de207e Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Mon, 22 May 2023 08:41:02 +0000 >Subject: [PATCH] Bug 33833: Use database in t/Socialdata.t > >Remove T::D::C. >Add subtests. >Remove useless parameter from get_report call. >Add two additional trivial tests. > >Note: The module C4::SocialData looks a bit weird. > >Test plan: >Run t/SocialData.t > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Signed-off-by: Owen Leonard <oleonard@myacpl.org> > >Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >--- > t/SocialData.t | 79 ++++++++++++++++++++++---------------------------- > 1 file changed, 35 insertions(+), 44 deletions(-) > >diff --git a/t/SocialData.t b/t/SocialData.t >index 97d657529fd..b0f51c3a3ec 100755 >--- a/t/SocialData.t >+++ b/t/SocialData.t >@@ -1,5 +1,7 @@ > #!/usr/bin/perl > >+# Copyright 2012, 2023 Koha development team >+# > # This file is part of Koha. > # > # Koha is free software; you can redistribute it and/or modify it >@@ -16,59 +18,48 @@ > # along with Koha; if not, see <http://www.gnu.org/licenses>. > > use Modern::Perl; >+use Test::More tests => 2; > >-use Test::More; >-use Test::MockModule; >- >-use Module::Load::Conditional qw/check_install/; >+use t::lib::TestBuilder; > >-BEGIN { >- if ( check_install( module => 'Test::DBIx::Class' ) ) { >- plan tests => 6; >- } else { >- plan skip_all => "Need Test::DBIx::Class" >- } >-} >+use Koha::Database; >+use C4::SocialData qw( get_data get_report ); > >-BEGIN { >- use_ok('C4::SocialData', qw( get_data get_report )); >-} >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; > >-use Test::DBIx::Class; >+$schema->storage->txn_begin; > >-fixtures_ok [ >- Biblioitem => [ >- ['biblionumber', 'isbn'], >- [1, '0-596-52674-1'], >- [2, '0-596-00289-0'], >- ], >- SocialData => [ >- [ >- 'isbn', 'num_critics', >- 'num_critics_pro', 'num_quotations', >- 'num_videos', 'score_avg', >- 'num_scores' >- ], >- [ '0-596-52674-1', 1, 2, 3, 4, 5.2, 6 ], >- [ '0-596-00289-0', 2, 3, 4, 5, 6.2, 7 ] >- ], >-], 'add fixtures'; >+# trivial data for trivial tests >+Koha::Biblioitems->search->update({ isbn => undef }); >+$builder->build({ source => 'Biblioitem', value => { isbn => '0-596-52674-1' } }); >+$builder->build({ source => 'Biblioitem', value => { isbn => '0-596-00289-0' } }); >+$builder->build({ source => 'SocialData', value => { isbn => '0-596-52674-1', score_avg => 6.5 } }); >+$builder->build({ source => 'SocialData', value => { isbn => '0-596-00289-0', score_avg => 7 } }); > >-my $db = Test::MockModule->new('Koha::Database'); >-$db->mock( _new_schema => sub { return Schema(); } ); >-Koha::Database::flush_schema_cache(); >+subtest 'get_data' => sub { >+ plan tests => 3; > >-my $data = C4::SocialData::get_data(); >-is( $data, undef, 'get_data should return undef if no param given'); >+ my $data = C4::SocialData::get_data(); >+ is( $data, undef, 'get_data should return undef if no param given'); > >-$data = C4::SocialData::get_data('0-596-52674-1'); >-is( $data->{isbn}, '0-596-52674-1', 'get_data should return the matching row'); >+ $data = C4::SocialData::get_data('0-596-52674-1'); >+ is( $data->{isbn}, '0-596-52674-1', 'get_data should return the matching row'); >+ is( sprintf("%3.1f", $data->{score_avg}), 6.5, 'check score_avg'); >+}; > >-my $report = C4::SocialData::get_report('0-596-52674-1'); >+subtest 'get_report' => sub { >+ plan tests => 3; > >-is( $report->{'without'}->[0]->{'original'}, >- '0-596-52674-1', 'testing get_report gives isbn' ); >+ my $report = C4::SocialData::get_report(); >+ # if isbn not normalized, social data not found, resulting in without key >+ is( $report->{'without'}->[0]->{'original'}, '0-596-52674-1', 'testing get_report gives isbn' ); >+ is( $report->{'without'}->[0]->{'isbn'}, '9780596526740', 'testing get_report' ); > >-is( $report->{'without'}->[0]->{'isbn'}, '9780596526740', >- 'testing get_report' ); >+ # test if we can get with key instead >+ $schema->resultset('SocialData')->search({ isbn => '0-596-52674-1' })->next->update({ isbn => '9780596526740' }); >+ $report = C4::SocialData::get_report(); >+ is( $report->{with}->[0]->{isbn}, '9780596526740', 'this isbn has social data' ); >+}; > >+$schema->storage->txn_rollback; >-- >2.25.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 33833
:
151679
|
151680
|
151681
|
151682
|
151689
|
151690
|
151691
| 155091 |
155092
|
155093