Bugzilla – Attachment 88206 Details for
Bug 14957
Write protecting MARC fields based on source of import
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 14957: Add tests and pod for new options param to ModBiblio
Bug-14957-Add-tests-and-pod-for-new-options-param-.patch (text/plain), 6.38 KB, created by
David Gustafsson
on 2019-04-17 15:38:03 UTC
(
hide
)
Description:
Bug 14957: Add tests and pod for new options param to ModBiblio
Filename:
MIME Type:
Creator:
David Gustafsson
Created:
2019-04-17 15:38:03 UTC
Size:
6.38 KB
patch
obsolete
>From 94a30097e18772b02cade8c9f74ad32f778feb35 Mon Sep 17 00:00:00 2001 >From: David Gustafsson <david.gustafsson@ub.gu.se> >Date: Wed, 17 Apr 2019 17:34:53 +0200 >Subject: [PATCH] Bug 14957: Add tests and pod for new options param to > ModBiblio > >https://bugs.koha-community.org/show_bug.cgi?id=14956 >--- > C4/Biblio.pm | 8 +++- > Koha/MarcMergeRule.pm | 12 ++++++ > admin/marc-merge-rules.pl | 4 +- > t/db_dependent/Biblio/MarcMergeRules.t | 73 ++++++++++++++++++++++++++++++++-- > 4 files changed, 91 insertions(+), 6 deletions(-) > >diff --git a/C4/Biblio.pm b/C4/Biblio.pm >index b837ff718b..7d0f988697 100644 >--- a/C4/Biblio.pm >+++ b/C4/Biblio.pm >@@ -257,6 +257,12 @@ in the C<biblio> and C<biblioitems> tables, as well as > which fields are used to store embedded item, biblioitem, > and biblionumber data for indexing. > >+The C<$options> argument is a hashref with additional parameters >+that currently has one available option: C<context>. C<context> >+is forwared to L<ApplyMarcMergeRules> where it is used for selecting the >+current rule set if Marc Merge Rules is enabled. >+See L<ApplyMarcMergeRules> for more details. >+ > Returns 1 on success 0 on failure > > =cut >@@ -3279,7 +3285,7 @@ sub _koha_delete_biblio_metadata { > > =head2 ModBiblioMarc > >- &ModBiblioMarc($newrec, $biblionumber, $frameworkcode, $options); >+ ModBiblioMarc($newrec, $biblionumber, $frameworkcode); > > Add MARC XML data for a biblio to koha > >diff --git a/Koha/MarcMergeRule.pm b/Koha/MarcMergeRule.pm >index 989827f66a..d1bdbbac18 100644 >--- a/Koha/MarcMergeRule.pm >+++ b/Koha/MarcMergeRule.pm >@@ -39,6 +39,18 @@ sub store { > $self->SUPER::store(@_); > } > >+=head2 delete >+ >+Override C<delete> to clear marc merge rules cache. >+ >+=cut >+ >+sub delete { >+ my $self = shift @_; >+ $cache->clear_from_cache('marc_merge_rules'); >+ $self->SUPER::delete(@_); >+} >+ > sub _type { > return 'MarcMergeRule'; > } >diff --git a/admin/marc-merge-rules.pl b/admin/marc-merge-rules.pl >index f9cc61b3e5..123dd5f86c 100755 >--- a/admin/marc-merge-rules.pl >+++ b/admin/marc-merge-rules.pl >@@ -15,8 +15,7 @@ > # You should have received a copy of the GNU General Public License > # along with Koha; if not, see <http://www.gnu.org/licenses>. > >-use strict; >-use warnings; >+use Modern::Perl; > > # standard or CPAN modules used > use CGI qw ( -utf8 ); >@@ -144,6 +143,7 @@ elsif ($op eq 'doedit' || $op eq 'add') { > }; > if (!@{$errors}) { > my $rule = Koha::MarcMergeRules->find_or_create($rule_data); >+ # Need to call set and store here in case we have an update > $rule->set($rule_data); > $rule->store(); > } >diff --git a/t/db_dependent/Biblio/MarcMergeRules.t b/t/db_dependent/Biblio/MarcMergeRules.t >index c05e92d74c..106b9c1be5 100755 >--- a/t/db_dependent/Biblio/MarcMergeRules.t >+++ b/t/db_dependent/Biblio/MarcMergeRules.t >@@ -24,7 +24,7 @@ use C4::Context; > use C4::Biblio; > use Koha::Database; #?? > >-use Test::More tests => 22; >+use Test::More tests => 23; > use Test::MockModule; > > use Koha::MarcMergeRules; >@@ -86,7 +86,7 @@ subtest 'Record fields has been overwritten when no merge rules are defined' => > > my $rule = Koha::MarcMergeRules->find_or_create({ > tag => '*', >- module => $modules[0]->id, >+ module => $modules[0]->name, > filter => '*', > add => 0, > append => 0, >@@ -585,7 +585,7 @@ subtest 'Record fields has been overwritten when add = 1, append = 1, remove = 1 > # Protect field 500 with more specific tag value > my $skip_all_rule = Koha::MarcMergeRules->find_or_create({ > tag => '500', >- module => $modules[0]->id, >+ module => $modules[0]->name, > filter => '*', > add => 0, > append => 0, >@@ -712,6 +712,73 @@ subtest 'An exception is thrown when rule tag is set to invalid regexp' => sub { > ok($exception->isa('Koha::Exceptions::MarcMergeRule::InvalidTagRegExp'), "Exception is of correct class"); > }; > >+$skip_all_rule->delete(); >+ >+subtest 'context option in ModBiblio is handled correctly' => sub { >+ plan tests => 6; >+ $rule->set( >+ { >+ tag => '250', >+ module => $modules[0]->name, >+ filter => '*', >+ 'add' => 0, >+ 'append' => 0, >+ 'remove' => 0, >+ 'delete' => 0, >+ } >+ ); >+ $rule->store(); >+ my ($biblionumber) = AddBiblio($orig_record, ''); >+ >+ # Since marc merc rules are not run on save, only update >+ # saved record should be identical to orig_record >+ my $saved_record = GetMarcBiblio({ biblionumber => $biblionumber }); >+ >+ my @all_fields = $saved_record->fields(); >+ # Koha also adds 999c field, therefore 4 not 3 >+ cmp_ok(scalar @all_fields, '==', 4, 'Saved record has the expected number of fields'); >+ is_deeply( >+ [map { $_->subfield('a') } $saved_record->field('250') ], >+ ['250 bottles of beer on the wall', '256 bottles of beer on the wall'], >+ 'All "250" fields of saved record are identical to original record passed to AddBiblio' >+ ); >+ >+ is_deeply( >+ [map { $_->subfield('a') } $saved_record->field('500') ], >+ ['One bottle of beer in the fridge'], >+ 'All "500" fields of saved record are identical to original record passed to AddBiblio' >+ ); >+ >+ $saved_record->append_fields( >+ MARC::Field->new('250', '', '', 'a' => '251 bottles of beer on the wall'), # Appended >+ MARC::Field->new('500', '', '', 'a' => 'One cold bottle of beer in the fridge'), # Appended >+ ); >+ >+ ModBiblio($saved_record, $biblionumber, '', { context => { $modules[0]->name => 'test' } }); >+ >+ my $updated_record = GetMarcBiblio({ biblionumber => $biblionumber }); >+ >+ @all_fields = $updated_record->fields(); >+ cmp_ok(scalar @all_fields, '==', 5, 'Updated record has the expected number of fields'); >+ is_deeply( >+ [map { $_->subfield('a') } $updated_record->field('250') ], >+ ['250 bottles of beer on the wall', '256 bottles of beer on the wall'], >+ '"250" fields have retained their original values' >+ ); >+ >+ is_deeply( >+ [map { $_->subfield('a') } $updated_record->field('500') ], >+ ['One bottle of beer in the fridge', 'One cold bottle of beer in the fridge'], >+ '"500" field has been appended' >+ ); >+ >+ # To trigger removal from search index etc >+ DelBiblio($biblionumber); >+}; >+ >+# Explicityly delete rule to trigger clearing of cache >+$rule->delete(); >+ > $schema->storage->txn_rollback; > > 1; >-- >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 14957
:
44056
|
44057
|
44058
|
51723
|
51724
|
56637
|
56638
|
56643
|
56644
|
56645
|
56646
|
56647
|
56648
|
57114
|
57115
|
57116
|
57117
|
57118
|
57119
|
59811
|
59812
|
59885
|
60711
|
60824
|
60825
|
61065
|
61641
|
61736
|
64792
|
72498
|
74855
|
75118
|
76201
|
76202
|
76203
|
76204
|
76205
|
76206
|
76207
|
76208
|
76209
|
76210
|
78651
|
78652
|
78653
|
79367
|
79368
|
79369
|
79370
|
79890
|
80972
|
80973
|
80974
|
80975
|
81176
|
81177
|
81178
|
81179
|
81621
|
81699
|
81700
|
81705
|
81706
|
81707
|
81708
|
81969
|
81970
|
81971
|
82030
|
82031
|
82775
|
87709
|
87711
|
87771
|
87929
|
88205
|
88206
|
89961
|
90668
|
90669
|
90671
|
90672
|
90722
|
90723
|
90740
|
90741
|
92933
|
92934
|
92935
|
92936
|
92937
|
92938
|
92999
|
93499
|
94909
|
94911
|
99998
|
100052
|
100053
|
100054
|
100055
|
100056
|
100057
|
100058
|
100059
|
100060
|
100061
|
101510
|
109955
|
109956
|
109957
|
109958
|
109959
|
109960
|
109961
|
109962
|
109963
|
116622
|
116623
|
116624
|
116625
|
117844
|
117845
|
117849
|
117850
|
117853
|
117859
|
117964
|
117965
|
117966
|
118918
|
118919
|
118920
|
118921
|
118922
|
118923
|
118924
|
118925
|
118926
|
118927
|
118934
|
118935
|
118936
|
118937
|
118938
|
118939
|
118940
|
118941
|
118942
|
118943
|
118944
|
118945
|
118946
|
118957
|
120533
|
120534
|
120535
|
120536
|
120537
|
120538
|
120539
|
120540
|
120541
|
120542
|
120543
|
120544
|
120545
|
120546
|
120547
|
120548
|
120550
|
120553
|
120554
|
120555
|
120556
|
120557
|
120581
|
120582
|
120583
|
120584
|
120585
|
120586
|
120587
|
120588
|
120589
|
120590
|
120591
|
120592
|
120593
|
120594
|
120595
|
120596
|
120597
|
120598
|
120599
|
120600
|
120601
|
120602
|
120603
|
120604
|
120605
|
120670
|
120671
|
120705
|
125514
|
125515
|
125516
|
125517
|
125518
|
125519
|
125520
|
125521
|
125522
|
125523
|
125524
|
125525
|
125526
|
125527
|
125528
|
125529
|
125530
|
125531
|
125532
|
125533
|
125534
|
125535
|
125536
|
125537
|
125538
|
125539
|
125540
|
125632
|
125633
|
125636
|
126424
|
126425
|
126431
|
126592
|
126666
|
126667
|
126752
|
126753
|
126754
|
126755
|
126756
|
126757
|
126758
|
126759
|
126760
|
126761
|
126762
|
126763
|
126764
|
126765
|
126766
|
126767
|
126768
|
126769
|
126770
|
126771
|
126772
|
126773
|
126774
|
126775
|
126776
|
126777
|
126778
|
126779
|
126780
|
126781
|
126782
|
126783
|
126784
|
126785
|
126786
|
126950
|
126951