From 9d47ef0f2d05e5c117ad79f2f8fe2f274fe2ea79 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 11 May 2020 15:35:34 -0300 Subject: [PATCH] Bug 25457: Regression tests This patch implements tests on the ViewPolicy RecordProcessor filter, to assess it caches the calculated MARC subfield structure between calls. Signed-off-by: Tomas Cohen Arazi Signed-off-by: Nick Clemens --- t/db_dependent/Filter_MARC_ViewPolicy.t | 71 ++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Filter_MARC_ViewPolicy.t b/t/db_dependent/Filter_MARC_ViewPolicy.t index 552245a01b..61dda7ebd3 100644 --- a/t/db_dependent/Filter_MARC_ViewPolicy.t +++ b/t/db_dependent/Filter_MARC_ViewPolicy.t @@ -23,7 +23,7 @@ use Modern::Perl; -use Test::More tests => 3; +use Test::More tests => 4; use List::MoreUtils qw/any/; use MARC::Record; @@ -33,6 +33,8 @@ use C4::Biblio; use Koha::Caches; use Koha::Database; +use t::lib::TestBuilder; + BEGIN { use_ok('Koha::RecordProcessor'); } @@ -41,6 +43,7 @@ my $dbh = C4::Context->dbh; my $database = Koha::Database->new(); my $schema = $database->schema(); +my $builder = t::lib::TestBuilder->new; sub run_hiding_tests { @@ -205,3 +208,69 @@ subtest 'Koha::Filter::MARC::ViewPolicy intranet tests' => sub { $schema->storage->txn_rollback(); }; +subtest 'caching tests' => sub { + + plan tests => 3; + + $schema->storage->txn_begin; + + my $fw_1 = $builder->build_object( { class => 'Koha::BiblioFrameworks' } ); + my $fw_2 = $builder->build_object( { class => 'Koha::BiblioFrameworks' } ); + my $mss_1 = $builder->build_object( + { + class => 'Koha::MarcSubfieldStructures', + value => { frameworkcode => $fw_1->frameworkcode } + } + ); + my $mss_2 = $builder->build_object( + { + class => 'Koha::MarcSubfieldStructures', + value => { frameworkcode => $fw_2->frameworkcode } + } + ); + + my $biblio = $builder->build_sample_biblio; + my $record = $biblio->metadata->record; + + my $processor = Koha::RecordProcessor->new( + { + schema => 'MARC', + filters => ('ViewPolicy'), + } + ); + + $processor->options( + { + frameworkcode => $fw_1->frameworkcode + } + ); + + $processor->process($record); + + ok( + exists $processor->filters->[0]->{_cached_frameworks} + ->{ $fw_1->frameworkcode }, + 'First framework is cached' + ); + + $processor->options( + { + frameworkcode => $fw_2->frameworkcode + } + ); + + $processor->process($record); + + ok( + exists $processor->filters->[0]->{_cached_frameworks} + ->{ $fw_1->frameworkcode }, + 'First framework is cached' + ); + ok( + exists $processor->filters->[0]->{_cached_frameworks} + ->{ $fw_2->frameworkcode }, + 'Second framework is cached' + ); + + $schema->storage->txn_rollback; +}; -- 2.11.0