Bug 37893: Add tests: DB changes get picked up by get_configuration without a server restart

prove t/db_dependent/Koha/SIP2/SIP2ModuleMigration.t

Test plan for the whole module:
[MODULE UI TESTING]
1) Checkout the branch and reset_all
2) Run 'updatedatabase'. The contents from
   /etc/koha/sites/kohadev/SIPConfig.xml have been migrated to the
database and should be accessible in the UI.
3) Visit the administration page:
   http://localhost:8081/cgi-bin/koha/admin/admin-home.pl
4) Notice the new 'Self-service circulation (SIP2)' item under 'Patrons
   and circulation'. Click it.
5) Notice you are now on the new SIP2 module. Create some institutions,
   accounts, listeners, etc. Play around with the forms.
6) Confirm all the data has been migrated correctly, and is editable in
   the UI as expected.

[SIP TESTING]
1) On ktd, run the following SIP emulator command:
$ perl misc/sip_cli_emulator.pl -su koha -sp koha -l kohalibrary --host localhost --patron 42 -m patron_information
2) Note that the response message contains 'Greetings from Koha'.
3) Using the module UI, visit SIP accounts:
   http://localhost:8081/cgi-bin/koha/sip2/accounts
4) Find the SIP account that has 'koha' as login. Click edit.
5) Scroll down to 'SIP response mappings' and click 'Add new screen msg regex'.
6) On 'Find', enter 'Greetings from Koha'. On 'Replace', enter 'Hello from 37893 test plan'. Save.
7) Repeat the sip command from 1). Note that 'Greetings from Koha has been replaced with 'Hello from 37893 test plan', without having to restart the SIP server.

[OPTIONAL]
1) You can repeat the previous steps in [MODULE UI TESTING] but edit the contents of
   /etc/koha/sites/kohadev/SIPConfig.xml beforehand with a more complex and
thorough configuration (something resembling a real SIPConfig.xml)
2) After updating the contents of SIPConfig.xml, restart SIP:
koha-sip --restart
3) Test the module again, verify the contents have been migrated as
    expected.

Signed-off-by: Andrew Fuerste Henry <andrew@bywatersolutions.com>
Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Pedro Amorim 2025-05-08 13:34:31 +00:00 committed by Lucas Gass
parent b1c964db86
commit c01f870d7e
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
1 changed files with 84 additions and 1 deletions

View File

@ -17,7 +17,9 @@
use Modern::Perl;
use Test::More tests => 1;
use Test::More tests => 2;
use t::lib::TestBuilder;
use C4::Installer;
use C4::SIP::Sip::Configuration;
@ -78,3 +80,84 @@ subtest 'Config from XML matches config from database' => sub {
$schema->storage->txn_rollback;
};
subtest 'config_timestamp is updated when database configuration changes' => sub {
plan tests => 3;
my $schema = Koha::Database->new->schema;
$schema->storage->txn_begin;
Koha::SIP2::Institutions->delete;
Koha::SIP2::Accounts->delete;
Koha::SIP2::Listeners->delete;
Koha::SIP2::ServerParams->delete;
Koha::SIP2::SystemPreferenceOverrides->delete;
my $builder = t::lib::TestBuilder->new();
my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode};
my ( $response, $findpatron );
my $seen_patron = $builder->build_object(
{
class => 'Koha::Patrons',
value => {
branchcode => $branchcode,
password => '123456',
},
}
)->store();
Koha::SIP2::Institutions->search()->delete;
my $sip_institution = $builder->build_object(
{
class => 'Koha::SIP2::Institutions',
value => {
name => 'CPL',
implementation => 'ILS',
retries => 5,
status_update => 0,
timeout => 25,
},
}
)->store();
my $sip_account = $builder->build_object(
{
class => 'Koha::SIP2::Accounts',
value => {
login_id => $seen_patron->userid,
login_password => '123456',
sip_institution_id => $sip_institution->sip_institution_id,
allow_fields => '',
hide_fields => '',
},
}
)->store();
my $cfg = C4::SIP::Sip::Configuration->get_configuration();
is(
$cfg->{accounts}->{ $sip_account->login_id }->{allow_fields}, '',
'$cfg->{accounts}->{$sip_account->login_id}->{allow_fields} is empty'
);
my $original_timestamp = Koha::SIP2::ServerParams->find( { key => 'config_timestamp' } );
sleep 1;
$sip_account->allow_fields('AB')->store();
my $new_cfg = C4::SIP::Sip::Configuration->get_configuration();
my $last_timestamp = Koha::SIP2::ServerParams->find( { key => 'config_timestamp' } );
isnt(
$original_timestamp->value, $last_timestamp->value,
'config_timestamp should be updated when database configuration changes'
);
is(
$cfg->{accounts}->{ $sip_account->login_id }->{allow_fields}, $sip_account->allow_fields,
'$cfg->{accounts}->{$sip_account->login_id}->{allow_fields} should now return the new value'
);
$schema->storage->txn_rollback;
};