Lines 19-25
use Modern::Perl;
Link Here
|
19 |
|
19 |
|
20 |
use POSIX qw(strftime); |
20 |
use POSIX qw(strftime); |
21 |
|
21 |
|
22 |
use Test::More tests => 67; |
22 |
use Test::More tests => 68; |
23 |
use t::lib::Mocks; |
23 |
use t::lib::Mocks; |
24 |
use Koha::Database; |
24 |
use Koha::Database; |
25 |
|
25 |
|
Lines 164-195
my $budgetid = C4::Budgets::AddBudget(
Link Here
|
164 |
); |
164 |
); |
165 |
my $budget = C4::Budgets::GetBudget($budgetid); |
165 |
my $budget = C4::Budgets::GetBudget($budgetid); |
166 |
|
166 |
|
167 |
# Prepare a sample MARC record with a ISBN to test GetHistory() |
|
|
168 |
my $marcxml = qq{<?xml version="1.0" encoding="UTF-8"?> |
169 |
<record |
170 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
171 |
xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd" |
172 |
xmlns="http://www.loc.gov/MARC21/slim"> |
173 |
|
174 |
<leader>03108cam a2200277 i 4500</leader> |
175 |
<controlfield tag="001">a2526595</controlfield> |
176 |
<controlfield tag="003">Koha</controlfield> |
177 |
<controlfield tag="005">20170306104815.0</controlfield> |
178 |
<controlfield tag="006">m o d </controlfield> |
179 |
<controlfield tag="007">cr |||||||||||</controlfield> |
180 |
<controlfield tag="008">150723s2016 vau b 000 0 eng d</controlfield> |
181 |
<datafield tag="020" ind1=" " ind2=" "> |
182 |
<subfield code="a">9780136019701</subfield> |
183 |
</datafield> |
184 |
</record> |
185 |
}; |
186 |
|
187 |
my @ordernumbers; |
167 |
my @ordernumbers; |
188 |
my ( $biblionumber1, $biblioitemnumber1 ) = AddBiblio( MARC::Record->new, '' ); |
168 |
my ( $biblionumber1, $biblioitemnumber1 ) = AddBiblio( MARC::Record->new, '' ); |
189 |
my ( $biblionumber2, $biblioitemnumber2 ) = AddBiblio( MARC::Record->new, '' ); |
169 |
my ( $biblionumber2, $biblioitemnumber2 ) = AddBiblio( MARC::Record->new, '' ); |
190 |
my ( $biblionumber3, $biblioitemnumber3 ) = AddBiblio( MARC::Record->new, '' ); |
170 |
my ( $biblionumber3, $biblioitemnumber3 ) = AddBiblio( MARC::Record->new, '' ); |
191 |
my ( $biblionumber4, $biblioitemnumber4 ) = AddBiblio( MARC::Record->new, '' ); |
171 |
my ( $biblionumber4, $biblioitemnumber4 ) = AddBiblio( MARC::Record->new, '' ); |
192 |
my ( $biblionumber5, $biblioitemnumber5 ) = AddBiblio( MARC::Record->new_from_xml( $marcxml, 'utf8', 'MARC21' ), '' ); |
172 |
my ( $biblionumber5, $biblioitemnumber5 ) = AddBiblio( MARC::Record->new, '' ); |
|
|
173 |
|
174 |
|
193 |
|
175 |
|
194 |
# Prepare 5 orders, and make distinction beween fields to be tested with eq and with == |
176 |
# Prepare 5 orders, and make distinction beween fields to be tested with eq and with == |
195 |
# Ex : a price of 50.1 will be stored internally as 5.100000 |
177 |
# Ex : a price of 50.1 will be stored internally as 5.100000 |
Lines 458-470
is( scalar( @$orders ), 2, 'GetHistory with a given ordernumber and search_child
Link Here
|
458 |
|
440 |
|
459 |
# Test GetHistory() with and without SearchWithISBNVariations |
441 |
# Test GetHistory() with and without SearchWithISBNVariations |
460 |
# The ISBN passed as a param is the ISBN-10 version of the 13-digit ISBN in the sample record declared in $marcxml |
442 |
# The ISBN passed as a param is the ISBN-10 version of the 13-digit ISBN in the sample record declared in $marcxml |
461 |
t::lib::Mocks::mock_preference('SearchWithISBNVariations', 0); |
|
|
462 |
$orders = GetHistory( isbn => '0136019706' ); |
463 |
is( scalar(@$orders), 0, "GetHistory searches correctly by ISBN" ); |
464 |
|
465 |
t::lib::Mocks::mock_preference('SearchWithISBNVariations', 1); |
466 |
$orders = GetHistory( isbn => '0136019706' ); |
467 |
is( scalar(@$orders), 1, "GetHistory searches correctly by ISBN" ); |
468 |
|
443 |
|
469 |
my $budgetid2 = C4::Budgets::AddBudget( |
444 |
my $budgetid2 = C4::Budgets::AddBudget( |
470 |
{ |
445 |
{ |
Lines 574-577
ok($active_count >= 1 , "GetBudgetsReport(1) OK");
Link Here
|
574 |
is($all_count, scalar GetBudgetsReport(), "GetBudgetReport returns inactive budget period acquisitions."); |
549 |
is($all_count, scalar GetBudgetsReport(), "GetBudgetReport returns inactive budget period acquisitions."); |
575 |
ok($active_count >= scalar GetBudgetsReport(1), "GetBudgetReport doesn't return inactive budget period acquisitions."); |
550 |
ok($active_count >= scalar GetBudgetsReport(1), "GetBudgetReport doesn't return inactive budget period acquisitions."); |
576 |
|
551 |
|
|
|
552 |
# "Flavoured" tests (tests that required a run for each marc flavour) |
553 |
# Tests should be added to the run_flavoured_tests sub below |
554 |
my $biblio_module = new Test::MockModule('C4::Biblio'); |
555 |
$biblio_module->mock( |
556 |
'GetMarcSubfieldStructure', |
557 |
sub { |
558 |
my ($self) = shift; |
559 |
|
560 |
my ( $title_field, $title_subfield ) = get_title_field(); |
561 |
my ( $isbn_field, $isbn_subfield ) = get_isbn_field(); |
562 |
my ( $issn_field, $issn_subfield ) = get_issn_field(); |
563 |
my ( $biblionumber_field, $biblionumber_subfield ) = ( '999', 'c' ); |
564 |
my ( $biblioitemnumber_field, $biblioitemnumber_subfield ) = ( '999', '9' ); |
565 |
my ( $itemnumber_field, $itemnumber_subfield ) = get_itemnumber_field(); |
566 |
|
567 |
return { |
568 |
'biblio.title' => [ { tagfield => $title_field, tagsubfield => $title_subfield } ], |
569 |
'biblio.biblionumber' => [ { tagfield => $biblionumber_field, tagsubfield => $biblionumber_subfield } ], |
570 |
'biblioitems.isbn' => [ { tagfield => $isbn_field, tagsubfield => $isbn_subfield } ], |
571 |
'biblioitems.issn' => [ { tagfield => $issn_field, tagsubfield => $issn_subfield } ], |
572 |
'biblioitems.biblioitemnumber' => [ { tagfield => $biblioitemnumber_field, tagsubfield => $biblioitemnumber_subfield } ], |
573 |
'items.itemnumber' => [ { tagfield => $itemnumber_subfield, tagsubfield => $itemnumber_subfield } ], |
574 |
}; |
575 |
} |
576 |
); |
577 |
|
578 |
sub run_flavoured_tests { |
579 |
my $marcflavour = shift; |
580 |
t::lib::Mocks::mock_preference('marcflavour', $marcflavour); |
581 |
|
582 |
# |
583 |
# Test SearchWithISBNVariations syspref |
584 |
# |
585 |
my $marc_record = MARC::Record->new; |
586 |
$marc_record->append_fields( create_isbn_field( '9780136019701', $marcflavour ) ); |
587 |
my ( $biblionumber6, $biblioitemnumber6 ) = AddBiblio( $marc_record, '' ); |
588 |
|
589 |
# Create order |
590 |
my $ordernumber = Koha::Acquisition::Order->new( { |
591 |
basketno => $basketno, |
592 |
biblionumber => $biblionumber6, |
593 |
budget_id => $budget->{budget_id}, |
594 |
order_internalnote => "internal note", |
595 |
order_vendornote => "vendor note", |
596 |
quantity => 1, |
597 |
ecost => 10, |
598 |
rrp => 10, |
599 |
listprice => 10, |
600 |
ecost => 10, |
601 |
rrp => 10, |
602 |
discount => 0, |
603 |
uncertainprice => 0, |
604 |
} )->store->ordernumber; |
605 |
|
606 |
t::lib::Mocks::mock_preference('SearchWithISBNVariations', 0); |
607 |
$orders = GetHistory( isbn => '0136019706' ); |
608 |
is( scalar(@$orders), 0, "GetHistory searches correctly by ISBN" ); |
609 |
|
610 |
t::lib::Mocks::mock_preference('SearchWithISBNVariations', 1); |
611 |
$orders = GetHistory( isbn => '0136019706' ); |
612 |
is( scalar(@$orders), 1, "GetHistory searches correctly by ISBN" ); |
613 |
|
614 |
my $order = GetOrder($ordernumber); |
615 |
DelOrder($order->{biblionumber}, $order->{ordernumber}, 1); |
616 |
} |
617 |
|
618 |
# Do "flavoured" tests |
619 |
subtest 'MARC21' => sub { |
620 |
plan tests => 2; |
621 |
run_flavoured_tests('MARC21'); |
622 |
}; |
623 |
|
624 |
subtest 'UNIMARC' => sub { |
625 |
plan tests => 2; |
626 |
run_flavoured_tests('UNIMARC'); |
627 |
}; |
628 |
|
629 |
subtest 'NORMARC' => sub { |
630 |
plan tests => 2; |
631 |
run_flavoured_tests('NORMARC'); |
632 |
}; |
633 |
|
634 |
### Functions required for "flavoured" tests |
635 |
sub get_title_field { |
636 |
my $marc_flavour = C4::Context->preference('marcflavour'); |
637 |
return ( $marc_flavour eq 'UNIMARC' ) ? ( '200', 'a' ) : ( '245', 'a' ); |
638 |
} |
639 |
|
640 |
sub get_isbn_field { |
641 |
my $marc_flavour = C4::Context->preference('marcflavour'); |
642 |
return ( $marc_flavour eq 'UNIMARC' ) ? ( '010', 'a' ) : ( '020', 'a' ); |
643 |
} |
644 |
|
645 |
sub get_issn_field { |
646 |
my $marc_flavour = C4::Context->preference('marcflavour'); |
647 |
return ( $marc_flavour eq 'UNIMARC' ) ? ( '011', 'a' ) : ( '022', 'a' ); |
648 |
} |
649 |
|
650 |
sub get_itemnumber_field { |
651 |
my $marc_flavour = C4::Context->preference('marcflavour'); |
652 |
return ( $marc_flavour eq 'UNIMARC' ) ? ( '995', '9' ) : ( '952', '9' ); |
653 |
} |
654 |
|
655 |
sub create_isbn_field { |
656 |
my ( $isbn, $marcflavour ) = @_; |
657 |
|
658 |
my ( $isbn_field, $isbn_subfield ) = get_isbn_field(); |
659 |
my $field = MARC::Field->new( $isbn_field, '', '', $isbn_subfield => $isbn ); |
660 |
|
661 |
# Add the price subfield |
662 |
my $price_subfield = ( $marcflavour eq 'UNIMARC' ) ? 'd' : 'c'; |
663 |
$field->add_subfields( $price_subfield => '$100' ); |
664 |
|
665 |
return $field; |
666 |
} |
667 |
|
577 |
$schema->storage->txn_rollback(); |
668 |
$schema->storage->txn_rollback(); |
578 |
- |
|
|