Browse Source

Bug 28445: Prevent UI/Form/Builder/Item.t to fail randomly

MySQL and Perl don't order strings with _ identically which cause a
mismatch when comparing the itemtypes.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
21.11.x
Jonathan Druart 2 years ago
parent
commit
77a34e099a
  1. 32
      t/db_dependent/Koha/UI/Form/Builder/Item.t

32
t/db_dependent/Koha/UI/Form/Builder/Item.t

@ -45,6 +45,16 @@ $cache->clear_from_cache("MarcSubfieldStructure-");
# 952$t is linked with items.copynumber and is not repeatable # 952$t is linked with items.copynumber and is not repeatable
setup_mss(); setup_mss();
# FIXME Later in this script we are comparing itemtypes, ordered by their description.
# MySQL and Perl don't sort _ identically.
# If you have one itemtype BK and another one B_K, MySQL will sort B_K first when Perl will sort it last
my @itemtypes = Koha::ItemTypes->search->as_list;
for my $itemtype ( @itemtypes ) {
my $d = $itemtype->description;
$d =~ s|_||g;
$itemtype->description($d)->store;
}
subtest 'authorised values' => sub { subtest 'authorised values' => sub {
#plan tests => 1; #plan tests => 1;
@ -111,29 +121,23 @@ subtest 'authorised values' => sub {
subtest 'itemtypes' => sub { subtest 'itemtypes' => sub {
plan tests => 2; plan tests => 2;
my ($subfield) = grep { $_->{kohafield} eq 'items.itype' } @$subfields; my ($subfield) = grep { $_->{kohafield} eq 'items.itype' } @$subfields;
my $itemtypes = Koha::ItemTypes->search; my @itemtypes = Koha::ItemTypes->search->as_list;
my $expected = [ my $expected = [
"", "",
map { $_->itemtype } map { $_->itemtype }
# We need to sort using uc or perl won't be case insensitive # We need to sort using uc or perl won't be case insensitive
sort { uc($a->translated_description) cmp uc($b->translated_description) } sort { uc($a->translated_description) cmp uc($b->translated_description) }
$itemtypes->as_list @itemtypes
]; ];
is_deeply( is_deeply(
$subfield->{marc_value}->{values}, $subfield->{marc_value}->{values},
$expected, $expected,
"Item types should be sorted by description and an empty entry should be shown" "Item types should be sorted by description and an empty entry should be shown"
) );
or diag("Itemtypes details: " . Dumper(
$subfield->{marc_value}->{values},
$expected,
{ map { $_->itemtype => $_->translated_description } $itemtypes->as_list },
$Koha::Schema::Result::Itemtype::LANGUAGE,
));
is_deeply( $subfield->{marc_value}->{labels}, is_deeply( $subfield->{marc_value}->{labels},
{ map { $_->itemtype => $_->description } $itemtypes->as_list }, { map { $_->itemtype => $_->description } @itemtypes},
'Labels should be correctly displayed' 'Labels should be correctly displayed'
); );
}; };

Loading…
Cancel
Save