Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
# Copyright 2015 Koha Development team |
4 |
# |
5 |
# This file is part of Koha |
6 |
# |
7 |
# Koha is free software; you can redistribute it and/or modify it |
8 |
# under the terms of the GNU General Public License as published by |
9 |
# the Free Software Foundation; either version 3 of the License, or |
10 |
# (at your option) any later version. |
11 |
# |
12 |
# Koha is distributed in the hope that it will be useful, but |
13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
# GNU General Public License for more details. |
16 |
# |
17 |
# You should have received a copy of the GNU General Public License |
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
19 |
|
20 |
use Modern::Perl; |
21 |
|
22 |
use Test::More tests => 9; |
23 |
|
24 |
use Koha::Library; |
25 |
use Koha::Libraries; |
26 |
use Koha::LibraryCategory; |
27 |
use Koha::LibraryCategories; |
28 |
use Koha::Database; |
29 |
|
30 |
use t::lib::TestBuilder; |
31 |
|
32 |
my $schema = Koha::Database->new->schema; |
33 |
$schema->storage->txn_begin; |
34 |
|
35 |
my $builder = t::lib::TestBuilder->new; |
36 |
my $nb_of_libraries = Koha::Libraries->search->count; |
37 |
my $nb_of_categories = Koha::LibraryCategories->search->count; |
38 |
my $new_library_1 = Koha::Library->new({ |
39 |
branchcode => 'my_bc_1', |
40 |
branchname => 'my_branchname_1', |
41 |
branchnotes => 'my_branchnotes_1', |
42 |
})->store; |
43 |
my $new_library_2 = Koha::Library->new({ |
44 |
branchcode => 'my_bc_2', |
45 |
branchname => 'my_branchname_2', |
46 |
branchnotes => 'my_branchnotes_2', |
47 |
})->store; |
48 |
my $new_category_1 = Koha::LibraryCategory->new({ |
49 |
categorycode => 'my_cc_1', |
50 |
categoryname => 'my_categoryname_1', |
51 |
codedescription => 'my_codedescription_1', |
52 |
categorytype => 'properties', |
53 |
} )->store; |
54 |
my $new_category_2 = Koha::LibraryCategory->new( { |
55 |
categorycode => 'my_cc_2', |
56 |
categoryname => 'my_categoryname_2', |
57 |
codedescription => 'my_codedescription_2', |
58 |
categorytype => 'searchdomain', |
59 |
} )->store; |
60 |
my $new_category_3 = Koha::LibraryCategory->new( { |
61 |
categorycode => 'my_cc_3', |
62 |
categoryname => 'my_categoryname_3', |
63 |
codedescription => 'my_codedescription_3', |
64 |
categorytype => 'searchdomain', |
65 |
} )->store; |
66 |
|
67 |
is( Koha::Libraries->search->count, $nb_of_libraries + 2, 'The 2 libraries should have been added' ); |
68 |
is( Koha::LibraryCategories->search->count, $nb_of_categories + 3, 'The 3 library categories should have been added' ); |
69 |
|
70 |
$new_library_1->add_to_categories( [$new_category_1] ); |
71 |
$new_library_2->add_to_categories( [$new_category_2] ); |
72 |
my $retrieved_library_1 = Koha::Libraries->find( $new_library_1->branchcode ); |
73 |
is( $retrieved_library_1->branchname, $new_library_1->branchname, 'Find a library by branchcode should return the correct library' ); |
74 |
is( Koha::Libraries->find( $new_library_1->branchcode )->get_categories->count, 1, '1 library should have been linked to the category 1' ); |
75 |
|
76 |
$retrieved_library_1->update_categories( [ $new_category_2, $new_category_3 ] ); |
77 |
is( Koha::Libraries->find( $new_library_1->branchcode )->get_categories->count, 2, '2 libraries should have been linked to the category 2' ); |
78 |
|
79 |
my $retrieved_category_2 = Koha::LibraryCategories->find( $new_category_2->categorycode ); |
80 |
is( $retrieved_category_2->branchcodes->count, 2, '2 libraries should have been linked to the category_2' ); |
81 |
is( $retrieved_category_2->categorycode, uc('my_cc_2'), 'The Koha::LibraryCategory constructor should have upercased the categorycode' ); |
82 |
|
83 |
$retrieved_library_1->delete; |
84 |
is( Koha::Libraries->search->count, $nb_of_libraries + 1, 'Delete should have deleted the library' ); |
85 |
|
86 |
$retrieved_category_2->delete; |
87 |
is( Koha::LibraryCategories->search->count, $nb_of_categories + 2, 'Delete should have deleted the library category' ); |
88 |
|
89 |
$schema->storage->txn_rollback; |
90 |
1; |