3 # This test is db dependent: SIPServer needs MsgType which needs Auth.
4 # And Auth needs config vars and prefences in its BEGIN block.
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
23 use Test
::More tests
=> 1;
26 my ( $mockConfig, $mockPrefork );
29 # In order to test SIPServer::get_timeout, we need to mock
30 # Configuration->new and PreFork->run.
32 use C4
::SIP
::Sip
::Configuration
;
33 $mockConfig = Test
::MockModule
->new( 'C4::SIP::Sip::Configuration' );
34 $mockConfig->mock( 'new', sub { return {}; } );
35 use Net
::Server
::PreFork
;
36 $mockPrefork = Test
::MockModule
->new( 'Net::Server::PreFork' );
37 $mockPrefork->mock( 'run', sub {} );
40 use C4
::SIP
::SIPServer
;
43 # TODO We should include more tests here.
45 subtest
'Get_timeout' => sub {
48 my $server = { policy
=> { timeout
=> 1 },
49 config
=> { timeout
=> 2 },
56 is
( C4
::SIP
::SIPServer
::get_timeout
(), 30, "Default fallback" );
57 is
( C4
::SIP
::SIPServer
::get_timeout
( undef, { fallback
=> 25 } ), 25, "Fallback parameter" );
58 is
( C4
::SIP
::SIPServer
::get_timeout
( $server, { transport
=> 1 } ), 3, "Transport value" );
59 is
( C4
::SIP
::SIPServer
::get_timeout
( $server, { client
=> 1 } ), 4, "Client value" );
60 is
( C4
::SIP
::SIPServer
::get_timeout
( $server, { policy
=> 1 } ), '001', "Policy value" );
62 delete $server->{policy
}->{timeout
};
63 is
( C4
::SIP
::SIPServer
::get_timeout
( $server, { policy
=> 1 } ), '000', "No policy" );
65 $server->{service
}->{client_timeout
} = '0';
66 is
( C4
::SIP
::SIPServer
::get_timeout
( $server, { client
=> 1 } ), 0, "Client zero" );
67 $server->{service
}->{client_timeout
} = 'no';
68 is
( C4
::SIP
::SIPServer
::get_timeout
( $server, { client
=> 1 } ), 0, "Client no" );
69 delete $server->{service
}->{client_timeout
};
70 is
( C4
::SIP
::SIPServer
::get_timeout
( $server, { client
=> 1 } ), 3, "Fallback to service" );
72 delete $server->{service
}->{timeout
};
73 is
( C4
::SIP
::SIPServer
::get_timeout
( $server, { transport
=> 1 } ), 2, "Back to old config" );
74 delete $server->{config
}->{timeout
};
75 is
( C4
::SIP
::SIPServer
::get_timeout
( $server, { transport
=> 1 } ), 30, "Fallback again" );