Browse Source

Bug 19482: (follow-up) Fix update, add tests, restore closing </td>

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 <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
20.11.x
Nick Clemens 11 months ago
committed by Jonathan Druart
parent
commit
dcbc856b60
  1. 2
      installer/data/mysql/atomicupdate/bug_19482_add_mandatory_field_to_mapping.perl
  2. 2
      koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt
  3. 4
      t/db_dependent/Koha/SearchEngine/Elasticsearch/ExportConfig.t
  4. 6
      t/db_dependent/Koha/SearchEngine/Elasticsearch/Reset.t
  5. 9
      t/db_dependent/Koha/SearchField.t

2
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 );

2
koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt

@ -197,7 +197,7 @@ a.add, a.delete {
[% ELSE %]
<input type="text" name="search_field_label" value="[% search_field.label | html %]" />
[% END %]
</td>
<td>
[% IF search_field.mandatory %]
<input type="hidden" name="search_field_type" value="[% search_field.type | html %]" />

4
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');

6
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;

9
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;

Loading…
Cancel
Save