Bug 19382: (QA follow-up) Throw exception if only_this_guarantor is set for a non...
[koha.git] / t / db_dependent / Koha / Desks.t
blob89814456ff24862350e7a1feb4b96cc0facef763
1 #!/usr/bin/perl
3 # Copyright 2015 Koha Development team
4 # Copyright 2020 BULAC
6 # This file is part of Koha
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21 use Modern::Perl;
23 use Test::More tests => 4;
25 use Koha::Desk;
26 use Koha::Desks;
27 use Koha::Database;
28 use Koha::Libraries;
30 use t::lib::TestBuilder;
32 my $schema = Koha::Database->new->schema;
33 $schema->storage->txn_begin;
35 # Add CPL if missing.
36 if (not defined Koha::Libraries->find('CPL')) {
37 Koha::Library->new({ branchcode => 'CPL', branchname => 'Centerville' })->store;
40 my $builder = t::lib::TestBuilder->new;
41 my $nb_of_desks = Koha::Desks->search->count;
42 my $new_desk_1 = Koha::Desk->new({
43 desk_name => 'my_desk_name_for_test_1',
44 branchcode => 'CPL',
45 })->store;
46 my $new_desk_2 = Koha::Desk->new({
47 desk_name => 'my_desk_name_for_test_2',
48 branchcode => 'CPL',
49 })->store;
51 like( $new_desk_1->desk_id, qr|^\d+$|, 'Adding a new desk should have set the desk_id');
52 is( Koha::Desks->search->count, $nb_of_desks + 2, 'The 2 desks should have been added' );
54 my $retrieved_desk_1 = Koha::Desks->find( $new_desk_1->desk_id );
55 is( $retrieved_desk_1->desk_name, $new_desk_1->desk_name, 'Find a desk by id should return the correct desk' );
57 $retrieved_desk_1->delete;
58 is( Koha::Desks->search->count, $nb_of_desks + 1, 'Delete should have deleted the desk' );
60 $schema->storage->txn_rollback;