From 5428d1dbcfc51ace3c651a081ba3b9ff6571e725 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 11 Aug 2023 14:37:07 +0000 Subject: [PATCH] Bug 34519: Unit tests Signed-off-by: Janusz Kaczmarek Signed-off-by: Katrin Fischer --- .../Template/Plugin/ExtendedAttributeTypes.t | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 t/db_dependent/Koha/Template/Plugin/ExtendedAttributeTypes.t diff --git a/t/db_dependent/Koha/Template/Plugin/ExtendedAttributeTypes.t b/t/db_dependent/Koha/Template/Plugin/ExtendedAttributeTypes.t new file mode 100644 index 0000000000..df1deae3a6 --- /dev/null +++ b/t/db_dependent/Koha/Template/Plugin/ExtendedAttributeTypes.t @@ -0,0 +1,76 @@ +#!/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 . + +use Modern::Perl; + +use Test::More tests => 5; + +use C4::Context; +use Koha::Database; +use Koha::Patron::Attribute::Types; + +use t::lib::TestBuilder; +use t::lib::Mocks; + +BEGIN { + use_ok('Koha::Template::Plugin::ExtendedAttributeTypes'); +} + +my $schema = Koha::Database->schema; +my $builder = t::lib::TestBuilder->new; + +$schema->storage->txn_begin; + +my $plugin = Koha::Template::Plugin::ExtendedAttributeTypes->new(); +ok( $plugin, "initialized ExtendedAttributeTypes plugin" ); + +my $typeA = $builder->build_object( + { + class => 'Koha::Patron::Attribute::Types', + value => { + staff_searchable => 0, + description => "Desc type A", + } + } +); +my $typeB = $builder->build_object( + { + class => 'Koha::Patron::Attribute::Types', + value => { + staff_searchable => 1, + description => "Desc type B", + } + } +); + +my $all_plugin = $plugin->all(); +my $all_objects = Koha::Patron::Attribute::Types->search(); + +is_deeply( $all_plugin->unblessed, $all_objects->unblessed, "all method returns all the types correctly"); + +my $all_plugin_codes = $plugin->codes(); +my $all_object_codes = Koha::Patron::Attribute::Types->search()->get_column('code'); + +is_deeply( $all_plugin_codes, $all_object_codes, "codes method returns the codes as expected"); + +my $searchable_plugin_codes = $plugin->codes({ staff_searchable => 1 }); +my $searchable_object_codes = Koha::Patron::Attribute::Types->search({ staff_searchable => 1 })->get_column('code'); + +is_deeply( $searchable_plugin_codes, $searchable_object_codes, "searching plugin method works as expected"); + +$schema->storage->txn_rollback; + +1; -- 2.30.2