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

(-)a/t/db_dependent/Koha/ILL/Requests.t (-2 / +129 lines)
Lines 22-27 use File::Basename qw/basename/; Link Here
22
use C4::Circulation qw( AddIssue AddReturn );
22
use C4::Circulation qw( AddIssue AddReturn );
23
23
24
use Koha::Database;
24
use Koha::Database;
25
use Koha::DateUtils qw( dt_from_string );
25
use Koha::ILL::Request::Attributes;
26
use Koha::ILL::Request::Attributes;
26
use Koha::ILL::Request::Config;
27
use Koha::ILL::Request::Config;
27
use Koha::Biblios;
28
use Koha::Biblios;
Lines 860-866 subtest 'Backend testing (mocks)' => sub { Link Here
860
861
861
subtest 'Backend core methods' => sub {
862
subtest 'Backend core methods' => sub {
862
863
863
    plan tests => 20;
864
    plan tests => 28;
864
865
865
    $schema->storage->txn_begin;
866
    $schema->storage->txn_begin;
866
867
Lines 994-999 subtest 'Backend core methods' => sub { Link Here
994
        "Backend create: commit stage, permitted, ILLModuleUnmediated disabled."
995
        "Backend create: commit stage, permitted, ILLModuleUnmediated disabled."
995
    );
996
    );
996
997
998
    # Test backend_create with ILLModuleCopyrightClearance
999
    $backend->mock(
1000
        'create',
1001
        sub {
1002
            my ( $self, $params ) = @_;
1003
            my $request = $params->{request};
1004
            $request->branchcode( $params->{other}->{branchcode} );
1005
            $request->store;
1006
            return {
1007
                method => 'create',
1008
                stage  => 'commit',
1009
            };
1010
        }
1011
    );
1012
1013
    Koha::AdditionalContents->search->delete;
1014
    my $tomorrow  = dt_from_string->add( days => 1 );
1015
    my $yesterday = dt_from_string->add( days => -1 );
1016
1017
    my $library_additional_contents = $builder->build_object(
1018
        {
1019
            class => 'Koha::AdditionalContents',
1020
            value => {
1021
                expirationdate => $tomorrow,
1022
                published_on   => $yesterday,
1023
                category       => 'html_customizations',
1024
                location       => 'ILLModuleCopyrightClearance',
1025
                branchcode     => $illrq->patron->branchcode,
1026
            }
1027
        }
1028
    );
1029
    $library_additional_contents->translated_contents(
1030
        [
1031
            {
1032
                lang    => 'default',
1033
                content => '1',
1034
            }
1035
        ]
1036
    );
1037
    my $branchcode_before_create = $illrq->branchcode;
1038
    my $another_library          = $builder->build_object( { class => 'Koha::Libraries' } );
1039
    my $backend_create_result    = $illrq->backend_create(
1040
        {
1041
            stage      => 'form', op => 'cud-create', opac => 1, branchcode => $another_library->branchcode,
1042
            cardnumber => $illrq->patron->cardnumber
1043
        }
1044
    );
1045
    is( $illrq->branchcode, $another_library->branchcode, "Branchcode is the provided branchcode" );
1046
1047
    my $copyright_content = Koha::AdditionalContents->search_for_display(
1048
        {
1049
            category   => 'html_customizations',
1050
            location   => ['ILLModuleCopyrightClearance'],
1051
            lang       => 'default',
1052
            library_id => $illrq->patron->branchcode,
1053
        }
1054
    );
1055
    is( $copyright_content->count, 1 );
1056
1057
    $backend_create_result =
1058
        $illrq->backend_create(
1059
        { opac => 1, branchcode => $illrq->patron->branchcode, cardnumber => $illrq->patron->cardnumber } );
1060
    is(
1061
        $backend_create_result->{stage}, 'copyrightclearance',
1062
        'Additional contents found for provided cardnumber\'s library, should be copyrightclearance stage'
1063
    );
1064
1065
    $backend_create_result = $illrq->backend_create( { opac => 1, branchcode => $illrq->patron->branchcode } );
1066
    is(
1067
        $backend_create_result->{stage}, 'commit',
1068
        'Cardnumber not supplied and couldnt find additional_contents for all libraries. Dont show copyrightclearance'
1069
    );
1070
1071
    my $patron_1 = $builder->build_object( { class => 'Koha::Patrons' } );
1072
    $backend_create_result = $illrq->backend_create( { opac => 1, branchcode => $patron_1->branchcode } );
1073
    is(
1074
        $backend_create_result->{stage}, 'commit',
1075
        'Supplied cardnumber\'s branchcode doesnt match any additional_contents of same branchcode. Dont show copyrightclearance'
1076
    );
1077
1078
    my $all_libraries_copyright_content = Koha::AdditionalContents->search_for_display(
1079
        {
1080
            category   => 'html_customizations',
1081
            location   => ['ILLModuleCopyrightClearance'],
1082
            lang       => 'default',
1083
            library_id => $another_library->branchcode,
1084
        }
1085
    );
1086
    is( $all_libraries_copyright_content->count, 0 );
1087
1088
    my $all_libraries_additional_contents = $builder->build_object(
1089
        {
1090
            class => 'Koha::AdditionalContents',
1091
            value => {
1092
                expirationdate => $tomorrow,
1093
                published_on   => $yesterday,
1094
                category       => 'html_customizations',
1095
                location       => 'ILLModuleCopyrightClearance',
1096
                branchcode     => undef,
1097
            }
1098
        }
1099
    );
1100
    $all_libraries_additional_contents->translated_contents(
1101
        [
1102
            {
1103
                lang    => 'default',
1104
                content => '1',
1105
            }
1106
        ]
1107
    );
1108
1109
    $backend_create_result = $illrq->backend_create( { opac => 1, branchcode => $illrq->patron->branchcode } );
1110
    is(
1111
        $backend_create_result->{stage}, 'copyrightclearance',
1112
        'Cardnumber not supplied, found additional_contents for all libraries. Should show copyrightclearance'
1113
    );
1114
1115
    $all_libraries_copyright_content = Koha::AdditionalContents->search_for_display(
1116
        {
1117
            category   => 'html_customizations',
1118
            location   => ['ILLModuleCopyrightClearance'],
1119
            lang       => 'default',
1120
            library_id => $another_library->branchcode,
1121
        }
1122
    );
1123
    is( $all_libraries_copyright_content->count, 1 );
1124
997
    # backend_renew
1125
    # backend_renew
998
    $backend->set_series( 'renew', { stage => 'bar', method => 'renew' } );
1126
    $backend->set_series( 'renew', { stage => 'bar', method => 'renew' } );
999
    is_deeply(
1127
    is_deeply(
1000
- 

Return to bug 41237