Bugzilla – Attachment 125620 Details for
Bug 27526
Remove Mod/AddItemFromMarc from additem.pl
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27526: Add tests for columns_to_str and host_items
Bug-27526-Add-tests-for-columnstostr-and-hostitems.patch (text/plain), 6.73 KB, created by
Tomás Cohen Arazi (tcohen)
on 2021-10-01 11:34:16 UTC
(
hide
)
Description:
Bug 27526: Add tests for columns_to_str and host_items
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2021-10-01 11:34:16 UTC
Size:
6.73 KB
patch
obsolete
>From d243477fe6ba83cd8ab112ac4dc0518d7470dd85 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Mon, 2 Aug 2021 14:47:09 +0200 >Subject: [PATCH] Bug 27526: Add tests for columns_to_str and host_items > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > Koha/Item.pm | 8 +-- > t/db_dependent/Koha/Biblio.t | 39 +++++++++++++- > t/db_dependent/Koha/Item.t | 100 ++++++++++++++++++++++++++++++++++- > 3 files changed, 139 insertions(+), 8 deletions(-) > >diff --git a/Koha/Item.pm b/Koha/Item.pm >index c258259804..3cce38faa2 100644 >--- a/Koha/Item.pm >+++ b/Koha/Item.pm >@@ -965,12 +965,8 @@ sub columns_to_str { > > next if $column eq 'more_subfields_xml'; > >- my $value; >- if ( Koha::Object::_datetime_column_type( $columns_info->{$column}->{data_type} ) ) { >- $value = output_pref({ dateformat => 'rfc3339', dt => dt_from_string($value, 'sql')}); >- } else { >- $value = $self->$column; >- } >+ my $value = $self->$column; >+ # Maybe we need to deal with datetime columns here, but so far we have damaged_on, itemlost_on and withdrawn_on, and they are not linked with kohafield > > if ( not defined $value or $value eq "" ) { > $values->{$column} = $value; >diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t >index 83de0634c6..cdb69615a1 100755 >--- a/t/db_dependent/Koha/Biblio.t >+++ b/t/db_dependent/Koha/Biblio.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 14; >+use Test::More tests => 15; > > use C4::Biblio qw( AddBiblio ModBiblio ); > use Koha::Database; >@@ -637,3 +637,40 @@ subtest 'get_marc_notes() UNIMARC tests' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'host_items' => sub { >+ plan tests => 6; >+ >+ my $biblio = $builder->build_sample_biblio( { frameworkcode => '' } ); >+ >+ t::lib::Mocks::mock_preference( 'EasyAnalyticalRecords', 1 ); >+ my $host_items = $biblio->host_items; >+ is( ref($host_items), 'Koha::Items' ); >+ is( $host_items->count, 0 ); >+ >+ my $item_1 = >+ $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); >+ my $host_item_1 = $builder->build_sample_item; >+ my $host_item_2 = $builder->build_sample_item; >+ >+ my $record = $biblio->metadata->record; >+ $record->append_fields( >+ MARC::Field->new( >+ '773', '', '', >+ 9 => $host_item_1->itemnumber, >+ 9 => $host_item_2->itemnumber >+ ), >+ ); >+ C4::Biblio::ModBiblio( $record, $biblio->biblionumber ); >+ $biblio = $biblio->get_from_storage; >+ $host_items = $biblio->host_items; >+ is( $host_items->count, 2 ); >+ is_deeply( [ $host_items->get_column('itemnumber') ], >+ [ $host_item_1->itemnumber, $host_item_2->itemnumber ] ); >+ >+ t::lib::Mocks::mock_preference( 'EasyAnalyticalRecords', 0 ); >+ $host_items = $biblio->host_items; >+ is( ref($host_items), 'Koha::Items' ); >+ is( $host_items->count, 0 ); >+ >+}; >diff --git a/t/db_dependent/Koha/Item.t b/t/db_dependent/Koha/Item.t >index d44c2ffcb8..e1274a414f 100755 >--- a/t/db_dependent/Koha/Item.t >+++ b/t/db_dependent/Koha/Item.t >@@ -18,13 +18,15 @@ > # along with Koha; if not, see <http://www.gnu.org/licenses>. > > use Modern::Perl; >+use utf8; > >-use Test::More tests => 12; >+use Test::More tests => 13; > use Test::Exception; > > use C4::Biblio qw( GetMarcSubfieldStructure ); > use C4::Circulation qw( AddIssue AddReturn ); > >+use Koha::Caches; > use Koha::Items; > use Koha::Database; > use Koha::DateUtils; >@@ -1050,3 +1052,99 @@ subtest 'move_to_biblio() tests' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'columns_to_str' => sub { >+ plan tests => 4; >+ >+ $schema->storage->txn_begin; >+ >+ my ( $itemtag, $itemsubfield ) = C4::Biblio::GetMarcFromKohaField( "items.itemnumber" ); >+ >+ my $cache = Koha::Caches->get_instance(); >+ $cache->clear_from_cache("MarcStructure-0-"); >+ $cache->clear_from_cache("MarcStructure-1-"); >+ $cache->clear_from_cache("default_value_for_mod_marc-"); >+ $cache->clear_from_cache("MarcSubfieldStructure-"); >+ >+ # Creating subfields 'é', 'è' that are not linked with a kohafield >+ Koha::MarcSubfieldStructures->search( >+ { >+ frameworkcode => '', >+ tagfield => $itemtag, >+ tagsubfield => ['é', 'è'], >+ } >+ )->delete; # In case it exist already >+ >+ # é is not linked with a AV >+ # è is linked with AV branches >+ Koha::MarcSubfieldStructure->new( >+ { >+ frameworkcode => '', >+ tagfield => $itemtag, >+ tagsubfield => 'é', >+ kohafield => undef, >+ repeatable => 1, >+ defaultvalue => 'ééé', >+ tab => 10, >+ } >+ )->store; >+ Koha::MarcSubfieldStructure->new( >+ { >+ frameworkcode => '', >+ tagfield => $itemtag, >+ tagsubfield => 'è', >+ kohafield => undef, >+ repeatable => 1, >+ defaultvalue => 'èèè', >+ tab => 10, >+ authorised_value => 'branches', >+ } >+ )->store; >+ >+ my $biblio = $builder->build_sample_biblio({ frameworkcode => '' }); >+ my $item = $builder->build_sample_item({ biblionumber => $biblio->biblionumber }); >+ my $itemlost = Koha::AuthorisedValues->search({ category => 'LOST' })->next->authorised_value; >+ my $dateaccessioned = '2020-12-15'; >+ my $library = Koha::Libraries->search->next; >+ my $branchcode = $library->branchcode; >+ >+ my $some_marc_xml = qq{<?xml version="1.0" encoding="UTF-8"?> >+<collection >+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >+ xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd" >+ xmlns="http://www.loc.gov/MARC21/slim"> >+ >+<record> >+ <leader> a </leader> >+ <datafield tag="999" ind1=" " ind2=" "> >+ <subfield code="é">value é</subfield> >+ <subfield code="è">$branchcode</subfield> >+ </datafield> >+</record> >+ >+</collection>}; >+ >+ $item->update( >+ { >+ itemlost => $itemlost, >+ dateaccessioned => $dateaccessioned, >+ more_subfields_xml => $some_marc_xml, >+ } >+ ); >+ >+ $item = $item->get_from_storage; >+ >+ my $s = $item->columns_to_str; >+ is( $s->{itemlost}, 'Lost' ); >+ is( $s->{dateaccessioned}, '2020-12-15'); >+ is( $s->{é}, 'value é'); >+ is( $s->{è}, $library->branchname ); >+ >+ $cache->clear_from_cache("MarcStructure-0-"); >+ $cache->clear_from_cache("MarcStructure-1-"); >+ $cache->clear_from_cache("default_value_for_mod_marc-"); >+ $cache->clear_from_cache("MarcSubfieldStructure-"); >+ >+ $schema->storage->txn_rollback; >+ >+}; >-- >2.32.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 27526
:
115679
|
115680
|
116006
|
117806
|
117807
|
117808
|
121589
|
121590
|
121591
|
122288
|
122318
|
122655
|
122656
|
122657
|
122658
|
122676
|
122677
|
122681
|
122682
|
122694
|
122695
|
122696
|
122946
|
122947
|
122948
|
122949
|
122950
|
122951
|
122952
|
122953
|
122954
|
122957
|
122958
|
122959
|
122974
|
123006
|
123007
|
123110
|
123329
|
123372
|
123415
|
123757
|
123758
|
123759
|
123760
|
123761
|
123762
|
123763
|
123764
|
123765
|
123766
|
123767
|
123768
|
123769
|
123770
|
123771
|
123772
|
125069
|
125605
|
125606
|
125607
|
125608
|
125609
|
125610
|
125611
|
125612
|
125613
|
125614
|
125615
|
125616
|
125617
|
125618
|
125619
| 125620 |
125818
|
125839
|
125863
|
126034
|
126051
|
126143
|
126144
|
126393
|
127025
|
127032