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

(-)a/t/db_dependent/Koha/Item.t (-2 / +139 lines)
Lines 21-27 use Modern::Perl; Link Here
21
use utf8;
21
use utf8;
22
22
23
use Test::NoWarnings;
23
use Test::NoWarnings;
24
use Test::More tests => 39;
24
use Test::More tests => 40;
25
use Test::Exception;
25
use Test::Exception;
26
use Test::MockModule;
26
use Test::MockModule;
27
use Test::Warn;
27
use Test::Warn;
Lines 46-51 use t::lib::Dates; Link Here
46
my $schema  = Koha::Database->new->schema;
46
my $schema  = Koha::Database->new->schema;
47
my $builder = t::lib::TestBuilder->new;
47
my $builder = t::lib::TestBuilder->new;
48
48
49
subtest '_status' => sub {
50
    plan tests => 12;
51
52
    $schema->storage->txn_begin;
53
54
    my $item    = $builder->build_sample_item();
55
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
56
    t::lib::Mocks::mock_userenv( { branchcode => $library->branchcode } );
57
58
    t::lib::Mocks::mock_preference( 'UseRecalls', 1 );
59
60
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
61
62
    my @test_cases = (
63
        {
64
            setup => sub {
65
                my $onloan_item = $builder->build_sample_item();
66
                AddIssue( $patron, $onloan_item->barcode, dt_from_string );
67
                return $onloan_item;
68
            },
69
            expected_status => 'checked_out',
70
            description     => 'Checked out status correctly returned',
71
        },
72
        {
73
            setup => sub {
74
                my $onsite_item = $builder->build_sample_item();
75
                AddIssue(
76
                    $patron, $onsite_item->barcode, dt_from_string, undef, undef, undef,
77
                    { onsite_checkout => 1 }
78
                );
79
                return $onsite_item;
80
            },
81
            expected_status => 'local_use',
82
            description     => 'Local use status correctly returned',
83
        },
84
        {
85
            setup => sub {
86
                return $item;
87
            },
88
            expected_status => 'available',
89
            description     => 'Available status correctly returned',
90
        },
91
        {
92
            setup => sub {
93
                $item->itemlost(1)->store();
94
                return $item;
95
            },
96
            expected_status => 'lost',
97
            description     => 'Lost status correctly returned',
98
        },
99
        {
100
            setup => sub {
101
                $item->withdrawn(1)->store();
102
                return $item;
103
            },
104
            expected_status => qr/lost,withdrawn/,
105
            description     => 'Lost and withdrawn status correctly returned',
106
        },
107
        {
108
            setup => sub {
109
                $item->damaged(1)->store();
110
                return $item;
111
            },
112
            expected_status => qr/lost,withdrawn,damaged/,
113
            description     => 'Lost, withdrawn, and damaged status correctly returned',
114
        },
115
        {
116
            setup => sub {
117
                $item->notforloan(1)->store();
118
                return $item;
119
            },
120
            expected_status => 'not_for_loan',
121
            description     => 'Positive not_for_loan status correctly returned',
122
        },
123
        {
124
            setup => sub {
125
                $item->notforloan(-1)->store();
126
                return $item;
127
            },
128
            expected_status => 'not_for_loan',
129
            description     => 'Negative not_for_loan status correctly returned',
130
        },
131
        {
132
            setup => sub {
133
                my $itemtype = $builder->build_object( { class => "Koha::ItemTypes", value => { notforloan => 1 } } );
134
                my $notforloan_item = $builder->build_sample_item( { itype => $itemtype->itemtype, } );
135
                return $notforloan_item;
136
            },
137
            expected_status => 'not_for_loan',
138
            description     => 'Item type not_for_loan status correctly returned',
139
        },
140
        {
141
            setup => sub {
142
                my $onhold_item = $builder->build_sample_item();
143
                C4::Reserves::AddReserve(
144
                    {
145
                        branchcode     => $library->branchcode,
146
                        borrowernumber => $patron->borrowernumber,
147
                        biblionumber   => $onhold_item->biblionumber,
148
                        itemnumber     => $onhold_item->itemnumber,
149
                    }
150
                );
151
                return $onhold_item;
152
            },
153
            expected_status => 'on_hold',
154
            description     => 'On hold status correctly returned',
155
        },
156
        {
157
            setup => sub {
158
                my $recalled_item = $builder->build_sample_item();
159
                AddIssue( $patron, $recalled_item->barcode, dt_from_string );
160
                Koha::Recalls->add_recall(
161
                    { biblio => $recalled_item->biblio, item => $recalled_item, patron => $patron } );
162
                return $recalled_item;
163
            },
164
            expected_status => 'recalled',
165
            description     => 'Recalled status correctly returned',
166
        },
167
        {
168
            setup => sub {
169
                $item->restricted(1)->store();
170
                return $item;
171
            },
172
            expected_status => 'restricted',
173
            description     => 'Restricted status correctly returned',
174
        },
175
    );
176
177
    foreach my $test_case (@test_cases) {
178
        my $item = $test_case->{setup}->();
179
        ok( $item->_status() =~ /$test_case->{expected_status}/, $test_case->{description} );
180
    }
181
182
    t::lib::Mocks::mock_preference( 'UseRecalls', 0 );
183
184
    $schema->storage->txn_rollback;
185
};
186
49
subtest 'z3950_status' => sub {
187
subtest 'z3950_status' => sub {
50
    plan tests => 9;
188
    plan tests => 9;
51
189
52
- 

Return to bug 37334