Bug 23916: (follow-up) Fix unit test
[koha.git] / t / db_dependent / Koha / Desks.t
1 #!/usr/bin/perl
2
3 # Copyright 2015 Koha Development team
4 # Copyright 2020 BULAC
5 #
6 # This file is part of Koha
7 #
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.
12 #
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.
17 #
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>.
20
21 use Modern::Perl;
22
23 use Test::More tests => 4;
24
25 use Koha::Desk;
26 use Koha::Desks;
27 use Koha::Database;
28 use Koha::Libraries;
29
30 use t::lib::TestBuilder;
31
32 my $schema = Koha::Database->new->schema;
33 $schema->storage->txn_begin;
34
35 # Add CPL if missing.
36 if (not defined Koha::Libraries->find('CPL')) {
37     Koha::Library->new({ branchcode => 'CPL', branchname => 'Centerville' })->store;
38 }
39
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;
50
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' );
53
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' );
56
57 $retrieved_desk_1->delete;
58 is( Koha::Desks->search->count, $nb_of_desks + 1, 'Delete should have deleted the desk' );
59
60 $schema->storage->txn_rollback;