Bug 28445: Add tests for subfields_to_prefill
I first wrote test for another thing but the code was actually correct. So submitting the tests. Note that the marc for more_subfields does not need to be passed, we can build it when needed. Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
parent
1fa2afe44b
commit
79e8701b1d
|
|
@ -16,6 +16,7 @@ package Koha::UI::Form::Builder::Item;
|
|||
# along with Koha; if not, see <http://www.gnu.org/licenses>.
|
||||
|
||||
use Modern::Perl;
|
||||
use MARC::Record;
|
||||
use C4::Context;
|
||||
use C4::Biblio qw( GetFrameworkCode GetMarcBiblio GetMarcStructure IsMarcStructureInternal );
|
||||
use C4::Koha qw( GetAuthorisedValues );
|
||||
|
|
@ -475,7 +476,13 @@ sub edit_form {
|
|||
$library->{selected} = 1 if $branchcode && $library->{branchcode} eq $branchcode;
|
||||
}
|
||||
|
||||
my $item = $self->{item};
|
||||
my $item = $self->{item};
|
||||
my $marc_more_subfields = $item->{more_subfields_xml}
|
||||
?
|
||||
# FIXME Use Maybe MARC::Record::new_from_xml if encoding issues on subfield (??)
|
||||
MARC::Record->new_from_xml( $item->{more_subfields_xml}, 'UTF-8' )
|
||||
: undef;
|
||||
|
||||
my $biblionumber = $self->{biblionumber};
|
||||
my $frameworkcode = $biblionumber ? GetFrameworkCode($biblionumber) : q{};
|
||||
my $marc_record = $biblionumber ? GetMarcBiblio( { biblionumber => $biblionumber } ) : undef;
|
||||
|
|
@ -527,9 +534,8 @@ sub edit_form {
|
|||
}
|
||||
else {
|
||||
# Not mapped, picked the values from more_subfields_xml's MARC
|
||||
my $marc_more = $item->{marc_more_subfields_xml};
|
||||
if ($marc_more) {
|
||||
for my $f ( $marc_more->fields($tag) ) {
|
||||
if ($marc_more_subfields) {
|
||||
for my $f ( $marc_more_subfields->fields($tag) ) {
|
||||
push @values, $f->subfield($subfieldtag);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
# along with Koha; if not, see <http://www.gnu.org/licenses>.
|
||||
|
||||
use Modern::Perl;
|
||||
use Test::More tests => 6;
|
||||
use Test::More tests => 7;
|
||||
use utf8;
|
||||
|
||||
use List::MoreUtils qw( uniq );
|
||||
|
|
@ -153,6 +153,25 @@ subtest 'prefill_with_default_values' => sub {
|
|||
|
||||
};
|
||||
|
||||
subtest 'subfields_to_prefill' => sub {
|
||||
plan tests => 2;
|
||||
|
||||
my $biblio = $builder->build_sample_biblio({ value => {frameworkcode => ''}});
|
||||
|
||||
my $more_subfields_xml = Koha::Item::Attributes->new({ "é" => "prefill é" })->to_marcxml;
|
||||
my $subfields =
|
||||
Koha::UI::Form::Builder::Item->new(
|
||||
{ biblionumber => $biblio->biblionumber, item => {more_subfields_xml => $more_subfields_xml}})->edit_form({subfields_to_prefill => ['é']});
|
||||
my ($subfield) = grep { $_->{subfield} eq 'é' } @$subfields;
|
||||
is( $subfield->{marc_value}->{value}, 'prefill é', 'Not mapped subfield prefilled if needed' );
|
||||
|
||||
$subfields =
|
||||
Koha::UI::Form::Builder::Item->new(
|
||||
{ biblionumber => $biblio->biblionumber, item => {itemnotes => 'prefill z'}})->edit_form({subfields_to_prefill => ['z']});
|
||||
($subfield) = grep { $_->{subfield} eq 'z' } @$subfields;
|
||||
is( $subfield->{marc_value}->{value}, 'prefill z', 'Mapped subfield prefilled if needed');
|
||||
};
|
||||
|
||||
subtest 'branchcode' => sub {
|
||||
plan tests => 2;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue