Bug 12001: (QA follow-up) Add test for Koha::Account::Lines object
authorJosef Moravec <josef.moravec@gmail.com>
Mon, 19 Feb 2018 21:24:32 +0000 (21:24 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 23 Feb 2018 13:57:30 +0000 (10:57 -0300)
Test plan
prove t/db_dependent/Koha/Account/Lines.t
--> should be green

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
t/db_dependent/Koha/Account/Lines.t [new file with mode: 0755]

diff --git a/t/db_dependent/Koha/Account/Lines.t b/t/db_dependent/Koha/Account/Lines.t
new file mode 100755 (executable)
index 0000000..0c3287d
--- /dev/null
@@ -0,0 +1,65 @@
+#!/usr/bin/perl
+
+# Copyright 2018 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 => 1;
+
+use Koha::Account::Lines;
+use Koha::Items;
+
+use t::lib::TestBuilder;
+
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
+
+my $builder = t::lib::TestBuilder->new;
+
+subtest 'item' => sub {
+        plan tests => 2;
+
+        my $library = $builder->build( { source => 'Branch' } );
+        my $biblioitem = $builder->build( { source => 'Biblioitem' } );
+        my $patron = $builder->build( { source => 'Borrower' } );
+        my $item = Koha::Item->new(
+        {
+            biblionumber     => $biblioitem->{biblionumber},
+            biblioitemnumber => $biblioitem->{biblioitemnumber},
+            homebranch       => $library->{branchcode},
+            holdingbranch    => $library->{branchcode},
+            barcode          => 'some_barcode_12',
+            itype            => 'BK',
+        })->store;
+
+        my $line = Koha::Account::Line->new(
+        {
+            borrowernumber => $patron->{borrowernumber},
+            itemnumber     => $item->itemnumber,
+            accounttype    => "F",
+            amount         => 10,
+        })->store;
+
+        my $account_line_item = $line->item;
+        is( ref( $account_line_item ), 'Koha::Item', 'Koha::Account::Line->item should return a Koha::Item' );
+        is( $line->itemnumber, $account_line_item->itemnumber, 'Koha::Account::Line->item should return the correct item' );
+};
+
+$schema->storage->txn_rollback;
+
+1;