Lines 31-37
use t::lib::TestBuilder;
Link Here
|
31 |
use Mojo::JSON qw(encode_json); |
31 |
use Mojo::JSON qw(encode_json); |
32 |
|
32 |
|
33 |
use C4::Auth; |
33 |
use C4::Auth; |
34 |
use C4::Biblio qw( DelBiblio ); |
34 |
use C4::Biblio qw( DelBiblio ); |
35 |
use C4::Circulation qw( AddIssue AddReturn ); |
35 |
use C4::Circulation qw( AddIssue AddReturn ); |
36 |
|
36 |
|
37 |
use Koha::Biblios; |
37 |
use Koha::Biblios; |
Lines 65-115
subtest 'get() tests' => sub {
Link Here
|
65 |
$patron->discard_changes; |
65 |
$patron->discard_changes; |
66 |
my $userid = $patron->userid; |
66 |
my $userid = $patron->userid; |
67 |
|
67 |
|
68 |
my $biblio = $builder->build_sample_biblio({ |
68 |
my $biblio = $builder->build_sample_biblio( |
69 |
title => 'The unbearable lightness of being', |
69 |
{ |
70 |
author => 'Milan Kundera' |
70 |
title => 'The unbearable lightness of being', |
71 |
}); |
71 |
author => 'Milan Kundera' |
|
|
72 |
} |
73 |
); |
72 |
|
74 |
|
73 |
my $formatted = $biblio->metadata->record->as_formatted; |
75 |
my $formatted = $biblio->metadata->record->as_formatted; |
74 |
DelBiblio( $biblio->id ); |
76 |
DelBiblio( $biblio->id ); |
75 |
|
77 |
|
76 |
$t->get_ok("//$userid:$password@/api/v1/deleted/biblios/" . $biblio->biblionumber) |
78 |
$t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/" . $biblio->biblionumber )->status_is(403); |
77 |
->status_is(403); |
|
|
78 |
|
79 |
|
79 |
$patron->flags(4)->store; |
80 |
$patron->flags(4)->store; |
80 |
|
81 |
|
81 |
$t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/" . $biblio->biblionumber |
82 |
$t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/" |
82 |
=> { Accept => 'application/weird+format' } ) |
83 |
. $biblio->biblionumber => { Accept => 'application/weird+format' } )->status_is(400); |
83 |
->status_is(400); |
|
|
84 |
|
84 |
|
85 |
$t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/" . $biblio->biblionumber |
85 |
$t->get_ok( |
86 |
=> { Accept => 'application/json' } ) |
86 |
"//$userid:$password@/api/v1/deleted/biblios/" . $biblio->biblionumber => { Accept => 'application/json' } ) |
87 |
->status_is(200) |
87 |
->status_is(200)->json_is( '/title', 'The unbearable lightness of being' ) |
88 |
->json_is( '/title', 'The unbearable lightness of being' ) |
88 |
->json_is( '/author', 'Milan Kundera' ); |
89 |
->json_is( '/author', 'Milan Kundera' ); |
|
|
90 |
|
89 |
|
91 |
$t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/" . $biblio->biblionumber |
90 |
$t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/" |
92 |
=> { Accept => 'application/marcxml+xml' } ) |
91 |
. $biblio->biblionumber => { Accept => 'application/marcxml+xml' } )->status_is(200); |
93 |
->status_is(200); |
|
|
94 |
|
92 |
|
95 |
$t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/" . $biblio->biblionumber |
93 |
$t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/" |
96 |
=> { Accept => 'application/marc-in-json' } ) |
94 |
. $biblio->biblionumber => { Accept => 'application/marc-in-json' } )->status_is(200); |
97 |
->status_is(200); |
|
|
98 |
|
95 |
|
99 |
$t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/" . $biblio->biblionumber |
96 |
$t->get_ok( |
100 |
=> { Accept => 'application/marc' } ) |
97 |
"//$userid:$password@/api/v1/deleted/biblios/" . $biblio->biblionumber => { Accept => 'application/marc' } ) |
101 |
->status_is(200); |
98 |
->status_is(200); |
102 |
|
99 |
|
103 |
$t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/" . $biblio->biblionumber |
100 |
$t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/" . $biblio->biblionumber => { Accept => 'text/plain' } ) |
104 |
=> { Accept => 'text/plain' } ) |
101 |
->status_is(200)->content_is($formatted); |
105 |
->status_is(200) |
|
|
106 |
->content_is($formatted); |
107 |
|
102 |
|
108 |
my $biblio_exist = $builder->build_sample_biblio(); |
103 |
my $biblio_exist = $builder->build_sample_biblio(); |
109 |
$t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/" . $biblio_exist->biblionumber |
104 |
$t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/" |
110 |
=> { Accept => 'application/marc' } ) |
105 |
. $biblio_exist->biblionumber => { Accept => 'application/marc' } )->status_is(404) |
111 |
->status_is(404) |
106 |
->json_is( '/error', 'Object not found.' ); |
112 |
->json_is( '/error', 'Object not found.' ); |
|
|
113 |
|
107 |
|
114 |
subtest 'marc-in-json encoding tests' => sub { |
108 |
subtest 'marc-in-json encoding tests' => sub { |
115 |
|
109 |
|
Lines 126-136
subtest 'get() tests' => sub {
Link Here
|
126 |
|
120 |
|
127 |
DelBiblio( $biblio->id ); |
121 |
DelBiblio( $biblio->id ); |
128 |
|
122 |
|
129 |
my $result = $t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/" . $biblio->biblionumber |
123 |
my $result = $t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/" |
130 |
=> { Accept => 'application/marc-in-json' } ) |
124 |
. $biblio->biblionumber => { Accept => 'application/marc-in-json' } )->status_is(200)->tx->res->body; |
131 |
->status_is(200)->tx->res->body; |
|
|
132 |
|
125 |
|
133 |
my $encoded_title = Encode::encode( "UTF-8", $title_with_diacritics ); |
126 |
my $encoded_title = Encode::encode( "UTF-8", $title_with_diacritics ); |
134 |
|
127 |
|
135 |
like( $result, qr/\Q$encoded_title/, "The title is not double encoded" ); |
128 |
like( $result, qr/\Q$encoded_title/, "The title is not double encoded" ); |
136 |
}; |
129 |
}; |
Lines 139-146
subtest 'get() tests' => sub {
Link Here
|
139 |
plan tests => 3; |
132 |
plan tests => 3; |
140 |
|
133 |
|
141 |
my $marcflavour = C4::Context->preference('marcflavour'); |
134 |
my $marcflavour = C4::Context->preference('marcflavour'); |
142 |
t::lib::Mocks::mock_preference('marcflavour', 'UNIMARC'); |
135 |
t::lib::Mocks::mock_preference( 'marcflavour', 'UNIMARC' ); |
143 |
|
|
|
144 |
|
136 |
|
145 |
my $title_with_diacritics = "L'insoutenable légèreté de l'être"; |
137 |
my $title_with_diacritics = "L'insoutenable légèreté de l'être"; |
146 |
|
138 |
|
Lines 153-171
subtest 'get() tests' => sub {
Link Here
|
153 |
|
145 |
|
154 |
my $record = $biblio->metadata->record; |
146 |
my $record = $biblio->metadata->record; |
155 |
$record->leader(' nam 3 4500'); |
147 |
$record->leader(' nam 3 4500'); |
156 |
$biblio->metadata->metadata($record->as_xml_record('UNIMARC')); |
148 |
$biblio->metadata->metadata( $record->as_xml_record('UNIMARC') ); |
157 |
$biblio->metadata->store; |
149 |
$biblio->metadata->store; |
158 |
|
150 |
|
159 |
DelBiblio( $biblio->id ); |
151 |
DelBiblio( $biblio->id ); |
160 |
|
152 |
|
161 |
my $result = $t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/" . $biblio->biblionumber |
153 |
my $result = $t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/" |
162 |
=> { Accept => 'application/marcxml+xml' } ) |
154 |
. $biblio->biblionumber => { Accept => 'application/marcxml+xml' } )->status_is(200)->tx->res->body; |
163 |
->status_is(200)->tx->res->body; |
|
|
164 |
|
155 |
|
165 |
my $encoded_title = Encode::encode( "UTF-8", $title_with_diacritics ); |
156 |
my $encoded_title = Encode::encode( "UTF-8", $title_with_diacritics ); |
166 |
|
157 |
|
167 |
like( $result, qr/\Q$encoded_title/, "The title is not double encoded" ); |
158 |
like( $result, qr/\Q$encoded_title/, "The title is not double encoded" ); |
168 |
t::lib::Mocks::mock_preference('marcflavour', $marcflavour); |
159 |
t::lib::Mocks::mock_preference( 'marcflavour', $marcflavour ); |
169 |
}; |
160 |
}; |
170 |
|
161 |
|
171 |
$schema->storage->txn_rollback; |
162 |
$schema->storage->txn_rollback; |
Lines 188-197
subtest 'list() tests' => sub {
Link Here
|
188 |
$patron->discard_changes; |
179 |
$patron->discard_changes; |
189 |
my $userid = $patron->userid; |
180 |
my $userid = $patron->userid; |
190 |
|
181 |
|
191 |
t::lib::Mocks::mock_preference('marcflavour', 'UNIMARC'); |
182 |
t::lib::Mocks::mock_preference( 'marcflavour', 'UNIMARC' ); |
192 |
|
183 |
|
193 |
my $title_with_diacritics = "L'insoutenable légèreté de l'être"; |
184 |
my $title_with_diacritics = "L'insoutenable légèreté de l'être"; |
194 |
my $biblio = $builder->build_sample_biblio( |
185 |
my $biblio = $builder->build_sample_biblio( |
195 |
{ |
186 |
{ |
196 |
title => $title_with_diacritics, |
187 |
title => $title_with_diacritics, |
197 |
author => "Milan Kundera", |
188 |
author => "Milan Kundera", |
Lines 200-214
subtest 'list() tests' => sub {
Link Here
|
200 |
|
191 |
|
201 |
my $record = $biblio->metadata->record; |
192 |
my $record = $biblio->metadata->record; |
202 |
$record->leader(' nam 3 4500'); |
193 |
$record->leader(' nam 3 4500'); |
203 |
$biblio->metadata->metadata($record->as_xml_record('UNIMARC'))->store; |
194 |
$biblio->metadata->metadata( $record->as_xml_record('UNIMARC') )->store; |
204 |
|
195 |
|
205 |
my $biblio_id_1 = $biblio->id; |
196 |
my $biblio_id_1 = $biblio->id; |
206 |
|
197 |
|
207 |
t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); |
198 |
t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); |
208 |
my $biblio_id_2 = $builder->build_sample_biblio->id; |
199 |
my $biblio_id_2 = $builder->build_sample_biblio->id; |
209 |
|
200 |
|
210 |
DelBiblio( $biblio_id_1 ); |
201 |
DelBiblio($biblio_id_1); |
211 |
DelBiblio( $biblio_id_2 ); |
202 |
DelBiblio($biblio_id_2); |
212 |
|
203 |
|
213 |
my $query = encode_json( [ { biblio_id => $biblio_id_1 }, { biblio_id => $biblio_id_2 } ] ); |
204 |
my $query = encode_json( [ { biblio_id => $biblio_id_1 }, { biblio_id => $biblio_id_2 } ] ); |
214 |
|
205 |
|
Lines 219-227
subtest 'list() tests' => sub {
Link Here
|
219 |
$t->get_ok( "//$userid:$password@/api/v1/deleted/biblios?q=$query" => { Accept => 'application/weird+format' } ) |
210 |
$t->get_ok( "//$userid:$password@/api/v1/deleted/biblios?q=$query" => { Accept => 'application/weird+format' } ) |
220 |
->status_is(400); |
211 |
->status_is(400); |
221 |
|
212 |
|
222 |
$t->get_ok( "//$userid:$password@/api/v1/deleted/biblios?q=$query" => { Accept => 'application/json' } )->status_is(200); |
213 |
$t->get_ok( "//$userid:$password@/api/v1/deleted/biblios?q=$query" => { Accept => 'application/json' } ) |
|
|
214 |
->status_is(200); |
223 |
|
215 |
|
224 |
my $result = $t->get_ok( "//$userid:$password@/api/v1/deleted/biblios?q=$query" => { Accept => 'application/marcxml+xml' } ) |
216 |
my $result = |
|
|
217 |
$t->get_ok( "//$userid:$password@/api/v1/deleted/biblios?q=$query" => { Accept => 'application/marcxml+xml' } ) |
225 |
->status_is(200)->tx->res->body; |
218 |
->status_is(200)->tx->res->body; |
226 |
|
219 |
|
227 |
my $encoded_title = Encode::encode( "UTF-8", $title_with_diacritics ); |
220 |
my $encoded_title = Encode::encode( "UTF-8", $title_with_diacritics ); |
Lines 230-252
subtest 'list() tests' => sub {
Link Here
|
230 |
$t->get_ok( "//$userid:$password@/api/v1/deleted/biblios?q=$query" => { Accept => 'application/marc-in-json' } ) |
223 |
$t->get_ok( "//$userid:$password@/api/v1/deleted/biblios?q=$query" => { Accept => 'application/marc-in-json' } ) |
231 |
->status_is(200); |
224 |
->status_is(200); |
232 |
|
225 |
|
233 |
$t->get_ok( "//$userid:$password@/api/v1/deleted/biblios?q=$query" => { Accept => 'application/marc' } )->status_is(200); |
226 |
$t->get_ok( "//$userid:$password@/api/v1/deleted/biblios?q=$query" => { Accept => 'application/marc' } ) |
|
|
227 |
->status_is(200); |
234 |
|
228 |
|
235 |
$t->get_ok( "//$userid:$password@/api/v1/deleted/biblios?q=$query" => { Accept => 'text/plain' } )->status_is(200); |
229 |
$t->get_ok( "//$userid:$password@/api/v1/deleted/biblios?q=$query" => { Accept => 'text/plain' } )->status_is(200); |
236 |
|
230 |
|
237 |
# DELETE any biblio with ISBN = TOMAS |
231 |
# DELETE any biblio with ISBN = TOMAS |
238 |
Koha::Biblios->search({ 'biblioitem.isbn' => 'TOMAS' }, { join => [ 'biblioitem' ] }) |
232 |
Koha::Biblios->search( { 'biblioitem.isbn' => 'TOMAS' }, { join => ['biblioitem'] } )->delete; |
239 |
->delete; |
|
|
240 |
|
241 |
|
233 |
|
242 |
my $isbn_query = encode_json({ isbn => 'TOMAS' }); |
234 |
my $isbn_query = encode_json( { isbn => 'TOMAS' } ); |
243 |
my $tomas_biblio = $builder->build_sample_biblio({ |
235 |
my $tomas_biblio = $builder->build_sample_biblio( { isbn => 'TOMAS' } ); |
244 |
isbn => 'TOMAS' |
|
|
245 |
}); |
246 |
DelBiblio( $tomas_biblio->id ); |
236 |
DelBiblio( $tomas_biblio->id ); |
247 |
$t->get_ok( "//$userid:$password@/api/v1/biblios?q=$isbn_query" => |
237 |
$t->get_ok( "//$userid:$password@/api/v1/biblios?q=$isbn_query" => { Accept => 'text/plain' } )->status_is(200); |
248 |
{ Accept => 'text/plain' } ) |
|
|
249 |
->status_is(200); |
250 |
|
238 |
|
251 |
$schema->storage->txn_rollback; |
239 |
$schema->storage->txn_rollback; |
252 |
}; |
240 |
}; |
253 |
- |
|
|