From 7fbafe5d7dc042a797e2c006be5c9f2e6b4a2c69 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 8 Oct 2018 16:21:25 -0300 Subject: [PATCH] Bug 21503: Tests for the existing behavior This patch introduces 7 tests for the current behaviour for the AuthorisedValues template plugin. To test: - Apply this patch - Run: $ kshell k$ prove t/db_dependent/Template/Plugin/AuthorisedValues.t => SUCCESS: Tests pass, all green! Signed-off-by: Fridolin Somers Signed-off-by: Jonathan Druart --- .../Template/Plugin/AuthorisedValues.t | 85 ++++++++++++++++++- 1 file changed, 83 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/Template/Plugin/AuthorisedValues.t b/t/db_dependent/Template/Plugin/AuthorisedValues.t index e57dad165d..d9a1f3add5 100644 --- a/t/db_dependent/Template/Plugin/AuthorisedValues.t +++ b/t/db_dependent/Template/Plugin/AuthorisedValues.t @@ -16,21 +16,25 @@ use Modern::Perl; -use Test::More tests => 1; +use Test::More tests => 2; use C4::Context; +use Koha::Caches; use Koha::Database; +use Koha::MarcSubfieldStructures; 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; + + $schema->storage->txn_begin; + my $avc = $builder->build_object( { class => 'Koha::AuthorisedValueCategories' } ); my $av_1 = $builder->build_object( @@ -63,4 +67,81 @@ subtest 'GetByCode' => sub { 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' ); + + $schema->storage->txn_rollback; +}; + +subtest 'GetDescriptionByKohaField' => sub { + + plan tests => 7; + + $schema->storage->txn_begin; + + my $avc = $builder->build_object( { class => 'Koha::AuthorisedValueCategories' } ); + + # Create a framework mapping + Koha::MarcSubfieldStructure->new( + { tagfield => '988', + tagsubfield => 'a', + liblibrarian => 'Dummy field', + libopac => 'Dummy field', + repeatable => 0, + mandatory => 0, + kohafield => 'dummy.field', + tab => '9', + authorised_value => $avc->category_name, + authtypecode => q{}, + value_builder => q{}, + isurl => 0, + hidden => 0, + frameworkcode => q{}, + seealso => q{}, + link => q{}, + defaultvalue => undef + } + )->store; + + # Make sure we are not catch by cache + Koha::Caches->get_instance->flush_all; + my $av_1 = $builder->build_object( + { class => 'Koha::AuthorisedValues', + value => { category => $avc->category_name, lib_opac => 'lib_opac', lib => 'lib' } + } + ); + my $av_2 = $builder->build_object( + { class => 'Koha::AuthorisedValues', + value => { category => $avc->category_name, lib_opac => undef, lib => 'lib' } + } + ); + my $av_3 = $builder->build_object( + { class => 'Koha::AuthorisedValues', + value => { category => $avc->category_name, lib_opac => undef, lib => undef } + } + ); + my $non_existent_av = $av_3->authorised_value; + $av_3->delete; + + my $av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField( + { opac => 1, kohafield => 'dummy.field', authorised_value => $av_1->authorised_value } ); + is( $av, 'lib_opac', 'We requested OPAC description.' ); + $av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField( + { opac => 1, kohafield => 'dummy.field', authorised_value => $av_2->authorised_value } ); + is( $av, 'lib', 'We requested OPAC description, return a regular description.' ); + $av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField( + { opac => 1, kohafield => 'dummy.field', authorised_value => $av_3->authorised_value } ); + is( $av, $av_3->authorised_value, 'We requested OPAC or regular description, return the authorised_value.' ); + $av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField( + { opac => 1, kohafield => 'dummy.field', authorised_value => $non_existent_av } ); + is( $av, $av_3->authorised_value, 'We requested a non existing authorised_value for the OPAC, return the authorised_value.' ); + $av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField( + { kohafield => 'dummy.field', authorised_value => $av_1->authorised_value } ); + is( $av, 'lib', 'We requested a regular description.' ); + $av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField( + { kohafield => 'dummy.field', authorised_value => $av_3->authorised_value } ); + is( $av, $av_3->authorised_value, 'We requested a regular description, return the authorised_value.' ); + $av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField( + { kohafield => 'dummy.field', authorised_value => $non_existent_av } ); + is( $av, $av_3->authorised_value, 'We requested a non existing authorised_value, return the authorised_value.' ); + + $schema->storage->txn_rollback; }; -- 2.20.1