Bugzilla – Attachment 135004 Details for
Bug 30756
Get skip block out of Koha_Authority.t and add TestBuilder
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30756: Ground work for improving Koha_Authority.t
Bug-30756-Ground-work-for-improving-KohaAuthorityt.patch (text/plain), 6.37 KB, created by
David Nind
on 2022-05-15 00:21:43 UTC
(
hide
)
Description:
Bug 30756: Ground work for improving Koha_Authority.t
Filename:
MIME Type:
Creator:
David Nind
Created:
2022-05-15 00:21:43 UTC
Size:
6.37 KB
patch
obsolete
>From 349ade95f6ac835dcd86f0437fd62672b72fd6ee Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Sat, 14 May 2022 07:42:42 +0000 >Subject: [PATCH] Bug 30756: Ground work for improving Koha_Authority.t > >Move stuff into two subtests. > >Test plan: >Run t/db_dependent/Koha_Authority.t. >If you have no imported auths, you will still see skips. > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> > >Signed-off-by: David Nind <david@davidnind.com> >--- > t/db_dependent/Koha_Authority.t | 109 +++++++++++++++++--------------- > 1 file changed, 57 insertions(+), 52 deletions(-) > >diff --git a/t/db_dependent/Koha_Authority.t b/t/db_dependent/Koha_Authority.t >index e5764579f4..159bb3bb20 100755 >--- a/t/db_dependent/Koha_Authority.t >+++ b/t/db_dependent/Koha_Authority.t >@@ -18,85 +18,90 @@ > # along with Koha; if not, see <http://www.gnu.org/licenses>. > > use Modern::Perl; >+use Test::More tests => 3; > >-use C4::Context; >-use C4::Charset qw( MarcToUTF8Record ); >-use C4::AuthoritiesMarc qw( AddAuthority ); >-use Koha::Database; >-use Test::More; > use File::Basename; > use MARC::Batch; > use MARC::File; > use IO::File; >+ >+use C4::Context; >+use C4::Charset qw( MarcToUTF8Record ); >+use C4::AuthoritiesMarc qw( AddAuthority ); >+use Koha::Database; > use Koha::Authorities; > > BEGIN { > use_ok('Koha::MetadataRecord::Authority'); > } > >-my $schema = Koha::Database->new->schema; >+our $schema = Koha::Database->new->schema; > $schema->storage->txn_begin; >+our $dbh = C4::Context->dbh; >+ >+subtest 'Part 1' => sub { >+ # TODO Move this part to a t/lib packages >+ my $sourcedir = dirname(__FILE__) . "/data"; >+ my $input_marc_file = "$sourcedir/marc21/zebraexport/authority/exported_records"; >+ >+ my $fh = IO::File->new($input_marc_file); >+ my $batch = MARC::Batch->new( 'USMARC', $fh ); >+ while ( my $record = $batch->next ) { >+ C4::Charset::MarcToUTF8Record($record, 'MARC21'); >+ AddAuthority($record, '', ''); >+ } > >-# TODO Move this part to a t/lib packages >-my $sourcedir = dirname(__FILE__) . "/data"; >-my $input_marc_file = "$sourcedir/marc21/zebraexport/authority/exported_records"; >+ my $record = MARC::Record->new; >+ $record->add_fields( >+ [ '001', '1234' ], >+ [ '150', ' ', ' ', a => 'Cooking' ], >+ [ '450', ' ', ' ', a => 'Cookery' ], >+ ); >+ my $authority = Koha::MetadataRecord::Authority->new($record); > >-my $fh = IO::File->new($input_marc_file); >-my $batch = MARC::Batch->new( 'USMARC', $fh ); >-while ( my $record = $batch->next ) { >- C4::Charset::MarcToUTF8Record($record, 'MARC21'); >- AddAuthority($record, '', ''); >-} >+ is(ref($authority), 'Koha::MetadataRecord::Authority', 'Created valid Koha::MetadataRecord::Authority object'); > >-my $record = MARC::Record->new; >-$record->add_fields( >- [ '001', '1234' ], >- [ '150', ' ', ' ', a => 'Cooking' ], >- [ '450', ' ', ' ', a => 'Cookery' ], >- ); >-my $authority = Koha::MetadataRecord::Authority->new($record); >+ is($authority->authorized_heading(), 'Cooking', 'Authorized heading was correct'); > >-is(ref($authority), 'Koha::MetadataRecord::Authority', 'Created valid Koha::MetadataRecord::Authority object'); >+ is_deeply($authority->record, $record, 'Saved record'); > >-is($authority->authorized_heading(), 'Cooking', 'Authorized heading was correct'); >+ my $authid = Koha::Authorities->search->next->authid; > >-is_deeply($authority->record, $record, 'Saved record'); >+ $authority = Koha::MetadataRecord::Authority->get_from_authid($authid); > >-my $authid = Koha::Authorities->search->next->authid; >+ is(ref($authority), 'Koha::MetadataRecord::Authority', 'Retrieved valid Koha::MetadataRecord::Authority object'); > >-$authority = Koha::MetadataRecord::Authority->get_from_authid($authid); >+ is($authority->authid, $authid, 'Object authid is correct'); > >-is(ref($authority), 'Koha::MetadataRecord::Authority', 'Retrieved valid Koha::MetadataRecord::Authority object'); >+ is($authority->record->field('001')->data(), $authid, 'Retrieved correct record'); > >-is($authority->authid, $authid, 'Object authid is correct'); >+ $authority = Koha::MetadataRecord::Authority->get_from_authid('alphabetsoup'); >+ is($authority, undef, 'No invalid record is retrieved'); >+}; > >-is($authority->record->field('001')->data(), $authid, 'Retrieved correct record'); >+subtest 'Part2' => sub { >+ SKIP: { >+ my $sth = $dbh->prepare("SELECT import_record_id FROM import_records WHERE record_type = 'auth' LIMIT 1;"); >+ $sth->execute(); > >-$authority = Koha::MetadataRecord::Authority->get_from_authid('alphabetsoup'); >-is($authority, undef, 'No invalid record is retrieved'); >+ my $import_record_id; >+ for my $row ($sth->fetchrow_hashref) { >+ $import_record_id = $row->{'import_record_id'}; >+ } > >-SKIP: >-{ >- my $dbh = C4::Context->dbh; >- my $sth = $dbh->prepare("SELECT import_record_id FROM import_records WHERE record_type = 'auth' LIMIT 1;"); >- $sth->execute(); >+ skip 'No authorities in reservoir', 3 unless $import_record_id; >+ my $authority = Koha::MetadataRecord::Authority->get_from_breeding($import_record_id); > >- my $import_record_id; >- for my $row ($sth->fetchrow_hashref) { >- $import_record_id = $row->{'import_record_id'}; >- } >+ is(ref($authority), 'Koha::MetadataRecord::Authority', 'Retrieved valid Koha::MetadataRecord::Authority object'); > >- skip 'No authorities in reservoir', 3 unless $import_record_id; >- $authority = Koha::MetadataRecord::Authority->get_from_breeding($import_record_id); >+ is($authority->authid, undef, 'Records in reservoir do not have an authid'); > >- is(ref($authority), 'Koha::MetadataRecord::Authority', 'Retrieved valid Koha::MetadataRecord::Authority object'); >+ is(ref($authority->record), 'MARC::Record', 'MARC record attached to authority'); > >- is($authority->authid, undef, 'Records in reservoir do not have an authid'); >- >- is(ref($authority->record), 'MARC::Record', 'MARC record attached to authority'); >- >- $authority = Koha::MetadataRecord::Authority->get_from_breeding('alphabetsoup'); >- is($authority, undef, 'No invalid record is retrieved from reservoir'); >-} >+ $authority = Koha::MetadataRecord::Authority->get_from_breeding('alphabetsoup'); >+ is($authority, undef, 'No invalid record is retrieved from reservoir'); >+ } >+ done_testing(); >+}; > >-done_testing(); >+$schema->storage->txn_rollback; >-- >2.30.2
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 30756
:
134998
|
134999
|
135000
|
135004
|
135005
|
135006
|
135104
|
135105
|
135106
|
135702