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

(-)a/t/db_dependent/SIP/Message.t (-1 / +51 lines)
Lines 21-27 Link Here
21
# along with Koha; if not, see <http://www.gnu.org/licenses>.
21
# along with Koha; if not, see <http://www.gnu.org/licenses>.
22
22
23
use Modern::Perl;
23
use Modern::Perl;
24
use Test::More tests => 3;
24
use Test::More tests => 4;
25
use Test::MockObject;
25
use Test::MockObject;
26
use Test::MockModule;
26
use Test::MockModule;
27
use Test::Warn;
27
use Test::Warn;
Lines 73-78 subtest 'Checkin V2' => sub { Link Here
73
    $schema->storage->txn_rollback;
73
    $schema->storage->txn_rollback;
74
};
74
};
75
75
76
subtest 'Lastseen response' => sub {
77
78
    my $schema = Koha::Database->new->schema;
79
    $schema->storage->txn_begin;
80
81
    plan tests => 6;
82
    my $builder = t::lib::TestBuilder->new();
83
    my $branchcode = $builder->build({ source => 'Branch' })->{branchcode};
84
    my ( $response, $findpatron );
85
    my $mocks = create_mocks( \$response, \$findpatron, \$branchcode );
86
    my $seen_patron = $builder->build({
87
        source => 'Borrower',
88
        value  => {
89
            lastseen => '2001-01-01',
90
            password => hash_password( PATRON_PW ),
91
            branchcode => $branchcode,
92
        },
93
    });
94
    my $cardnum = $seen_patron->{cardnumber};
95
    my $sip_patron = C4::SIP::ILS::Patron->new( $cardnum );
96
    $findpatron = $sip_patron;
97
98
    my $siprequest = PATRON_INFO. 'engYYYYMMDDZZZZHHMMSS'.'Y         '.
99
        FID_INST_ID. $branchcode. '|'.
100
        FID_PATRON_ID. $cardnum. '|'.
101
        FID_PATRON_PWD. PATRON_PW. '|';
102
    my $msg = C4::SIP::Sip::MsgType->new( $siprequest, 0 );
103
104
    my $server = { ils => $mocks->{ils} };
105
    undef $response;
106
    t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '' );
107
    $msg->handle_patron_info( $server );
108
109
    isnt( $response, undef, 'At least we got a response.' );
110
    my $respcode = substr( $response, 0, 2 );
111
    is( $respcode, PATRON_INFO_RESP, 'Response code fine' );
112
    $seen_patron = Koha::Patrons->find({ cardnumber => $seen_patron->{cardnumber} });
113
    is( output_pref({str => $seen_patron->lastseen(), dateonly => 1}), output_pref({str => '2001-01-01', dateonly => 1}),'Last seen not updated if not tracking patrons');
114
    undef $response;
115
    t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '1' );
116
    $msg->handle_patron_info( $server );
117
118
    isnt( $response, undef, 'At least we got a response.' );
119
    $respcode = substr( $response, 0, 2 );
120
    is( $respcode, PATRON_INFO_RESP, 'Response code fine' );
121
    $seen_patron = Koha::Patrons->find({ cardnumber => $seen_patron->cardnumber() });
122
    is( output_pref({str => $seen_patron->lastseen(), dateonly => 1}), output_pref({dt => dt_from_string(), dateonly => 1}),'Last seen updated if tracking patrons');
123
    $schema->storage->txn_rollback;
124
125
};
76
# Here is room for some more subtests
126
# Here is room for some more subtests
77
127
78
# END of main code
128
# END of main code
(-)a/t/db_dependent/SIP/Patron.t (-2 / +27 lines)
Lines 4-12 Link Here
4
# This needs to be extended! Your help is appreciated..
4
# This needs to be extended! Your help is appreciated..
5
5
6
use Modern::Perl;
6
use Modern::Perl;
7
use Test::More tests => 3;
7
use Test::More tests => 4;
8
8
9
use Koha::Database;
9
use Koha::Database;
10
use Koha::Patrons;
11
use Koha::DateUtils;
10
use t::lib::TestBuilder;
12
use t::lib::TestBuilder;
11
use t::lib::Mocks;
13
use t::lib::Mocks;
12
use C4::SIP::ILS::Patron;
14
use C4::SIP::ILS::Patron;
Lines 72-75 subtest "OverduesBlockCirc tests" => sub { Link Here
72
74
73
};
75
};
74
76
77
subtest "update_lastseen tests" => sub {
78
    plan tests => 2;
79
80
    my $seen_patron = $builder->build(
81
        {
82
            source => 'Borrower',
83
            value  => {
84
                lastseen    => "2001-01-01",
85
            }
86
        }
87
    );
88
    my $sip_patron = C4::SIP::ILS::Patron->new( $seen_patron->{cardnumber} );
89
    t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '' );
90
    $sip_patron->update_lastseen();
91
    $seen_patron = Koha::Patrons->find({ cardnumber => $seen_patron->{cardnumber} });
92
    is( output_pref({str => $seen_patron->lastseen(), dateonly => 1}), output_pref({str => '2001-01-01', dateonly => 1}),'Last seen not updated if not tracking patrons');
93
    t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '1' );
94
    $sip_patron->update_lastseen();
95
    $seen_patron = Koha::Patrons->find({ cardnumber => $seen_patron->cardnumber() });
96
    is( output_pref({str => $seen_patron->lastseen(), dateonly => 1}), output_pref({dt => dt_from_string(), dateonly => 1}),'Last seen updated to today if tracking patrons');
97
98
99
};
100
75
$schema->storage->txn_rollback;
101
$schema->storage->txn_rollback;
76
- 

Return to bug 18625