Bug 22363: Add tests
authorJosef Moravec <josef.moravec@gmail.com>
Mon, 18 Feb 2019 14:01:44 +0000 (14:01 +0000)
committerNick Clemens <nick@bywatersolutions.com>
Mon, 11 Mar 2019 11:22:00 +0000 (11:22 +0000)
Signed-off-by: Andrew Isherwood <andrew.isherwood@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
t/db_dependent/Koha/ActionLogs.t [new file with mode: 0644]

diff --git a/t/db_dependent/Koha/ActionLogs.t b/t/db_dependent/Koha/ActionLogs.t
new file mode 100644 (file)
index 0000000..894c8af
--- /dev/null
@@ -0,0 +1,70 @@
+#!/usr/bin/perl
+# This file is part of Koha.
+#
+# Copyright 2019 Koha Development Team
+#
+# 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 C4::Context;
+use C4::Log;
+use Koha::Database;
+
+use t::lib::TestBuilder;
+
+BEGIN {
+  use_ok('Koha::ActionLogs');
+}
+
+my $schema  = Koha::Database->new->schema;
+my $builder = t::lib::TestBuilder->new;
+
+subtest 'store() tests' => sub {
+    plan tests => 2;
+
+    $schema->storage->txn_begin;
+
+    my $logs_count = Koha::ActionLogs->count;
+    my $log = Koha::ActionLog->new({
+        module => 'CIRCULATION',
+        action => 'ISSUE',
+        interface => 'intranet',
+    })->store;
+    $log->discard_changes;
+
+    is( ref($log), 'Koha::ActionLog', 'Log object creation success');
+    is( Koha::ActionLogs->count, $logs_count + 1, 'Exactly one log was saved');
+
+    $schema->storage->txn_rollback;
+};
+
+subtest 'search() tests' => sub {
+    plan tests => 1;
+
+    $schema->storage->txn_begin;
+
+    my $patron1 = $builder->build_object({
+        class => 'Koha::Patrons',
+    });
+
+    logaction("MEMBERS", "MODIFY", $patron1->borrowernumber, "test");
+
+    is(Koha::ActionLogs->search({ object => $patron1->borrowernumber })->count, 1, 'search() return right number of action logs');
+
+    $schema->storage->txn_rollback;
+};
+
+1;