Bug 18512: Add tests
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 2 May 2017 20:27:48 +0000 (17:27 -0300)
committerKyle M Hall <kyle@bywatersolutions.com>
Mon, 8 May 2017 12:38:11 +0000 (08:38 -0400)
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
t/db_dependent/Template/Plugin/AuthorisedValues.t [new file with mode: 0644]

diff --git a/t/db_dependent/Template/Plugin/AuthorisedValues.t b/t/db_dependent/Template/Plugin/AuthorisedValues.t
new file mode 100644 (file)
index 0000000..e57dad1
--- /dev/null
@@ -0,0 +1,66 @@
+#!/usr/bin/perl
+
+# 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 C4::Context;
+use Koha::Database;
+use Koha::Template::Plugin::AuthorisedValues;
+
+use t::lib::TestBuilder;
+use t::lib::Mocks;
+
+my $schema = Koha::Database->schema;
+$schema->storage->txn_begin;
+my $builder = t::lib::TestBuilder->new;
+
+subtest 'GetByCode' => sub {
+    plan tests => 4;
+    my $avc =
+      $builder->build_object( { class => 'Koha::AuthorisedValueCategories' } );
+    my $av_1 = $builder->build_object(
+        {
+            class => 'Koha::AuthorisedValues',
+            value => { category => $avc->category_name }
+        }
+    );
+    my $av_2 = $builder->build_object(
+        {
+            class => 'Koha::AuthorisedValues',
+            value => { category => $avc->category_name }
+        }
+    );
+    my $description =
+      Koha::Template::Plugin::AuthorisedValues->GetByCode( $avc->category_name,
+        $av_1->authorised_value );
+    is( $description, $av_1->lib, 'GetByCode should return the correct dsecription' );
+    my $opac_description =
+      Koha::Template::Plugin::AuthorisedValues->GetByCode( $avc->category_name,
+        $av_1->authorised_value, 'opac' );
+    is( $opac_description, $av_1->opac_description, 'GetByCode should return the correct opac_description' );
+    $av_1->lib_opac(undef)->store;
+    $opac_description =
+      Koha::Template::Plugin::AuthorisedValues->GetByCode( $avc->category_name,
+        $av_1->authorised_value, 'opac' );
+    is( $opac_description, $av_1->lib, 'GetByCode should return the staff description if the lib_opac is not filled' );
+
+    $description =
+      Koha::Template::Plugin::AuthorisedValues->GetByCode( $avc->category_name,
+        'does_not_exist' );
+    is( $description, 'does_not_exist', 'GetByCode should return the code passed if the AV does not exist' );
+};