Bug 17958: Add tests for Koha::Notice::Template[s]
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 23 Jan 2017 11:35:13 +0000 (12:35 +0100)
committerKyle M Hall <kyle@bywatersolutions.com>
Fri, 17 Feb 2017 11:44:34 +0000 (11:44 +0000)
Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
t/db_dependent/Koha/Notices.t [new file with mode: 0644]

diff --git a/t/db_dependent/Koha/Notices.t b/t/db_dependent/Koha/Notices.t
new file mode 100644 (file)
index 0000000..3f90f9f
--- /dev/null
@@ -0,0 +1,71 @@
+#!/usr/bin/perl
+
+# Copyright 2017 Koha Development team
+#
+# This file is part of Koha
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
+
+use Modern::Perl;
+
+use Test::More tests => 3;
+
+use Koha::Notice::Templates;
+use Koha::Database;
+
+use t::lib::TestBuilder;
+
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
+
+my $builder       = t::lib::TestBuilder->new;
+my $library       = $builder->build( { source => 'Branch' } );
+my $nb_of_templates = Koha::Notice::Templates->search->count;
+my ( $module, $mtt ) = ( 'circulation', 'email' );
+my $new_template = Koha::Notice::Template->new(
+    {
+        module                 => $module,
+        code                   => 'tmpl_code_for_t',
+        branchcode             => $library->{branchcode},
+        name                   => 'my template name for test 1',
+        title                  => 'my template title for test 1',
+        content                => 'This one is almost empty',
+        message_transport_type => $mtt,
+    }
+)->store;
+
+is(
+    Koha::Notice::Templates->search->count,
+    $nb_of_templates + 1,
+    'The template should have been added'
+);
+
+my $retrieved_template = Koha::Notice::Templates->find(
+    {
+        module                 => $module,
+        code                   => $new_template->code,
+        branchcode             => $library->{branchcode},
+        message_transport_type => $mtt,
+    }
+);
+is( $retrieved_template->name, $new_template->name,
+    'Find a notice template by pk should return the correct template' );
+
+$retrieved_template->delete;
+is( Koha::Notice::Templates->search->count,
+    $nb_of_templates, 'Delete should have deleted the template' );
+
+$schema->storage->txn_rollback;
+
+1;