Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
use Modern::Perl; |
4 |
use Test::More tests => 2; |
5 |
use t::lib::TestBuilder; |
6 |
use String::Random qw(random_string); |
7 |
use Koha::Database; |
8 |
use Koha::Subscription; |
9 |
use Koha::AdditionalField; |
10 |
use C4::Context; |
11 |
|
12 |
my $builder = t::lib::TestBuilder->new; |
13 |
my $schema = Koha::Database->schema; |
14 |
|
15 |
subtest 'set_additional_fields with marcfield_mode = "get"' => sub { |
16 |
plan tests => 1; |
17 |
|
18 |
$schema->txn_begin; |
19 |
|
20 |
my $biblio = $builder->build_sample_biblio(); |
21 |
my $record = $biblio->record; |
22 |
$record->append_fields( |
23 |
MARC::Field->new('999', '', '', 'Z' => 'some value'), |
24 |
); |
25 |
$biblio->metadata->metadata($record->as_xml_record(C4::Context->preference('marcflavour'))); |
26 |
$biblio->metadata->store()->discard_changes(); |
27 |
my $subscription = Koha::Subscription->new( |
28 |
{ |
29 |
biblionumber => $biblio->biblionumber, |
30 |
} |
31 |
); |
32 |
$subscription->store()->discard_changes(); |
33 |
|
34 |
my $field = Koha::AdditionalField->new( |
35 |
{ |
36 |
tablename => 'subscription', |
37 |
name => random_string('c' x 100), |
38 |
marcfield => '999$Z', |
39 |
marcfield_mode => 'get', |
40 |
} |
41 |
); |
42 |
$field->store()->discard_changes(); |
43 |
$subscription->set_additional_fields( |
44 |
[ |
45 |
{ id => $field->id }, |
46 |
] |
47 |
); |
48 |
|
49 |
my $values = $subscription->additional_field_values()->as_list(); |
50 |
|
51 |
is($values->[0]->value, 'some value', 'value was copied from the biblio record to the field'); |
52 |
|
53 |
$schema->txn_rollback; |
54 |
}; |
55 |
|
56 |
subtest 'set_additional_fields with marcfield_mode = "set"' => sub { |
57 |
plan tests => 1; |
58 |
|
59 |
$schema->txn_begin; |
60 |
|
61 |
my $biblio = $builder->build_sample_biblio(); |
62 |
my $subscription = Koha::Subscription->new( |
63 |
{ |
64 |
biblionumber => $biblio->biblionumber, |
65 |
} |
66 |
); |
67 |
$subscription->store()->discard_changes(); |
68 |
|
69 |
my $field = Koha::AdditionalField->new( |
70 |
{ |
71 |
tablename => 'subscription', |
72 |
name => random_string('c' x 100), |
73 |
marcfield => '999$Z', |
74 |
marcfield_mode => 'set', |
75 |
} |
76 |
); |
77 |
$field->store()->discard_changes(); |
78 |
$subscription->set_additional_fields( |
79 |
[ |
80 |
{ |
81 |
id => $field->id, |
82 |
value => 'some value', |
83 |
}, |
84 |
] |
85 |
); |
86 |
|
87 |
my $record = $biblio->record; |
88 |
is($record->subfield('999', 'Z'), 'some value', 'value was copied from the field to the biblio record'); |
89 |
|
90 |
$schema->txn_rollback; |
91 |
}; |