Bug 32986: (follow-up) Unit tests
[koha.git] / t / db_dependent / Koha / Template / Plugin / Notices.t
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 => 6;
20
21 use C4::Context;
22 use Koha::Database;
23 use Koha::ItemTypes;
24
25 use t::lib::TestBuilder;
26 use t::lib::Mocks;
27
28 BEGIN {
29     use_ok('Koha::Template::Plugin::Notices');
30 }
31
32 my $schema  = Koha::Database->schema;
33 my $builder = t::lib::TestBuilder->new;
34
35 $schema->storage->txn_begin;
36
37 my $plugin = Koha::Template::Plugin::Notices->new();
38 ok( $plugin, "initialized Notices plugin" );
39
40 my $notice_templates = Koha::Notice::Templates->search();
41
42 my $fetched_templates = $plugin->GetTemplates(undef);
43 is( scalar @$fetched_templates, $notice_templates->count, "All templates returned when no parameters passed" );
44
45 my $notice_A = $builder->build_object(
46     {
47         class => 'Koha::Notice::Templates',
48         value => {}
49     }
50 );
51
52 $fetched_templates = $plugin->GetTemplates( $notice_A->module );
53 is( scalar @$fetched_templates, 1, "GetTemplates with module passed gets the one notice in new module" );
54
55 is_deeply( @$fetched_templates[0]->unblessed, $notice_A->unblessed, 'The notice is correctly retrieved' );
56
57 $notice_A->delete;
58
59 $fetched_templates = $plugin->GetTemplates( $notice_A->module );
60 is( scalar @$fetched_templates, 0, "No notice returned when invalid module passed" );
61
62 $schema->storage->txn_rollback;
63
64 1;