Bugzilla – Attachment 124898 Details for
Bug 29029
Koha::Object - add filter method based on column sets
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29029: Add tests
Bug-29029-Add-tests.patch (text/plain), 4.59 KB, created by
Marcel de Rooy
on 2021-09-15 15:02:07 UTC
(
hide
)
Description:
Bug 29029: Add tests
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2021-09-15 15:02:07 UTC
Size:
4.59 KB
patch
obsolete
>From 544c90f638e5e25390616370246afc406df230e6 Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Wed, 15 Sep 2021 14:59:21 +0000 >Subject: [PATCH] Bug 29029: Add tests >Content-Type: text/plain; charset=utf-8 > >--- > t/db_dependent/Koha/Object/ColumnSet.t | 88 ++++++++++++++++++++++++++ > 1 file changed, 88 insertions(+) > create mode 100755 t/db_dependent/Koha/Object/ColumnSet.t > >diff --git a/t/db_dependent/Koha/Object/ColumnSet.t b/t/db_dependent/Koha/Object/ColumnSet.t >new file mode 100755 >index 0000000000..c289f1f6f5 >--- /dev/null >+++ b/t/db_dependent/Koha/Object/ColumnSet.t >@@ -0,0 +1,88 @@ >+#!/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 Data::Dumper qw/Dumper/; >+use Test::MockModule; >+use Test::More tests => 1; >+ >+use t::lib::TestBuilder; >+ >+use Koha::City; >+use Koha::Logger; >+use Koha::Object::ColumnSet; >+use Koha::Schema::Result::City; >+ >+our $builder = t::lib::TestBuilder->new; >+our $column_sets = {}; >+our $city_module = Test::MockModule->new( 'Koha::Schema::Result::City' ); >+our $logger_module = Test::MockModule->new( 'Koha::Logger' ); >+our $log_test; >+ >+subtest 'Test ColumnSet on City' => sub { >+ plan tests => 14; >+ >+ my $city = $builder->build_object( { class => 'Koha::Cities' } ); >+ my $dump = {}; >+ >+ # First test: feature not supported >+ # This ASSUMES that City does not yet contain a get_column_set routine. >+ my $count = keys %{$city->unblessed}; >+ is_deeply( $city->filter({ column_set => 'whatever' }), {}, 'No data expected' ); >+ is_deeply( Koha::Object::ColumnSet->new({ name => 'opac_test', rs => $city->_result })->list_columns, [], >+ 'No columns listed when feature not supported in schema' ); >+ >+ # Now test bad supported feature (wrong return value) >+ $city_module->mock( 'get_column_set', sub {} ); >+ is_deeply( $city->filter({ column_set => 'whatever' }), {}, 'No data for bad support' ); >+ is_deeply( Koha::Object::ColumnSet->new({ name => 'opac_test', rs => $city->_result })->list_columns, [], >+ 'list_columns should still be empty' ); >+ >+ # What about empty column sets? >+ $city_module->mock( 'get_column_set', sub { return $column_sets->{$_[1]} // []; } ); >+ is_deeply( $city->filter({ column_set => 'whatever' }), {}, 'Expected no fields' ); >+ is_deeply( Koha::Object::ColumnSet->new({ name => 'opac_test', rs => $city->_result })->list_columns, [], >+ 'list_columns should still be empty again' ); >+ >+ # Now make it return some data >+ $column_sets->{test} = [ 'aap', 'noot', 'mies' ]; >+ $column_sets->{opac_test} = [ 'city_name', 'city_state' ]; >+ is( keys %{$city->filter({ column_set => 'opac_test' })}, 2, 'Expected two fields' ); >+ is( keys %{$city->filter({ column_set => 'test' })}, 0, 'No data for unknown fields' ); >+ is_deeply( Koha::Object::ColumnSet->new({ name => 'opac_test', rs => $city->_result })->list_columns, $column_sets->{opac_test}, >+ 'list_columns should return some columns now' ); >+ >+ # Test input parameter, deny_mode >+ my $input = { city_id => 20, city_name => 'Rotterdam', aap => 2 }; >+ my $result = $city->filter({ input => $input, column_set => 'test' }); >+ is_deeply( $result, { aap => 2 }, 'Only one key got through' ); >+ $result = $city->filter({ input => $input, column_set => 'test', deny_mode => 1 }); >+ is_deeply( $result, { city_id => 20, city_name => 'Rotterdam' }, 'Two keys with deny_mode' ); >+ >+ # Test dump parameter >+ $result = $city->filter({ input => $input, column_set => 'test', dump => $dump }); >+ is_deeply( $dump, { city_id => 20, city_name => 'Rotterdam' }, 'Check dump variable' ); >+ >+ # Test logging >+ $log_test = 0; >+ $logger_module->mock( 'warn', sub { $log_test++; } ); >+ $result = $city->filter({ input => $input, column_set => 'test', log_level => 'warn' }); >+ is( $log_test, 1, 'Filter triggered warn' ); >+ $result = $city->filter({ input => {}, column_set => 'test', log_level => 'warn' }); >+ is( $log_test, 1, 'Empty hash did not trigger warn again' ); >+ >+}; >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 29029
:
124885
|
124897
| 124898