Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/env perl |
|
|
2 |
|
3 |
# This file is part of Koha. |
4 |
# |
5 |
# Koha is free software; you can redistribute it and/or modify it under the |
6 |
# terms of the GNU General Public License as published by the Free Software |
7 |
# Foundation; either version 3 of the License, or (at your option) any later |
8 |
# version. |
9 |
# |
10 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
11 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
12 |
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
13 |
# |
14 |
# You should have received a copy of the GNU General Public License along |
15 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
16 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
17 |
|
18 |
use Modern::Perl; |
19 |
|
20 |
use Test::More tests => 1; |
21 |
use Test::Mojo; |
22 |
use Test::Warn; |
23 |
|
24 |
use t::lib::Mocks; |
25 |
use t::lib::TestBuilder; |
26 |
|
27 |
use C4::Auth; |
28 |
use Koha::Biblios; |
29 |
use Koha::Database; |
30 |
|
31 |
my $schema = Koha::Database->new->schema; |
32 |
my $builder = t::lib::TestBuilder->new; |
33 |
|
34 |
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); |
35 |
|
36 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
37 |
|
38 |
subtest 'delete() tests' => sub { |
39 |
|
40 |
plan tests => 7; |
41 |
|
42 |
$schema->storage->txn_begin; |
43 |
|
44 |
my $patron = $builder->build_object({ |
45 |
class => 'Koha::Patrons', |
46 |
value => { flags => 9 } |
47 |
}); |
48 |
my $password = 'thePassword123'; |
49 |
$patron->set_password({ password => $password, skip_validation => 1 }); |
50 |
my $userid = $patron->userid; |
51 |
|
52 |
my $biblio_id = $builder->build_object({ class => 'Koha::Biblios' })->id; |
53 |
my $item = $builder->build_object( { class => 'Koha::Items', value => { biblionumber => $biblio_id } } ); |
54 |
|
55 |
# Bibs with items cannot be deleted |
56 |
$t->delete_ok( "//$userid:$password@/api/v1/biblios/$biblio_id" ) |
57 |
->status_is(409); |
58 |
|
59 |
$item->delete(); |
60 |
|
61 |
# Bibs with no items can be deleted |
62 |
$t->delete_ok( "//$userid:$password@/api/v1/biblios/$biblio_id" ) |
63 |
->status_is(200) |
64 |
->content_is(q{""}); |
65 |
|
66 |
$t->delete_ok( "//$userid:$password@/api/v1/biblios/$biblio_id" ) |
67 |
->status_is(404); |
68 |
|
69 |
$schema->storage->txn_rollback; |
70 |
}; |
71 |
|