From 82dbecdee7895a3e2bcf50c5b0842c79e0e72a78 Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Wed, 31 Jul 2024 13:17:47 +0000 Subject: [PATCH] Bug 34355: Add unit tests Signed-off-by: Andrew Fuerste Henry --- t/db_dependent/Koha/MarcOrder.t | 84 +++++++++++++++++++++++++-------- 1 file changed, 65 insertions(+), 19 deletions(-) diff --git a/t/db_dependent/Koha/MarcOrder.t b/t/db_dependent/Koha/MarcOrder.t index 91b95b2486..b7fce9373d 100755 --- a/t/db_dependent/Koha/MarcOrder.t +++ b/t/db_dependent/Koha/MarcOrder.t @@ -17,9 +17,10 @@ use Modern::Perl; -use Test::More tests => 4; +use Test::More tests => 5; use Koha::MarcOrder; +use Koha::MarcOrderAccount; use Koha::Acquisition::Baskets; use Koha::Acquisition::Bookseller; use MARC::Record; @@ -29,6 +30,10 @@ use Koha::Database; use t::lib::Mocks; use t::lib::TestBuilder; +use File::Temp qw|tempfile|; +use MARC::Field; +use MARC::File::XML; + my $schema = Koha::Database->new->schema; my $builder = t::lib::TestBuilder->new; @@ -320,49 +325,36 @@ subtest 'add_items_from_import_record() - addorderiso2709.pl' => sub { my $client_item_fields = { 'notforloans' => [ '', - '' ], 'c_budget_id' => 2, 'replacementprices' => [ '0.00', - '0.00' ], 'uris' => [ '', - '' ], 'c_replacement_price' => '0.00', - 'public_notes' => [ - '', - '' - ], - 'itemcallnumbers' => [ + 'public_notes' => [''], + 'itemcallnumbers' => [ '', - '' ], 'budget_codes' => [ '', - '' ], 'nonpublic_notes' => [ '', - '' ], 'homebranches' => [ 'CPL', - 'CPL' ], 'copynos' => [ '', - '' ], 'holdingbranches' => [ 'CPL', - 'CPL' ], 'ccodes' => [ '', - '' ], 'locs' => [ '', @@ -370,7 +362,6 @@ subtest 'add_items_from_import_record() - addorderiso2709.pl' => sub { ], 'itemprices' => [ '10.00', - '10.00' ], 'c_discount' => '', 'c_price' => '0.00', @@ -379,7 +370,6 @@ subtest 'add_items_from_import_record() - addorderiso2709.pl' => sub { 'c_quantity' => '1', 'itypes' => [ 'BK', - 'BK' ], 'coded_location_qualifiers' => [], 'barcodes' => [], @@ -408,7 +398,7 @@ subtest 'add_items_from_import_record() - addorderiso2709.pl' => sub { "Listprice has been created successfully" ); is( - @{$orders}[0]->{quantity}, 2, + @{$orders}[0]->{quantity}, 1, "Quantity has been read correctly" ); is( @@ -430,3 +420,59 @@ subtest 'add_items_from_import_record() - addorderiso2709.pl' => sub { $schema->storage->txn_rollback; }; +subtest 'match_file_to_account' => sub { + plan tests => 2; + + $schema->storage->txn_begin; + + my ( $fh, $name ) = tempfile( SUFFIX => '.marcxml' ); + + my $rec = MARC::Record->new; + my $fld = MARC::Field->new( '975', '', '', 'p', '12345' ); + $rec->append_fields($fld); + my $str = $rec->as_xml; + + print $fh $str; + + close $fh; + + my $account1 = Koha::MarcOrderAccount->new( + { + match_field => '975$p', + match_value => '12345', + encoding => 'UTF-8', + description => 'test', + } + )->store; + + my $file_match = Koha::MarcOrder->match_file_to_account( + { + filename => $name, + filepath => $name, + profile => $account1, + } + ); + + is( $file_match, 1, 'File matched correctly to the account' ); + + my $account2 = Koha::MarcOrderAccount->new( + { + match_field => '975$p', + match_value => 'abcde', + encoding => 'UTF-8', + description => 'test', + } + )->store; + + my $file_match2 = Koha::MarcOrder->match_file_to_account( + { + filename => $name, + filepath => $name, + profile => $account2, + } + ); + + is( $file_match2, 0, 'File not matched to the account' ); + + $schema->storage->txn_rollback; +}; -- 2.39.2