Bugzilla – Attachment 94280 Details for
Bug 23807
Add Koha::Item->as_marc_field
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23807: Unit tests
Bug-23807-Unit-tests.patch (text/plain), 3.39 KB, created by
Josef Moravec
on 2019-10-16 12:06:52 UTC
(
hide
)
Description:
Bug 23807: Unit tests
Filename:
MIME Type:
Creator:
Josef Moravec
Created:
2019-10-16 12:06:52 UTC
Size:
3.39 KB
patch
obsolete
>From 21211daeb824c334a0e898705e539320f7be1487 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 14 Oct 2019 08:32:58 -0300 >Subject: [PATCH] Bug 23807: Unit tests > >This patch introduces tests for the Koha::Item->as_marc_field method. It >tries to cover all the use cases. > >To test: >1. Apply this patchset >2. Run: > $ kshell > k$ prove t/db_dependent/Koha/Item.t >=> SUCCESS; Tests pass! >3. Sign off :-D > >Signed-off-by: Jan Kolator <kolatorj@email.cz> > >Signed-off-by: Josef Moravec <josef.moravec@gmail.com> >--- > t/db_dependent/Koha/Item.t | 68 +++++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 67 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/Koha/Item.t b/t/db_dependent/Koha/Item.t >index a4bb012756..b9ff871097 100644 >--- a/t/db_dependent/Koha/Item.t >+++ b/t/db_dependent/Koha/Item.t >@@ -19,7 +19,9 @@ > > use Modern::Perl; > >-use Test::More tests => 2; >+use Test::More tests => 3; >+ >+use C4::Biblio; > > use Koha::Items; > use Koha::Database; >@@ -81,4 +83,68 @@ subtest 'has_pending_hold() tests' => sub { > t::lib::Mocks::mock_preference( 'AllowItemsOnHoldCheckout', 0 ); > $dbh->do("DELETE FROM tmp_holdsqueue WHERE itemnumber=$itemnumber"); > ok( !$item->has_pending_hold, "We don't have a pending hold if nothing in the tmp_holdsqueue"); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest "as_marc_field() tests" => sub { >+ >+ my $mss = C4::Biblio::GetMarcSubfieldStructure( '', { unsafe => 1 } ); >+ >+ my @schema_columns = $schema->resultset('Item')->result_source->columns; >+ my @mapped_columns = grep { exists $mss->{'items.'.$_} } @schema_columns; >+ >+ plan tests => 2 * (scalar @mapped_columns + 1) + 1; >+ >+ $schema->storage->txn_begin; >+ >+ my $item = $builder->build_sample_item; >+ >+ # Tests with the mss parameter >+ my $marc_field = $item->as_marc_field({ mss => $mss }); >+ >+ is( >+ $marc_field->tag, >+ $mss->{'items.itemnumber'}[0]->{tagfield}, >+ 'Generated field set the right tag number' >+ ); >+ >+ foreach my $column ( @mapped_columns ) { >+ my $tagsubfield = $mss->{ 'items.' . $column }[0]->{tagsubfield}; >+ is( $marc_field->subfield($tagsubfield), >+ $item->$column, "Value is mapped correctly for column $column" ); >+ } >+ >+ # Tests without the mss parameter >+ $marc_field = $item->as_marc_field(); >+ >+ is( >+ $marc_field->tag, >+ $mss->{'items.itemnumber'}[0]->{tagfield}, >+ 'Generated field set the right tag number' >+ ); >+ >+ foreach my $column (@mapped_columns) { >+ my $tagsubfield = $mss->{ 'items.' . $column }[0]->{tagsubfield}; >+ is( $marc_field->subfield($tagsubfield), >+ $item->$column, "Value is mapped correctly for column $column" ); >+ } >+ >+ my $unmapped_subfield = Koha::MarcSubfieldStructure->new( >+ { >+ frameworkcode => '', >+ tagfield => $mss->{'items.itemnumber'}[0]->{tagfield}, >+ tagsubfield => 'X', >+ } >+ )->store; >+ >+ $mss = C4::Biblio::GetMarcSubfieldStructure( '', { unsafe => 0 } ); >+ my @unlinked_subfields; >+ push @unlinked_subfields, X => 'Something weird'; >+ $item->more_subfields_xml( C4::Items::_get_unlinked_subfields_xml( \@unlinked_subfields ) )->store; >+ >+ $marc_field = $item->as_marc_field; >+ is( scalar $marc_field->subfield('X'), 'Something weird', 'more_subfield_xml is considered' ); >+ >+ $schema->storage->txn_rollback; > }; >-- >2.11.0
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 23807
:
94029
|
94094
|
94274
|
94275
|
94279
| 94280