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

(-)a/t/Koha/Z3950responder.t (+32 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
use Test::More tests => 8;
5
6
BEGIN {
7
    use_ok('Koha::Z3950Responder');
8
}
9
10
my $zR = Koha::Z3950Responder->new({});
11
12
my $args={ PEER_NAME => 'PEER'};
13
$zR->init_handler($args);
14
is ( $args->{IMP_NAME}, 'Koha',"Server returns basic info");
15
$args->{DATABASES} = ['biblios'];
16
$args->{QUERY} = 'biblios';
17
$args->{SETNAME} = 'biblios';
18
$args->{START} = 0;
19
$args->{OFFSET} = 0;
20
$args->{NUMBER} = 42;
21
$zR->search_handler( $args );
22
is ( $args->{ERR_CODE}, 2, "We didn't start server , should fail");
23
is ( $args->{ERR_STR}, 'Cannot connect to upstream server', "We didn't start server, should fail because it cannot connect");
24
$zR->present_handler( $args );
25
is ( $args->{ERR_CODE}, 30, "There is no handler as we aren't connected");
26
is ( $args->{ERR_STR}, 'No such resultset', "We don't have a handler, should fail because we don't");
27
my $arg_check = ( $args );
28
$zR->fetch_handler( $args );
29
is_deeply( $args, $arg_check, "nothing should change");
30
$zR->close_handler( $args );
31
is_deeply( $args, $arg_check, "nothing should change");
32
(-)a/t/db_dependent/Koha/Z3950Responder/Session.t (+71 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
use Test::More tests => 3;
5
use t::lib::TestBuilder;
6
use C4::Items;
7
8
BEGIN {
9
    use_ok('Koha::Z3950Responder');
10
    use_ok('Koha::Z3950Responder::Session');
11
}
12
13
my $builder = t::lib::TestBuilder->new;
14
my $schema  = Koha::Database->new->schema;
15
16
$schema->storage->txn_begin;
17
18
subtest 'add_item_status' => sub {
19
20
    plan tests => 2;
21
22
    # Make sure we are using default values set in code
23
    $builder->schema->resultset( 'AuthorisedValue' )->delete_all;
24
25
    ## FIRST ITEM HAS ALL THE STATUSES ##
26
    my $item_1 = $builder->build({
27
        source => 'Item',
28
        value => {
29
            onloan => '2017-07-07',
30
            itemlost => 1,
31
            notforloan => 1,
32
            damaged => 1,
33
            withdrawn => 1,
34
        }
35
    });
36
    my $item_marc_1 = C4::Items::GetMarcItem( $item_1->{biblionumber}, $item_1->{itemnumber} );
37
    my $item_field_1 = scalar $item_marc_1->field('952');
38
    $builder->build({ source => 'Reserve', value=> { itemnumber => $item_1->{itemnumber} } });
39
    $builder->build({ source => 'Branchtransfer', value=> { itemnumber => $item_1->{itemnumber}, datearrived => undef } });
40
    ## END FIRST ITEM ##
41
42
    ## SECOND ITEM HAS NO STATUSES ##
43
    my $item_2 = $builder->build({
44
        source => 'Item',
45
        value => {
46
            onloan => undef,
47
            itemlost => 0,
48
            notforloan => 0,
49
            damaged => 0,
50
            withdrawn => 0,
51
        }
52
    });
53
    my $item_marc_2 = C4::Items::GetMarcItem( $item_2->{biblionumber}, $item_2->{itemnumber} );
54
    my $item_field_2 = scalar $item_marc_2->field('952');
55
    ## END SECOND ITEM ##
56
57
    # Create the responder
58
    my $args={ PEER_NAME => 'PEER'};
59
    my $zR = Koha::Z3950Responder->new({add_item_status_subfield => 'k'});
60
    $zR->init_handler($args);
61
62
    $args->{HANDLE}->add_item_status($item_field_1);
63
    is($item_field_1->subfield('k'),"Checked Out, Lost, Not for Loan, Damaged, Withdrawn, In Transit, On Hold","All statuses added in one field as expected");
64
65
    $args->{HANDLE}->add_item_status($item_field_2);
66
    is($item_field_2->subfield('k'),'Available',"Available status added as expected");
67
68
};
69
70
$schema->storage->txn_rollback;
71
(-)a/t/db_dependent/Koha/Z3950Responder/Session2.t (-1 / +87 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
use Test::More tests => 3;
5
use t::lib::TestBuilder;
6
use C4::Items;
7
8
BEGIN {
9
    use_ok('Koha::Z3950Responder');
10
    use_ok('Koha::Z3950Responder::Session');
11
}
12
13
my $builder = t::lib::TestBuilder->new;
14
my $schema  = Koha::Database->new->schema;
15
16
$schema->storage->txn_begin;
17
18
subtest 'add_item_status' => sub {
19
20
    plan tests => 2;
21
22
    # This time we are sustituting some values
23
    $builder->schema->resultset( 'AuthorisedValue' )->delete_all;
24
    $builder->build({
25
        source => 'AuthorisedValue',
26
        value => {
27
            category => 'Z3950_STATUS',
28
            authorised_value => 'AVAILABLE',
29
            lib => "Free as a bird"
30
        }
31
    });
32
    $builder->build({
33
        source => 'AuthorisedValue',
34
        value => {
35
            category => 'Z3950_STATUS',
36
            authorised_value => 'DAMAGED',
37
            lib => "Borked completely"
38
        }
39
    });
40
41
    ## FIRST ITEM HAS ALL THE STATUSES ##
42
    my $item_1 = $builder->build({
43
        source => 'Item',
44
        value => {
45
            onloan => '2017-07-07',
46
            itemlost => 1,
47
            notforloan => 1,
48
            damaged => 1,
49
            withdrawn => 1,
50
        }
51
    });
52
    my $item_marc_1 = C4::Items::GetMarcItem( $item_1->{biblionumber}, $item_1->{itemnumber} );
53
    my $item_field_1 = scalar $item_marc_1->field('952');
54
    $builder->build({ source => 'Reserve', value=> { itemnumber => $item_1->{itemnumber} } });
55
    $builder->build({ source => 'Branchtransfer', value=> { itemnumber => $item_1->{itemnumber}, datearrived => undef } });
56
    ## END FIRST ITEM ##
57
58
    ## SECOND ITEM HAS NO STATUSES ##
59
    my $item_2 = $builder->build({
60
        source => 'Item',
61
        value => {
62
            onloan => undef,
63
            itemlost => 0,
64
            notforloan => 0,
65
            damaged => 0,
66
            withdrawn => 0,
67
        }
68
    });
69
    my $item_marc_2 = C4::Items::GetMarcItem( $item_2->{biblionumber}, $item_2->{itemnumber} );
70
    my $item_field_2 = scalar $item_marc_2->field('952');
71
    ## END SECOND ITEM ##
72
73
    # Create the responder
74
    my $args={ PEER_NAME => 'PEER'};
75
    my $zR = Koha::Z3950Responder->new({add_item_status_subfield => 'k'});
76
    $zR->init_handler($args);
77
78
    $args->{HANDLE}->add_item_status($item_field_1);
79
    is($item_field_1->subfield('k'),"Checked Out, Lost, Not for Loan, Borked completely, Withdrawn, In Transit, On Hold","All statuses added in one field as expected");
80
81
    $args->{HANDLE}->add_item_status($item_field_2);
82
    is($item_field_2->subfield('k'),'Free as a bird',"Available status is 'Free as a bird' added as expected");
83
84
};
85
86
$schema->storage->txn_rollback;
87

Return to bug 13937