From c066a8ca2f648b9c823dedf9afad01dea1a4b6b1 Mon Sep 17 00:00:00 2001 From: Mark Tompsett Date: Mon, 20 Apr 2015 20:11:23 -0400 Subject: [PATCH] Bug 14030 - Added tests for duplicates. It seems that the id's are not really used, but rather the subtags, types, and language related fields. These tests check for duplicates. TEST PLAN --------- 1) Apply both patches 2) prove -v t/db_dependent/Languages.t -- may fail if you have duplicates. 3) ./installer/data/mysql/updatedatabase.pl -- this will trigger the atomicupdate, which because of this tweak, will correct duplicates. 4) prove -v t/db_dependent/Languages.t -- should succeed. 5) Run the updatedatabase.pl script multiple times. 6) prove -v t/db_dependent/Languages.t -- should still succeed. 7) koha qa test tools. Signed-off-by: Bernardo Gonzalez Kriegel No koha-qa errors, test run successfully, no more duplicates Signed-off-by: Katrin Fischer Fixed German description. Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- ...ug_14030-Add_Georgian_fix_Kannada_code.sql | 24 ++++++++++++- .../data/mysql/mandatory/subtag_registry.sql | 2 +- t/db_dependent/Languages.t | 35 ++++++++++++++++++- 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/installer/data/mysql/atomicupdate/bug_14030-Add_Georgian_fix_Kannada_code.sql b/installer/data/mysql/atomicupdate/bug_14030-Add_Georgian_fix_Kannada_code.sql index d07503ee98..59ac0cebfc 100644 --- a/installer/data/mysql/atomicupdate/bug_14030-Add_Georgian_fix_Kannada_code.sql +++ b/installer/data/mysql/atomicupdate/bug_14030-Add_Georgian_fix_Kannada_code.sql @@ -7,8 +7,23 @@ UPDATE language_descriptions SET subtag = 'kn', lang = 'kn' WHERE subtag = 'ka' UPDATE language_descriptions SET subtag = 'kn' WHERE subtag = 'ka' AND description = 'Kannada'; INSERT IGNORE INTO language_subtag_registry( subtag, type, description, added) VALUES ( 'ka', 'language', 'Georgian','2015-04-20'); +DELETE FROM language_subtag_registry + WHERE NOT id IN + (SELECT id FROM + (SELECT MIN(id) as id,subtag,type,description,added + FROM language_subtag_registry + GROUP BY subtag,type,description,added) + AS subtable); + INSERT IGNORE INTO language_rfc4646_to_iso639(rfc4646_subtag,iso639_2_code) VALUES ( 'ka', 'geo'); +DELETE FROM language_rfc4646_to_iso639 + WHERE NOT id IN + (SELECT id FROM + (SELECT MIN(id) as id,rfc4646_subtag,iso639_2_code + FROM language_rfc4646_to_iso639 + GROUP BY rfc4646_subtag,iso639_2_code) + AS subtable); INSERT IGNORE INTO language_descriptions(subtag, type, lang, description) VALUES ( 'ka', 'language', 'ka', 'ქართული'); @@ -16,6 +31,13 @@ INSERT IGNORE INTO language_descriptions(subtag, type, lang, description) VALUES INSERT IGNORE INTO language_descriptions(subtag, type, lang, description) VALUES ( 'ka', 'language', 'fr', 'Géorgien'); -INSERT IGNORE INTO language_descriptions(subtag, type, lang, description) VALUES ( 'ka', 'language', 'de', 'Georgische'); +INSERT IGNORE INTO language_descriptions(subtag, type, lang, description) VALUES ( 'ka', 'language', 'de', 'Georgisch'); INSERT IGNORE INTO language_descriptions(subtag, type, lang, description) VALUES ( 'ka', 'language', 'es', 'Georgiano'); + +DELETE FROM language_descriptions + WHERE NOT id IN + (SELECT id FROM + (SELECT MIN(id) as id,subtag,type,lang,description + FROM language_descriptions GROUP BY subtag,type,lang,description) + AS subtable); diff --git a/installer/data/mysql/mandatory/subtag_registry.sql b/installer/data/mysql/mandatory/subtag_registry.sql index bdf26316f0..aee0e9bdda 100755 --- a/installer/data/mysql/mandatory/subtag_registry.sql +++ b/installer/data/mysql/mandatory/subtag_registry.sql @@ -554,7 +554,7 @@ INSERT INTO language_descriptions(subtag, type, lang, description) VALUES ( 'ka', 'language', 'fr', 'Géorgien'); INSERT INTO language_descriptions(subtag, type, lang, description) -VALUES ( 'ka', 'language', 'de', 'Georgische'); +VALUES ( 'ka', 'language', 'de', 'Georgisch'); INSERT INTO language_descriptions(subtag, type, lang, description) VALUES ( 'ka', 'language', 'es', 'Georgiano'); diff --git a/t/db_dependent/Languages.t b/t/db_dependent/Languages.t index ca4413e344..d27e823de2 100755 --- a/t/db_dependent/Languages.t +++ b/t/db_dependent/Languages.t @@ -6,7 +6,7 @@ use strict; use warnings; -use Test::More tests => 13; +use Test::More tests => 16; use List::Util qw(first); use Data::Dumper; use Test::Warn; @@ -57,4 +57,37 @@ my @currentcheck2 = map { $_->{current} } @$translatedlanguages2; $onlyzeros = first { $_ != 0 } @currentcheck2; ok($onlyzeros, "There is a $onlyzeros\n"); +# Language Descriptions +my $sth = $dbh->prepare("SELECT DISTINCT subtag,type,lang,description from language_descriptions;"); +$sth->execute(); +my $DistinctLangDesc = $sth->fetchall_arrayref({}); + +$sth = $dbh->prepare("SELECT subtag,type,lang,description from language_descriptions;"); +$sth->execute(); +my $LangDesc = $sth->fetchall_arrayref({}); + +is(scalar(@$LangDesc),scalar(@$DistinctLangDesc),"No unexpected language_description duplicates."); + +# Language_subtag_registry +$sth = $dbh->prepare("SELECT DISTINCT subtag,type,description,added FROM language_subtag_registry;"); +$sth->execute(); +my $DistinctLangReg = $sth->fetchall_arrayref({}); + +$sth = $dbh->prepare("SELECT subtag,type,description,added FROM language_subtag_registry;"); +$sth->execute(); +my $LangReg = $sth->fetchall_arrayref({}); + +is(scalar(@$LangReg),scalar(@$DistinctLangReg),"No unexpected language_subtag_registry duplicates."); + +# Language RFC4646 to ISO639 +$sth = $dbh->prepare("SELECT DISTINCT rfc4646_subtag,iso639_2_code FROM language_rfc4646_to_iso639;"); +$sth->execute(); +my $DistinctLangRfc4646 = $sth->fetchall_arrayref({}); + +$sth = $dbh->prepare("SELECT rfc4646_subtag,iso639_2_code FROM language_rfc4646_to_iso639;"); +$sth->execute(); +my $LangRfc4646 = $sth->fetchall_arrayref({}); + +is(scalar(@$LangRfc4646),scalar(@$DistinctLangRfc4646),"No unexpected language_rfc4646_to_iso639 duplicates."); + $dbh->rollback; -- 2.39.5