|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
# Test script to verify IP address logging in action_logs |
| 4 |
# This script tests that the IP address is properly stored in action_logs |
| 5 |
|
| 6 |
use Modern::Perl; |
| 7 |
use Test::More tests => 5; |
| 8 |
|
| 9 |
use C4::Context; |
| 10 |
use C4::Log qw(logaction); |
| 11 |
use Koha::Database; |
| 12 |
use Koha::ActionLogs; |
| 13 |
use t::lib::TestBuilder; |
| 14 |
use t::lib::Mocks; |
| 15 |
|
| 16 |
my $schema = Koha::Database->new->schema; |
| 17 |
$schema->storage->txn_begin; |
| 18 |
|
| 19 |
my $builder = t::lib::TestBuilder->new; |
| 20 |
|
| 21 |
# Mock REMOTE_ADDR |
| 22 |
$ENV{REMOTE_ADDR} = '192.168.1.100'; |
| 23 |
|
| 24 |
# Clear any existing action logs for this test |
| 25 |
Koha::ActionLogs->search->delete; |
| 26 |
|
| 27 |
# Perform a test action log |
| 28 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 29 |
|
| 30 |
# Call logaction which should now capture the IP address |
| 31 |
logaction( "TESTING", "ADD", $patron->borrowernumber, "Test IP logging", "intranet" ); |
| 32 |
|
| 33 |
# Check that the action log was created with the IP address |
| 34 |
my $action_log = Koha::ActionLogs->search( { module => 'TESTING', action => 'ADD' } )->next; |
| 35 |
ok( $action_log, "Action log was created" ); |
| 36 |
is( $action_log->module, "TESTING", "Module is correct" ); |
| 37 |
is( $action_log->action, "ADD", "Action is correct" ); |
| 38 |
is( $action_log->info, "Test IP logging", "Info is correct" ); |
| 39 |
is( $action_log->ip_address, "192.168.1.100", "IP address was captured correctly" ); |
| 40 |
|
| 41 |
# Clean up |
| 42 |
$schema->storage->txn_rollback; |
| 43 |
|
| 44 |
done_testing(); |