Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/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, see <http://www.gnu.org/licenses>. |
16 |
|
17 |
use Modern::Perl; |
18 |
|
19 |
use Test::More tests => 2; |
20 |
|
21 |
use t::lib::Mocks; |
22 |
|
23 |
BEGIN { |
24 |
use_ok('Koha::Template::Plugin::ClassSources'); |
25 |
} |
26 |
|
27 |
my $schema = Koha::Database->schema; |
28 |
|
29 |
subtest 'all' => sub { |
30 |
plan tests => 4; |
31 |
|
32 |
$schema->storage->txn_begin; |
33 |
$schema->resultset('ClassSource')->delete(); |
34 |
$schema->resultset('ClassSource')->create({ |
35 |
cn_source => 'anscr', |
36 |
description => 'ANSCR (Sound Recordings)', |
37 |
used => 0, |
38 |
class_sort_rule => 'generic', |
39 |
class_split_rule => 'generic', |
40 |
}); |
41 |
$schema->resultset('ClassSource')->create({ |
42 |
cn_source => 'ddc', |
43 |
description => 'Dewey Decimal Classification', |
44 |
used => 1, |
45 |
class_sort_rule => 'dewey', |
46 |
class_split_rule => 'dewey', |
47 |
}); |
48 |
$schema->resultset('ClassSource')->create({ |
49 |
cn_source => 'z', |
50 |
description => 'Other/Generic Classification Scheme', |
51 |
used => 0, |
52 |
class_sort_rule => 'generic', |
53 |
class_split_rule => 'generic', |
54 |
}); |
55 |
|
56 |
t::lib::Mocks::mock_preference('DefaultClassificationSource', ''); |
57 |
|
58 |
my $plugin = Koha::Template::Plugin::ClassSources->new(); |
59 |
subtest 'when given no parameters' => sub { |
60 |
plan tests => 2; |
61 |
my @class_sources = $plugin->all(); |
62 |
|
63 |
is(scalar @class_sources, 1, 'it returns only "used" class sources'); |
64 |
is($class_sources[0]->used, 1, 'it returns only "used" class sources'); |
65 |
}; |
66 |
|
67 |
subtest 'when given parameter "selected"' => sub { |
68 |
plan tests => 1; |
69 |
my @class_sources = $plugin->all({ selected => 'anscr' }); |
70 |
|
71 |
ok(scalar @class_sources == 2, 'it returns "used" class sources and the selected one'); |
72 |
}; |
73 |
|
74 |
subtest 'when DefaultClassificationSource is set to a not used class source' => sub { |
75 |
plan tests => 1; |
76 |
t::lib::Mocks::mock_preference('DefaultClassificationSource', 'anscr'); |
77 |
my @class_sources = $plugin->all(); |
78 |
|
79 |
ok(scalar @class_sources == 2, 'it returns "used" class sources and the default one'); |
80 |
}; |
81 |
|
82 |
subtest 'when DefaultClassificationSource is set and "selected" parameter is given' => sub { |
83 |
plan tests => 1; |
84 |
t::lib::Mocks::mock_preference('DefaultClassificationSource', 'anscr'); |
85 |
my @class_sources = $plugin->all({ selected => 'z' }); |
86 |
ok(scalar @class_sources == 3, 'it returns "used" class sources, the default one and the selected one'); |
87 |
}; |
88 |
|
89 |
$schema->storage->txn_rollback; |
90 |
}; |