Bugzilla – Attachment 105216 Details for
Bug 20817
Add ability to retain 9xx fields when adding on order item to existing record
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 20817: Add unit tests
Bug-20817-Add-unit-tests.patch (text/plain), 6.90 KB, created by
Kyle M Hall
on 2020-05-21 15:12:37 UTC
(
hide
)
Description:
Bug 20817: Add unit tests
Filename:
MIME Type:
Creator:
Kyle M Hall
Created:
2020-05-21 15:12:37 UTC
Size:
6.90 KB
patch
obsolete
>From df8691dee947a34db7e933ae73ada69cb0e0c5d7 Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Thu, 21 May 2020 10:27:39 -0400 >Subject: [PATCH] Bug 20817: Add unit tests > >--- > t/Acquisition/Utils.t | 161 ++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 161 insertions(+) > create mode 100755 t/Acquisition/Utils.t > >diff --git a/t/Acquisition/Utils.t b/t/Acquisition/Utils.t >new file mode 100755 >index 0000000000..79e4e93935 >--- /dev/null >+++ b/t/Acquisition/Utils.t >@@ -0,0 +1,161 @@ >+#!/usr/bin/perl >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+use utf8; >+ >+use Test::More tests => 4; >+use Test::MockModule; >+ >+use t::lib::Mocks; >+use t::lib::TestBuilder; >+ >+use MARC::Record; >+ >+use_ok('Koha::Acquisition::Utils'); >+ >+my $schema = Koha::Database->schema; >+$schema->storage->txn_begin; >+my $builder = t::lib::TestBuilder->new; >+my $dbh = C4::Context->dbh; >+ >+subtest "get_infos_syspref" => sub { >+ plan tests => 4; >+ >+ my $record = MARC::Record->new; >+ $record->append_fields( >+ MARC::Field->new( '500', '', '', a => 'Test 1' ), >+ MARC::Field->new( '505', '', '', a => 'Test 2', u => 'http://example.com' ), >+ MARC::Field->new( '520', '', '', a => 'Test 3' ), >+ MARC::Field->new( '541', '', '', a => 'Test 4' ), >+ ); >+ >+ my $MarcFieldsToOrder = q{ >+test1: 500$a >+test2: 505$a >+test3: 520$a >+test4: 541$a >+ }; >+ t::lib::Mocks::mock_preference('MarcFieldsToOrder', $MarcFieldsToOrder); >+ my $data = Koha::Acquisition::Utils::get_infos_syspref( >+ 'MarcFieldsToOrder', >+ $record, >+ [ 'test1', 'test2', 'test3', 'test4' ] >+ ); >+ >+ is( $data->{test1}, "Test 1", "Got test 1 correctly" ); >+ is( $data->{test2}, "Test 2", "Got test 2 correctly" ); >+ is( $data->{test3}, "Test 3", "Got test 3 correctly" ); >+ is( $data->{test4}, "Test 4", "Got test 4 correctly" ); >+}; >+ >+subtest "get_infos_syspref_on_item" => sub { >+ plan tests => 13; >+ >+ my $record = MARC::Record->new; >+ $record->append_fields( >+ MARC::Field->new( '500', '', '', a => 'Test 1' ), >+ MARC::Field->new( '505', '', '', a => 'Test 2', u => 'http://example.com' ), >+ MARC::Field->new( '975', '', '', a => 'Test 3', b => "Test 4" ), >+ MARC::Field->new( '975', '', '', a => 'Test 5', b => "Test 6" ), >+ MARC::Field->new( '975', '', '', a => 'Test 7', b => "Test 8" ), >+ MARC::Field->new( '976', '', '', a => 'Test 9', b => "Test 10" ), >+ MARC::Field->new( '976', '', '', a => 'Test 11', b => "Test 12" ), >+ MARC::Field->new( '976', '', '', a => 'Test 13', b => "Test 14" ), >+ ); >+ >+ my $MarcItemFieldsToOrder = q{ >+testA: 975$a >+testB: 975$b >+testC: 976$a >+testD: 976$b >+ }; >+ t::lib::Mocks::mock_preference('MarcItemFieldsToOrder', $MarcItemFieldsToOrder); >+ my $data = Koha::Acquisition::Utils::get_infos_syspref_on_item( >+ 'MarcItemFieldsToOrder', >+ $record, >+ [ 'testA', 'testB', 'testC', 'testD' ] >+ ); >+ >+ is( $data->[0]->{testA}, "Test 3", 'Got first 975$a correctly' ); >+ is( $data->[0]->{testB}, "Test 4", 'Got first 975$b correctly' ); >+ is( $data->[1]->{testA}, "Test 5", 'Got second 975$a correctly' ); >+ is( $data->[1]->{testB}, "Test 6", 'Got second 975$b correctly' ); >+ is( $data->[2]->{testA}, "Test 7", 'Got third 975$a correctly' ); >+ is( $data->[2]->{testB}, "Test 8", 'Got third 975$b correctly' ); >+ >+ is( $data->[0]->{testC}, "Test 9", 'Got first 976$a correctly' ); >+ is( $data->[0]->{testD}, "Test 10", 'Got first 976$b correctly' ); >+ is( $data->[1]->{testC}, "Test 11", 'Got second 976$a correctly' ); >+ is( $data->[1]->{testD}, "Test 12", 'Got second 976$b correctly' ); >+ is( $data->[2]->{testC}, "Test 13", 'Got third 976$a correctly' ); >+ is( $data->[2]->{testD}, "Test 14", 'Got third 976$b correctly' ); >+ >+ # Test with bad record where fields are not one-to-one >+ $record->append_fields( >+ MARC::Field->new( '500', '', '', a => 'Test 1' ), >+ MARC::Field->new( '505', '', '', a => 'Test 2', u => 'http://example.com' ), >+ MARC::Field->new( '975', '', '', a => 'Test 3', b => "Test 4" ), >+ MARC::Field->new( '975', '', '', b => "Test 6" ), >+ MARC::Field->new( '975', '', '', b => 'Test 7' ), >+ MARC::Field->new( '976', '', '', a => 'Test 9', b => "Test 10" ), >+ MARC::Field->new( '976', '', '', a => 'Test 11', b => "Test 12" ), >+ ); >+ >+ $data = Koha::Acquisition::Utils::get_infos_syspref_on_item( >+ 'MarcItemFieldsToOrder', >+ $record, >+ [ 'testA', 'testB', 'testC', 'testD' ] >+ ); >+ is( $data, -1, "Got -1 if record fields are not one-to-one"); >+}; >+ >+subtest "equal_number_of_fields" => sub { >+ plan tests => 2; >+ >+ my $record = MARC::Record->new; >+ $record->append_fields( >+ MARC::Field->new( '500', '', '', a => 'Test 1' ), >+ MARC::Field->new( '505', '', '', a => 'Test 2', u => 'http://example.com' ), >+ MARC::Field->new( '975', '', '', a => 'Test a', b => "Test b" ), >+ MARC::Field->new( '975', '', '', a => 'Test a', b => "Test b" ), >+ MARC::Field->new( '975', '', '', a => 'Test a', b => "Test b" ), >+ MARC::Field->new( '976', '', '', a => 'Test a', b => "Test b" ), >+ MARC::Field->new( '976', '', '', a => 'Test a', b => "Test b" ), >+ MARC::Field->new( '976', '', '', a => 'Test a', b => "Test b" ), >+ ); >+ >+ my $data = Koha::Acquisition::Utils::equal_number_of_fields( [ '975', '976' ], $record ); >+ is( $data, '3', "Got correct number of fields in return value" ); >+ >+ # Test with non-matching field sets >+ $record->append_fields( >+ MARC::Field->new( '500', '', '', a => 'Test 1' ), >+ MARC::Field->new( '505', '', '', a => 'Test 2', u => 'http://example.com' ), >+ MARC::Field->new( '975', '', '', a => 'Test a', b => "Test b" ), >+ MARC::Field->new( '975', '', '', a => 'Test a', b => "Test b" ), >+ MARC::Field->new( '975', '', '', a => 'Test a', b => "Test b" ), >+ MARC::Field->new( '976', '', '', a => 'Test a', b => "Test b" ), >+ MARC::Field->new( '976', '', '', a => 'Test a', b => "Test b" ), >+ ); >+ >+ $data = Koha::Acquisition::Utils::equal_number_of_fields( [ '975', '976' ], $record ); >+ is( $data, '-1', "Got -1 in return value" ); >+}; >+ >+$schema->storage->txn_rollback; >+C4::Context->clear_syspref_cache(); >-- >2.24.1 (Apple Git-126)
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 20817
:
79867
|
80537
|
86711
|
86746
|
105214
|
105215
|
105216
|
105217
|
105218
|
105219
|
115343
|
118371
|
118372
|
118373
|
118374
|
118375
|
118376
|
118377
|
118378
|
122692
|
122834
|
122841
|
122858
|
122861
|
128766
|
128767
|
128768
|
128769
|
128770
|
128771
|
128772
|
128773
|
128774
|
128775
|
128776
|
128777
|
128782
|
128783
|
128785
|
128786
|
128787
|
128788
|
128789
|
128790
|
128791
|
128792
|
128793
|
128794
|
128795
|
128796
|
128797
|
128798
|
131732
|
131733
|
131734
|
131735
|
131736
|
131737
|
131738
|
131739
|
131740
|
131741
|
131742
|
131743
|
131744
|
131745
|
131746
|
131747
|
131748
|
131749
|
142630
|
142631
|
142632
|
142633
|
142634
|
142635
|
142636
|
142637
|
142638
|
142639
|
142640
|
142641
|
142642
|
142643
|
142644
|
142645
|
142646
|
142647
|
142648
|
142649
|
142650
|
142651
|
142829