Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 2; |
22 |
use Test::More tests => 3; |
|
|
23 |
|
24 |
use C4::Biblio; |
23 |
|
25 |
|
24 |
use Koha::Items; |
26 |
use Koha::Items; |
25 |
use Koha::Database; |
27 |
use Koha::Database; |
Lines 81-84
subtest 'has_pending_hold() tests' => sub {
Link Here
|
81 |
t::lib::Mocks::mock_preference( 'AllowItemsOnHoldCheckout', 0 ); |
83 |
t::lib::Mocks::mock_preference( 'AllowItemsOnHoldCheckout', 0 ); |
82 |
$dbh->do("DELETE FROM tmp_holdsqueue WHERE itemnumber=$itemnumber"); |
84 |
$dbh->do("DELETE FROM tmp_holdsqueue WHERE itemnumber=$itemnumber"); |
83 |
ok( !$item->has_pending_hold, "We don't have a pending hold if nothing in the tmp_holdsqueue"); |
85 |
ok( !$item->has_pending_hold, "We don't have a pending hold if nothing in the tmp_holdsqueue"); |
|
|
86 |
|
87 |
$schema->storage->txn_rollback; |
88 |
}; |
89 |
|
90 |
subtest "as_marc_field() tests" => sub { |
91 |
|
92 |
my $mss = C4::Biblio::GetMarcSubfieldStructure( '', { unsafe => 1 } ); |
93 |
|
94 |
my @schema_columns = $schema->resultset('Item')->result_source->columns; |
95 |
my @mapped_columns = grep { exists $mss->{'items.'.$_} } @schema_columns; |
96 |
|
97 |
plan tests => 2 * (scalar @mapped_columns + 1) + 1; |
98 |
|
99 |
$schema->storage->txn_begin; |
100 |
|
101 |
my $item = $builder->build_sample_item; |
102 |
|
103 |
# Tests with the mss parameter |
104 |
my $marc_field = $item->as_marc_field({ mss => $mss }); |
105 |
|
106 |
is( |
107 |
$marc_field->tag, |
108 |
$mss->{'items.itemnumber'}[0]->{tagfield}, |
109 |
'Generated field set the right tag number' |
110 |
); |
111 |
|
112 |
foreach my $column ( @mapped_columns ) { |
113 |
my $tagsubfield = $mss->{ 'items.' . $column }[0]->{tagsubfield}; |
114 |
is( $marc_field->subfield($tagsubfield), |
115 |
$item->$column, "Value is mapped correctly for column $column" ); |
116 |
} |
117 |
|
118 |
# Tests without the mss parameter |
119 |
$marc_field = $item->as_marc_field(); |
120 |
|
121 |
is( |
122 |
$marc_field->tag, |
123 |
$mss->{'items.itemnumber'}[0]->{tagfield}, |
124 |
'Generated field set the right tag number' |
125 |
); |
126 |
|
127 |
foreach my $column (@mapped_columns) { |
128 |
my $tagsubfield = $mss->{ 'items.' . $column }[0]->{tagsubfield}; |
129 |
is( $marc_field->subfield($tagsubfield), |
130 |
$item->$column, "Value is mapped correctly for column $column" ); |
131 |
} |
132 |
|
133 |
my $unmapped_subfield = Koha::MarcSubfieldStructure->new( |
134 |
{ |
135 |
frameworkcode => '', |
136 |
tagfield => $mss->{'items.itemnumber'}[0]->{tagfield}, |
137 |
tagsubfield => 'X', |
138 |
} |
139 |
)->store; |
140 |
|
141 |
$mss = C4::Biblio::GetMarcSubfieldStructure( '', { unsafe => 0 } ); |
142 |
my @unlinked_subfields; |
143 |
push @unlinked_subfields, X => 'Something weird'; |
144 |
$item->more_subfields_xml( C4::Items::_get_unlinked_subfields_xml( \@unlinked_subfields ) )->store; |
145 |
|
146 |
$marc_field = $item->as_marc_field; |
147 |
is( scalar $marc_field->subfield('X'), 'Something weird', 'more_subfield_xml is considered' ); |
148 |
|
149 |
$schema->storage->txn_rollback; |
84 |
}; |
150 |
}; |
85 |
- |
|
|