Lines 27-47
use Koha::MarcModificationTemplates;
Link Here
|
27 |
use C4::Biblio qw(AddBiblio ModBiblioMarc DelBiblio); |
27 |
use C4::Biblio qw(AddBiblio ModBiblioMarc DelBiblio); |
28 |
use Koha::Biblios; |
28 |
use Koha::Biblios; |
29 |
|
29 |
|
30 |
eval{ |
30 |
eval { use C4::Context; }; |
31 |
use C4::Context; |
|
|
32 |
}; |
33 |
if ($@) { |
31 |
if ($@) { |
34 |
plan skip_all => "Tests skip. You must have a working Context\n"; |
32 |
plan skip_all => "Tests skip. You must have a working Context\n"; |
35 |
} |
33 |
} |
36 |
|
34 |
|
37 |
my $koha_conf = $ENV{KOHA_CONF}; |
35 |
my $koha_conf = $ENV{KOHA_CONF}; |
38 |
my $koha_conf_xml = XMLin($koha_conf); |
36 |
my $koha_conf_xml = XMLin($koha_conf); |
39 |
|
37 |
|
40 |
my $user = $ENV{KOHA_USER} || $koha_conf_xml->{config}->{user}; |
38 |
my $user = $ENV{KOHA_USER} || $koha_conf_xml->{config}->{user}; |
41 |
my $password = $ENV{KOHA_PASS} || $koha_conf_xml->{config}->{pass}; |
39 |
my $password = $ENV{KOHA_PASS} || $koha_conf_xml->{config}->{pass}; |
42 |
my $intranet = $ENV{KOHA_INTRANET_URL}; |
40 |
my $intranet = $ENV{KOHA_INTRANET_URL}; |
43 |
|
41 |
|
44 |
if (not defined $intranet) { |
42 |
if ( not defined $intranet ) { |
45 |
plan skip_all => "Tests skipped. You must set environment variable KOHA_INTRANET_URL to run tests\n"; |
43 |
plan skip_all => "Tests skipped. You must set environment variable KOHA_INTRANET_URL to run tests\n"; |
46 |
} |
44 |
} |
47 |
|
45 |
|
Lines 50-65
subtest 'Templates applied using simple and advanced MARC Editor' => sub {
Link Here
|
50 |
|
48 |
|
51 |
# Create "Test" MARC modification template |
49 |
# Create "Test" MARC modification template |
52 |
#my $template_id = AddModificationTemplate('TEST'); |
50 |
#my $template_id = AddModificationTemplate('TEST'); |
53 |
my $template = Koha::MarcModificationTemplate->new({ name => 'TEST' })->store; |
51 |
my $template = Koha::MarcModificationTemplate->new( { name => 'TEST' } )->store; |
54 |
|
52 |
|
55 |
ok($template, 'MARC modification template successfully created'); |
53 |
ok( $template, 'MARC modification template successfully created' ); |
56 |
my $add_template_action_result = AddModificationTemplateAction( |
54 |
my $add_template_action_result = AddModificationTemplateAction( |
57 |
$template->id, |
55 |
$template->id, |
58 |
'update_field', # Action |
56 |
'update_field', # Action |
59 |
0, |
57 |
0, |
60 |
250, # Field |
58 |
250, # Field |
61 |
'a', # Subfield |
59 |
'a', # Subfield |
62 |
'251 bottles of beer on the wall', # Value |
60 |
'251 bottles of beer on the wall', # Value |
63 |
'', |
61 |
'', |
64 |
'', |
62 |
'', |
65 |
'', |
63 |
'', |
Lines 73-128
subtest 'Templates applied using simple and advanced MARC Editor' => sub {
Link Here
|
73 |
0, |
71 |
0, |
74 |
'' |
72 |
'' |
75 |
); |
73 |
); |
76 |
ok($add_template_action_result, 'MARC modification template action successfully created'); |
74 |
ok( $add_template_action_result, 'MARC modification template action successfully created' ); |
77 |
my $record = MARC::Record->new(); |
75 |
my $record = MARC::Record->new(); |
78 |
$record->leader(' nam a22 7a 4500'); |
76 |
$record->leader(' nam a22 7a 4500'); |
79 |
$record->append_fields( |
77 |
$record->append_fields( |
80 |
MARC::Field->new('001', '12345'), |
78 |
MARC::Field->new( '001', '12345' ), |
81 |
MARC::Field->new('003', 'TEST'), |
79 |
MARC::Field->new( '003', 'TEST' ), |
82 |
MARC::Field->new('245', '1', '0', 'a' => 'TEST'), |
80 |
MARC::Field->new( '245', '1', '0', 'a' => 'TEST' ), |
83 |
MARC::Field->new('250', '','', 'a' => '250 bottles of beer on the wall'), |
81 |
MARC::Field->new( '250', '', '', 'a' => '250 bottles of beer on the wall' ), |
|
|
82 |
|
84 |
# @FIXME: Create test item type? Not super safe to rely on existing 'BK' type |
83 |
# @FIXME: Create test item type? Not super safe to rely on existing 'BK' type |
85 |
MARC::Field->new('942', '','', 'c' => 'BK'), |
84 |
MARC::Field->new( '942', '', '', 'c' => 'BK' ), |
86 |
); |
85 |
); |
87 |
my ($biblionumber) = AddBiblio($record, ''); |
86 |
my ($biblionumber) = AddBiblio( $record, '' ); |
88 |
|
87 |
|
89 |
my $saved_record = Koha::Biblios->find($biblionumber)->metadata->record(); |
88 |
my $saved_record = Koha::Biblios->find($biblionumber)->metadata->record(); |
90 |
my $saved_record_250_field = $saved_record->field('250'); |
89 |
my $saved_record_250_field = $saved_record->field('250'); |
91 |
isa_ok($saved_record_250_field, 'MARC::Field', 'Field with tag 250 has been saved'); |
90 |
isa_ok( $saved_record_250_field, 'MARC::Field', 'Field with tag 250 has been saved' ); |
92 |
is($saved_record_250_field->subfield('a'), '250 bottles of beer on the wall', 'Field 250a has the same value passed to AddBiblio'); |
91 |
is( |
|
|
92 |
$saved_record_250_field->subfield('a'), '250 bottles of beer on the wall', |
93 |
'Field 250a has the same value passed to AddBiblio' |
94 |
); |
93 |
|
95 |
|
94 |
my $old_template_preference = C4::Context->preference('SaveBiblioMarcModificationTemplate'); |
96 |
my $old_template_preference = C4::Context->preference('SaveBiblioMarcModificationTemplate'); |
95 |
C4::Context->set_preference('SaveBiblioMarcModificationTemplate', $template->id); |
97 |
C4::Context->set_preference( 'SaveBiblioMarcModificationTemplate', $template->id ); |
96 |
|
98 |
|
97 |
my $agent = Test::WWW::Mechanize->new(autocheck => 1); |
99 |
my $agent = Test::WWW::Mechanize->new( autocheck => 1 ); |
98 |
|
100 |
|
99 |
$agent->get_ok("$intranet/cgi-bin/koha/mainpage.pl", 'Connect to intranet'); |
101 |
$agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'Connect to intranet' ); |
100 |
$agent->form_name('loginform'); |
102 |
$agent->form_name('loginform'); |
101 |
$agent->field('password', $password); |
103 |
$agent->field( 'password', $password ); |
102 |
$agent->field('userid', $user); |
104 |
$agent->field( 'userid', $user ); |
103 |
$agent->field('branch', ''); |
105 |
$agent->field( 'branch', '' ); |
104 |
$agent->click_ok('', 'Login to staff interface'); |
106 |
$agent->click_ok( '', 'Login to staff interface' ); |
105 |
$agent->content_lacks('Invalid username or password', 'Logged in to staff interface'); |
107 |
$agent->content_lacks( 'Invalid username or password', 'Logged in to staff interface' ); |
106 |
|
108 |
|
107 |
$agent->get_ok("$intranet/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=$biblionumber", 'Load bibliographic record in simple MARC editor'); |
109 |
$agent->get_ok( |
|
|
110 |
"$intranet/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=$biblionumber", |
111 |
'Load bibliographic record in simple MARC editor' |
112 |
); |
108 |
$agent->submit_form_ok( |
113 |
$agent->submit_form_ok( |
109 |
{ |
114 |
{ |
110 |
form_id => 'f', |
115 |
form_id => 'f', |
111 |
button => '', |
116 |
button => '', |
112 |
}, |
117 |
}, |
113 |
'Save bibliographic record using simple MARC editor' |
118 |
'Save bibliographic record using simple MARC editor' |
114 |
); |
119 |
); |
115 |
|
120 |
|
116 |
$saved_record = Koha::Biblios->find($biblionumber)->metadata->record(); |
121 |
$saved_record = Koha::Biblios->find($biblionumber)->metadata->record(); |
117 |
$saved_record_250_field = $saved_record->field('250'); |
122 |
$saved_record_250_field = $saved_record->field('250'); |
118 |
is($saved_record_250_field->subfield('a'), '251 bottles of beer on the wall', 'Field with tag 250 has been modified by MARC modification template'); |
123 |
is( |
|
|
124 |
$saved_record_250_field->subfield('a'), '251 bottles of beer on the wall', |
125 |
'Field with tag 250 has been modified by MARC modification template' |
126 |
); |
119 |
|
127 |
|
120 |
# FIXME: Don't really need to to this, but could be useful so |
128 |
# FIXME: Don't really need to to this, but could be useful so |
121 |
# test below does not succed by accident |
129 |
# test below does not succeed by accident |
122 |
$saved_record->delete_fields($saved_record_250_field); |
130 |
$saved_record->delete_fields($saved_record_250_field); |
123 |
$saved_record->insert_fields_ordered(MARC::Field->new('250', '','', 'a' => '250 bottles of beer on the wall')); |
131 |
$saved_record->insert_fields_ordered( MARC::Field->new( '250', '', '', 'a' => '250 bottles of beer on the wall' ) ); |
124 |
$biblionumber = ModBiblioMarc($saved_record, $biblionumber); |
132 |
$biblionumber = ModBiblioMarc( $saved_record, $biblionumber ); |
125 |
ok($biblionumber, 'Field with tag 250 has been restored to original value'); |
133 |
ok( $biblionumber, 'Field with tag 250 has been restored to original value' ); |
126 |
|
134 |
|
127 |
# @FIXME: Leader record status n or c? |
135 |
# @FIXME: Leader record status n or c? |
128 |
my $record_xml = <<'EOF'; |
136 |
my $record_xml = <<'EOF'; |
Lines 145-158
EOF
Link Here
|
145 |
my $headers = HTTP::Headers->new( |
153 |
my $headers = HTTP::Headers->new( |
146 |
Content_Type => 'text/xml', |
154 |
Content_Type => 'text/xml', |
147 |
); |
155 |
); |
148 |
my $request = HTTP::Request->new('POST', "$intranet/cgi-bin/koha/svc/bib/$biblionumber", $headers, $record_xml); |
156 |
my $request = HTTP::Request->new( 'POST', "$intranet/cgi-bin/koha/svc/bib/$biblionumber", $headers, $record_xml ); |
149 |
my $response = $agent->request($request); |
157 |
my $response = $agent->request($request); |
150 |
|
158 |
|
151 |
is($response->code, '200', 'Emulate save in advanced MARC editor, Koha REST API responded with 200 for update biblio request'); |
159 |
is( |
152 |
like($response->decoded_content, qr/251 bottles of beer on the wall/, 'Field with tag 250 has been modified by MARC modification template'); |
160 |
$response->code, '200', |
|
|
161 |
'Emulate save in advanced MARC editor, Koha REST API responded with 200 for update biblio request' |
162 |
); |
163 |
like( |
164 |
$response->decoded_content, qr/251 bottles of beer on the wall/, |
165 |
'Field with tag 250 has been modified by MARC modification template' |
166 |
); |
153 |
|
167 |
|
154 |
# Clean up |
168 |
# Clean up |
155 |
DelBiblio($biblionumber); |
169 |
DelBiblio($biblionumber); |
156 |
$template->delete; |
170 |
$template->delete; |
157 |
C4::Context->set_preference('SaveBiblioMarcModificationTemplate', $old_template_preference); |
171 |
C4::Context->set_preference( 'SaveBiblioMarcModificationTemplate', $old_template_preference ); |
158 |
}; |
172 |
}; |
159 |
- |
|
|