View | Details | Raw Unified | Return to bug 33237
Collapse All | Expand All

(-)a/t/db_dependent/Letters.t (-90 / +69 lines)
Lines 879-951 subtest 'GetPreparedLetter' => sub { Link Here
879
879
880
};
880
};
881
881
882
883
884
subtest 'TranslateNotices' => sub {
882
subtest 'TranslateNotices' => sub {
885
    plan tests => 10;
883
    plan tests => 10;
886
884
887
    t::lib::Mocks::mock_preference( 'TranslateNotices', '1' );
885
    t::lib::Mocks::mock_config( 'intrahtdocs', '/kohadevbox/koha/t/mock_templates/intranet-tmpl' );
888
886
    t::lib::Mocks::mock_preference( 'OPACLanguages', 'fr-CA,en' );
889
    $dbh->do(
890
        q|
891
        INSERT INTO letter (module, code, branchcode, name, title, content, message_transport_type, lang) VALUES
892
        ('test', 'code', '', 'test', 'a test', 'just a test', 'email', 'default'),
893
        ('test', 'code', '', 'test', 'una prueba', 'solo una prueba', 'email', 'es-ES');
894
    | );
895
    my $substitute = {};
896
    my $letter = C4::Letters::GetPreparedLetter(
897
            module                 => 'test',
898
            tables                 => $tables,
899
            letter_code            => 'code',
900
            message_transport_type => 'email',
901
            substitute             => $substitute,
902
    );
903
    is(
904
        $letter->{title},
905
        'a test',
906
        'GetPreparedLetter should return the default one if the lang parameter is not provided'
907
    );
908
    # Note: What about includes, which language should be assumed 'default' here?
909
910
    $letter = C4::Letters::GetPreparedLetter(
911
            module                 => 'test',
912
            tables                 => $tables,
913
            letter_code            => 'code',
914
            message_transport_type => 'email',
915
            substitute             => $substitute,
916
            lang                   => 'es-ES',
917
    );
918
    is( $letter->{title}, 'una prueba',
919
        'GetPreparedLetter should return the required notice if it exists' );
920
921
    $letter = C4::Letters::GetPreparedLetter(
922
            module                 => 'test',
923
            tables                 => $tables,
924
            letter_code            => 'code',
925
            message_transport_type => 'email',
926
            substitute             => $substitute,
927
            lang                   => 'fr-FR',
928
    );
929
    is(
930
        $letter->{title},
931
        'a test',
932
        'GetPreparedLetter should return the default notice if the one required does not exist'
933
    );
934
935
    t::lib::Mocks::mock_preference( 'TranslateNotices', '' );
936
937
    $letter = C4::Letters::GetPreparedLetter(
938
            module                 => 'test',
939
            tables                 => $tables,
940
            letter_code            => 'code',
941
            message_transport_type => 'email',
942
            substitute             => $substitute,
943
            lang                   => 'es-ES',
944
    );
945
    is( $letter->{title}, 'a test',
946
        'GetPreparedLetter should return the default notice if pref disabled but additional language exists' );
947
948
    t::lib::Mocks::mock_preference( 'TranslateNotices', '1' );
949
887
950
    my $amount      = -20;
888
    my $amount      = -20;
951
    my $accountline = $builder->build(
889
    my $accountline = $builder->build(
Lines 962-1024 subtest 'TranslateNotices' => sub { Link Here
962
    $dbh->do(
900
    $dbh->do(
963
        q|
901
        q|
964
        INSERT INTO letter (module, code, branchcode, name, title, content, message_transport_type, lang) VALUES
902
        INSERT INTO letter (module, code, branchcode, name, title, content, message_transport_type, lang) VALUES
965
        ('test', 'payment', '', 'Paiement du compte', 'Paiement du compte', "[% PROCESS 'accounts.inc' %][% PROCESS account_type_description account=credit %][% credit.description %]", 'print', 'fr-CA'),
903
        ('test', 'payment', '', 'Default notice', 'Default notice', "[% PROCESS 'accounts.inc' %][% PROCESS account_type_description account=credit %][% credit.description %]", 'print', 'default'),
966
        ('test', 'payment', '', 'Default payment notice', 'Default payment notice', "[% PROCESS 'accounts.inc' %][% PROCESS account_type_description account=credit %][% credit.description %]", 'print', 'default');
904
        ('test', 'payment', '', 'Default notice', 'English notice', "[% PROCESS 'accounts.inc' %][% PROCESS account_type_description account=credit %][% credit.description %]", 'print', 'en'),
905
        ('test', 'payment', '', 'Paiement du compte', 'Paiement du compte', "[% PROCESS 'accounts.inc' %][% PROCESS account_type_description account=credit %][% credit.description %]", 'print', 'fr-CA');
967
    |
906
    |
968
    );
907
    );
969
970
    t::lib::Mocks::mock_config( 'intrahtdocs', '/kohadevbox/koha/t/mock_templates/intranet-tmpl' );
971
972
    $tables = {
908
    $tables = {
973
        borrowers => $borrowernumber,
909
        borrowers => $borrowernumber,
974
        credits   => $accountline->{accountlines_id},
910
        credits   => $accountline->{accountlines_id},
975
    };
911
    };
912
    my $substitute = {};
976
913
977
    $letter = C4::Letters::GetPreparedLetter(
914
    t::lib::Mocks::mock_preference( 'TranslateNotices', '1' );
915
916
    my $letter = C4::Letters::GetPreparedLetter(
978
        module                 => 'test',
917
        module                 => 'test',
918
        tables                 => $tables,
979
        letter_code            => 'payment',
919
        letter_code            => 'payment',
980
        message_transport_type => 'print',
920
        message_transport_type => 'print',
921
        substitute             => $substitute,
922
    );
923
    is(
924
        $letter->{title},
925
        'Default notice',
926
        'GetPreparedLetter should return the default one if the lang parameter is not provided'
927
    );
928
    like(
929
        $letter->{content}, qr/Paiement/,
930
        'Template includes match the default language from OPACLanguages (default = fr-CA)'
931
    );
932
933
    $letter = C4::Letters::GetPreparedLetter(
934
        module                 => 'test',
981
        tables                 => $tables,
935
        tables                 => $tables,
936
        letter_code            => 'payment',
937
        message_transport_type => 'print',
938
        substitute             => $substitute,
982
        lang                   => 'fr-CA',
939
        lang                   => 'fr-CA',
983
    );
940
    );
984
    is( $letter->{title}, 'Paiement du compte',
941
    is(
985
        'GetPreparedLetter should return the notice in patron\'s preferred language' );
942
        $letter->{title}, 'Paiement du compte',
943
        'GetPreparedLetter should return the requested language notice if it exists (fr-CA = default)'
944
    );
986
    like(
945
    like(
987
        $letter->{content}, qr/Paiement/,
946
        $letter->{content}, qr/Paiement/,
988
        'Template includes should use the patron\'s preferred language too'
947
        'Template includes should use the requested language too (fr-CA = default)'
989
    );
948
    );
990
949
991
    my $context = Test::MockModule->new('C4::Context');
992
    $context->mock( 'interface', 'intranet' );
993
994
    Koha::Cache::Memory::Lite->get_instance()->clear_from_cache('getlanguage');
995
    t::lib::Mocks::mock_preference( 'language', 'fr-CA,en' );
996
997
    $letter = C4::Letters::GetPreparedLetter(
950
    $letter = C4::Letters::GetPreparedLetter(
998
        module                 => 'test',
951
        module                 => 'test',
952
        tables                 => $tables,
999
        letter_code            => 'payment',
953
        letter_code            => 'payment',
1000
        message_transport_type => 'print',
954
        message_transport_type => 'print',
955
        substitute             => $substitute,
956
        lang                   => 'en',
957
    );
958
    is(
959
        $letter->{title}, 'English notice',
960
        'GetPreparedLetter should return the requested language notice if it exists (en != default)'
961
    );
962
    like(
963
        $letter->{content}, qr/Payment/,
964
        'Template includes should use the requested language too (en != default)'
965
    );
966
967
    $letter = C4::Letters::GetPreparedLetter(
968
        module                 => 'test',
1001
        tables                 => $tables,
969
        tables                 => $tables,
1002
        lang                   => 'default',
970
        letter_code            => 'payment',
971
        message_transport_type => 'print',
972
        substitute             => $substitute,
973
        lang                   => 'fr-FR',
974
    );
975
    is(
976
        $letter->{title},
977
        'Default notice',
978
        'GetPreparedLetter should return the default notice if the one requested language notice does not exist (default = fr-CA)'
979
    );
980
    like(
981
        $letter->{content}, qr/Paiement/,
982
        'Template includes should use the default language too if the requested language notice does not exist (default = fr-CA)'
1003
    );
983
    );
1004
    is( $letter->{title}, 'Default payment notice',
1005
        'GetPreparedLetter should return the notice in default language' );
1006
    like( $letter->{content}, qr/Paiement/, 'GetPreparedLetter should return the notice in the interface language' );
1007
984
1008
    $context->mock( 'interface', 'cron' );
985
    t::lib::Mocks::mock_preference( 'TranslateNotices', '' );
1009
986
1010
    $letter = C4::Letters::GetPreparedLetter(
987
    $letter = C4::Letters::GetPreparedLetter(
1011
        module                 => 'test',
988
        module                 => 'test',
989
        tables                 => $tables,
1012
        letter_code            => 'payment',
990
        letter_code            => 'payment',
1013
        message_transport_type => 'print',
991
        message_transport_type => 'print',
1014
        tables                 => $tables,
992
        substitute             => $substitute,
1015
        lang                   => 'default'
993
        lang                   => 'en',
994
    );
995
    is(
996
        $letter->{title}, 'Default notice',
997
        'GetPreparedLetter should return the default notice if pref disabled but additional language exists'
1016
    );
998
    );
1017
    is( $letter->{title}, 'Default payment notice',
1018
        'GetPreparedLetter should return the notice in default language' );
1019
    like(
999
    like(
1020
        $letter->{content}, qr/Paiement/,
1000
        $letter->{content}, qr/Paiement/,
1021
        'GetPreparedLetter should return the notice in the first language in language system preference'
1001
        'Template includes should use the default language if pref disabled but additional language exists (default = fr-CA)'
1022
    );
1002
    );
1023
};
1003
};
1024
1004
1025
- 

Return to bug 33237