Lines 17-57
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use t::lib::TestBuilder; |
|
|
21 |
|
22 |
use Test::More tests => 3; |
20 |
use Test::More tests => 3; |
23 |
use Test::Mojo; |
21 |
use Test::Mojo; |
|
|
22 |
use Test::Warn; |
23 |
|
24 |
use t::lib::TestBuilder; |
25 |
use t::lib::Mocks; |
26 |
|
24 |
use Data::Dumper; |
27 |
use Data::Dumper; |
25 |
use C4::Auth; |
28 |
use C4::Auth; |
26 |
use C4::Context; |
29 |
use C4::Context; |
|
|
30 |
|
27 |
use Koha::Database; |
31 |
use Koha::Database; |
28 |
use MARC::File::XML ( BinaryEncoding => 'utf8', RecordFormat => 'UNIMARC' ); |
32 |
use MARC::File::XML ( BinaryEncoding => 'utf8', RecordFormat => 'MARC21' ); |
|
|
33 |
|
34 |
my $schema = Koha::Database->new->schema; |
35 |
my $builder = t::lib::TestBuilder->new; |
36 |
|
37 |
t::lib::Mocks::mock_preference( 'SessionStorage', 'tmp' ); |
38 |
|
39 |
my $remote_address = '127.0.0.1'; |
40 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
29 |
|
41 |
|
30 |
BEGIN { |
42 |
BEGIN { |
31 |
use_ok('Koha::Biblios'); |
43 |
use_ok('Koha::Biblios'); |
32 |
} |
44 |
} |
33 |
|
45 |
|
34 |
my $schema = Koha::Database->schema; |
|
|
35 |
my $dbh = C4::Context->dbh; |
46 |
my $dbh = C4::Context->dbh; |
36 |
my $builder = t::lib::TestBuilder->new; |
|
|
37 |
|
38 |
$ENV{REMOTE_ADDR} = '127.0.0.1'; |
39 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
40 |
|
41 |
$schema->storage->txn_begin; |
42 |
|
47 |
|
43 |
my $file = MARC::File::XML->in( 't/db_dependent/Record/testrecords/marcxml_utf8.xml' ); |
48 |
my $file = MARC::File::XML->in( 't/db_dependent/Record/testrecords/marcxml_utf8.xml' ); |
44 |
my $record = $file->next(); |
49 |
my $record = $file->next(); |
45 |
my ( $biblionumber, $itemnumber ); |
50 |
|
|
|
51 |
$schema->storage->txn_begin; |
46 |
|
52 |
|
47 |
my $librarian = $builder->build({ |
53 |
my $librarian = $builder->build({ |
48 |
source => "Borrower", |
54 |
source => "Borrower", |
49 |
value => { |
55 |
value => { |
50 |
categorycode => 'S', |
56 |
categorycode => 'S', |
51 |
branchcode => 'NPL', |
57 |
branchcode => 'NPL', |
52 |
flags => 1, # editcatalogue |
58 |
flags => 1, # editcatalogue |
53 |
}, |
59 |
}, |
54 |
}); |
60 |
}); |
55 |
|
61 |
|
56 |
my $session = C4::Auth::get_session(''); |
62 |
my $session = C4::Auth::get_session(''); |
57 |
$session->param('number', $librarian->{ borrowernumber }); |
63 |
$session->param('number', $librarian->{ borrowernumber }); |
Lines 60-90
$session->param('ip', '127.0.0.1');
Link Here
|
60 |
$session->param('lasttime', time()); |
66 |
$session->param('lasttime', time()); |
61 |
$session->flush; |
67 |
$session->flush; |
62 |
|
68 |
|
|
|
69 |
my ( $biblionumber, $itemnumber ); |
70 |
|
63 |
subtest 'Create biblio' => sub { |
71 |
subtest 'Create biblio' => sub { |
64 |
plan tests => 5; |
72 |
plan tests => 5; |
65 |
|
73 |
|
66 |
my $tx = $t->ua->build_tx(POST => '/api/v1/biblios' => $record->as_xml()); |
74 |
my $tx = $t->ua->build_tx(POST => '/api/v1/biblios' => $record->as_xml()); |
67 |
$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); |
75 |
$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); |
68 |
$tx->req->cookies({name => 'CGISESSID', value => $session->id}); |
76 |
$tx->req->cookies({name => 'CGISESSID', value => $session->id}); |
69 |
$t->request_ok($tx) |
77 |
$t->request_ok($tx) |
70 |
->status_is(201); |
78 |
->status_is(201); |
71 |
$biblionumber = $tx->res->json->{biblionumber}; |
79 |
$biblionumber = $tx->res->json->{biblionumber}; |
72 |
$itemnumber = $tx->res->json->{items}; |
80 |
$itemnumber = $tx->res->json->{items}; |
73 |
|
81 |
|
74 |
$t->json_is('/biblionumber' => $biblionumber) |
82 |
$t->json_is('/biblionumber' => $biblionumber) |
75 |
->json_is('/items' => $itemnumber) |
83 |
->json_is('/items' => $itemnumber) |
76 |
->header_like(Location => qr/$biblionumber/, 'Location header contains biblionumber'); |
84 |
->header_like(Location => qr/$biblionumber/, 'Location header contains biblionumber'); |
|
|
85 |
|
77 |
}; |
86 |
}; |
78 |
|
87 |
|
79 |
subtest 'Delete biblio' => sub { |
88 |
subtest 'Delete biblio' => sub { |
80 |
plan tests => 2; |
89 |
plan tests => 2; |
81 |
|
90 |
|
82 |
my $tx = $t->ua->build_tx(DELETE => "/api/v1/biblios/$biblionumber"); |
91 |
my $tx = $t->ua->build_tx(DELETE => "/api/v1/biblios/$biblionumber"); |
83 |
$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); |
92 |
$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); |
84 |
$tx->req->cookies({name => 'CGISESSID', value => $session->id}); |
93 |
$tx->req->cookies({name => 'CGISESSID', value => $session->id}); |
85 |
$t->request_ok($tx) |
94 |
$t->request_ok($tx) |
86 |
->status_is(200); |
95 |
->status_is(200); |
87 |
}; |
|
|
88 |
|
96 |
|
|
|
97 |
}; |
89 |
|
98 |
|
90 |
$schema->storage->txn_rollback; |
99 |
$schema->storage->txn_rollback; |