From dcbc856b60436aa1341beb7da75ac3665d4e5f92 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Sun, 25 Oct 2020 02:16:42 +0000 Subject: [PATCH] Bug 19482: (follow-up) Fix update, add tests, restore closing To test: 1 - View the mappings page, confirm table is correctly structured 2 - prove -v t/db_dependent/Koha/SearchEngine/Elasticsearch/ExportConfig.t t/db_dependent/Koha/SearchEngine/Elasticsearch/Reset.t t/db_dependent/Koha/SearchField.t 3 - Confirm update statement works and table is ordered correctly Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart --- .../bug_19482_add_mandatory_field_to_mapping.perl | 2 +- .../modules/admin/searchengine/elasticsearch/mappings.tt | 2 +- .../Koha/SearchEngine/Elasticsearch/ExportConfig.t | 4 +++- t/db_dependent/Koha/SearchEngine/Elasticsearch/Reset.t | 6 +++++- t/db_dependent/Koha/SearchField.t | 9 ++++++++- 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/installer/data/mysql/atomicupdate/bug_19482_add_mandatory_field_to_mapping.perl b/installer/data/mysql/atomicupdate/bug_19482_add_mandatory_field_to_mapping.perl index 2bda6ddd1f..4fb8e51274 100644 --- a/installer/data/mysql/atomicupdate/bug_19482_add_mandatory_field_to_mapping.perl +++ b/installer/data/mysql/atomicupdate/bug_19482_add_mandatory_field_to_mapping.perl @@ -2,7 +2,7 @@ $DBversion = 'XXX'; # will be replaced by the RM if( CheckVersion( $DBversion ) ) { if( !column_exists( 'search_field', 'mandatory' ) ) { - $dbh->do( "ALTER TABLE search_field ADD COLUMN mandatory tinyint(1) NULL DEFAULT NULL" ); + $dbh->do( "ALTER TABLE search_field ADD COLUMN mandatory tinyint(1) NULL DEFAULT NULL AFTER opac" ); } SetVersion( $DBversion ); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt index 8eb5b9675b..bd726dacca 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt @@ -197,7 +197,7 @@ a.add, a.delete { [% ELSE %] [% END %] - + [% IF search_field.mandatory %] diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch/ExportConfig.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch/ExportConfig.t index 82dc5537f6..1c5ce67649 100755 --- a/t/db_dependent/Koha/SearchEngine/Elasticsearch/ExportConfig.t +++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch/ExportConfig.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 18; +use Test::More tests => 19; use Koha::Database; use Koha::SearchFields; @@ -43,6 +43,7 @@ my $search_field = Koha::SearchFields->find_or_create( weight => 17, staff_client => 0, opac => 1, + mandatory => 1 }, { key => 'name' } ); @@ -95,6 +96,7 @@ is( $mappings->{biblios}{title}{label}, 'Title', 'title has label Title'); is( $mappings->{biblios}{title}{facet_order}, undef, 'Facet order is undef'); is( $mappings->{biblios}{title}{opac}, 1, 'title is opac searchable'); is( $mappings->{biblios}{title}{staff_client}, 0, 'title is not staff searchable'); +is( $mappings->{biblios}{title}{mandatory}, 1, 'title is mandatory'); is(scalar(@{ $mappings->{biblios}{title}{mappings} }), 3, 'Title has 3 mappings'); diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch/Reset.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch/Reset.t index e57ee16596..57f4e06ea4 100755 --- a/t/db_dependent/Koha/SearchEngine/Elasticsearch/Reset.t +++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch/Reset.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 5; +use Test::More tests => 7; use Test::MockModule; use Koha::Database; @@ -29,6 +29,7 @@ my $indexes = { 'label' => 'Match', 'type' => '', 'weight' => 15, + 'mandatory' => 0, 'mappings' => [] } }, @@ -37,6 +38,7 @@ my $indexes = { 'label' => 'title', 'type' => '', 'weight' => 20, + 'mandatory' => 1, 'mapping' => [] } } @@ -66,9 +68,11 @@ is($search_fields->count, 2, 'There is 2 search fields after reset'); my $match_sf = Koha::SearchFields->search({ name => 'Match' })->next; is($match_sf->weight, '15.00', 'Match search field is weighted with 15'); +is($match_sf->mandatory, '0', 'Match search field is not mandatory'); my $title_sf = Koha::SearchFields->search({ name => 'title' })->next; is($title_sf->weight, '20.00', 'Title search field is weighted with 20'); +is($title_sf->mandatory, '1', 'Title search field is mandatory'); $schema->storage->txn_rollback; diff --git a/t/db_dependent/Koha/SearchField.t b/t/db_dependent/Koha/SearchField.t index 6f426fd1b9..8212d18064 100755 --- a/t/db_dependent/Koha/SearchField.t +++ b/t/db_dependent/Koha/SearchField.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 8; +use Test::More tests => 10; use Koha::Database; use Koha::SearchFields; @@ -128,11 +128,18 @@ ok($search_field->is_mapped_biblios, 'Search field is mapped with authorities an my $sf3 = $builder->build({ source => 'SearchField', + value => { + mandatory => 1, + } }); $search_field = Koha::SearchFields->find($sf3->{id}); ok(!$search_field->is_mapped_biblios, 'Search field is not mapped'); +ok($search_field->mandatory, 'Search field can be marked mandatory'); +$search_field->mandatory(0)->store; +ok(!$search_field->mandatory, 'Search field can be marked not mandatory'); + Koha::SearchFields->search({})->delete; $schema->storage->txn_rollback; -- 2.39.5