Bug 24459: Regression tests
authorTomas Cohen Arazi <tomascohen@theke.io>
Mon, 20 Jan 2020 12:47:18 +0000 (09:47 -0300)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Thu, 23 Jan 2020 09:07:07 +0000 (09:07 +0000)
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
t/db_dependent/Koha/Acquisition/Invoice.t [new file with mode: 0644]
t/db_dependent/Koha/Patron.t

diff --git a/t/db_dependent/Koha/Acquisition/Invoice.t b/t/db_dependent/Koha/Acquisition/Invoice.t
new file mode 100644 (file)
index 0000000..e99f01f
--- /dev/null
@@ -0,0 +1,70 @@
+#!/usr/bin/perl
+
+# Copyright 2020 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 => 2;
+use Test::MockModule;
+
+use t::lib::TestBuilder;
+
+use Koha::Database;
+use Koha::DateUtils qw(dt_from_string);
+
+use_ok('Koha::Acquisition::Invoice');
+
+my $schema  = Koha::Database->schema;
+my $builder = t::lib::TestBuilder->new;
+
+subtest 'to_api() tests' => sub {
+
+    plan tests => 6;
+
+    $schema->storage->txn_begin;
+
+    my $invoice_class = Test::MockModule->new('Koha::Acquisition::Invoice');
+    $invoice_class->mock(
+        'algo',
+        sub { return 'algo' }
+    );
+
+    my $invoice = $builder->build_object(
+        {
+            class => 'Koha::Acquisition::Invoices',
+            value => {
+                closedate => undef
+            }
+        }
+    );
+
+    my $closed = $invoice->to_api->{closed};
+    ok( defined $closed, 'closed is defined' );
+    ok( !$closed, 'closedate is undef, closed evaluates to false' );
+
+    $invoice->closedate( dt_from_string )->store->discard_changes;
+    $closed = $invoice->to_api->{closed};
+    ok( defined $closed, 'closed is defined' );
+    ok( $closed, 'closedate is defined, closed evaluates to true' );
+
+    my $invoice_json = $invoice->to_api({ embed => { algo => {} } });
+    ok( exists $invoice_json->{algo} );
+    is_deeply( $invoice_json->{algo}, 'algo' );
+
+    $schema->storage->txn_rollback;
+};
index adfcb60..63b77c1 100644 (file)
 
 use Modern::Perl;
 
-use Test::More tests => 2;
+use Test::More tests => 3;
 use Test::Exception;
 
 use Koha::Database;
+use Koha::DateUtils qw(dt_from_string);
 use Koha::Patrons;
 use Koha::Patron::Relationships;
 
@@ -154,3 +155,40 @@ subtest 'add_enrolment_fee_if_needed() tests' => sub {
         $schema->storage->txn_rollback;
     };
 };
+
+subtest 'to_api() tests' => sub {
+
+    plan tests => 6;
+
+    $schema->storage->txn_begin;
+
+    my $patron_class = Test::MockModule->new('Koha::Patron');
+    $patron_class->mock(
+        'algo',
+        sub { return 'algo' }
+    );
+
+    my $patron = $builder->build_object(
+        {
+            class => 'Koha::Patrons',
+            value => {
+                debarred => undef
+            }
+        }
+    );
+
+    my $restricted = $patron->to_api->{restricted};
+    ok( defined $restricted, 'restricted is defined' );
+    ok( !$restricted, 'debarred is undef, restricted evaluates to false' );
+
+    $patron->debarred( dt_from_string->add( days => 1 ) )->store->discard_changes;
+    $restricted = $patron->to_api->{restricted};
+    ok( defined $restricted, 'restricted is defined' );
+    ok( $restricted, 'debarred is defined, restricted evaluates to true' );
+
+    my $patron_json = $patron->to_api({ embed => { algo => {} } });
+    ok( exists $patron_json->{algo} );
+    is( $patron_json->{algo}, 'algo' );
+
+    $schema->storage->txn_rollback;
+};