Lines 44-49
use t::lib::Dates;
Link Here
|
44 |
my $schema = Koha::Database->new->schema; |
44 |
my $schema = Koha::Database->new->schema; |
45 |
my $builder = t::lib::TestBuilder->new; |
45 |
my $builder = t::lib::TestBuilder->new; |
46 |
|
46 |
|
|
|
47 |
subtest 'z3950_status' => sub { |
48 |
plan tests => 9; |
49 |
|
50 |
$schema->storage->txn_begin; |
51 |
t::lib::Mocks::mock_preference( 'z3950Status', '' ); |
52 |
|
53 |
my $itemtype = $builder->build_object( { class => "Koha::ItemTypes" } ); |
54 |
my $item = $builder->build_sample_item( |
55 |
{ |
56 |
itype => $itemtype->itemtype, |
57 |
} |
58 |
); |
59 |
|
60 |
my $statuses = $item->z3950_status(); |
61 |
is( scalar @{$statuses}, 0, "No statuses set when pref blank and item has no status" ); |
62 |
|
63 |
$item->onloan('2001-01-01')->store(); |
64 |
$statuses = $item->z3950_status(); |
65 |
is_deeply( $statuses, ['CHECKED_OUT'], "Item status is checked out when onloan is set" ); |
66 |
|
67 |
$item->damaged(1)->withdrawn(1)->itemlost(1)->store(); |
68 |
$statuses = $item->z3950_status(); |
69 |
is_deeply( |
70 |
$statuses, [ 'CHECKED_OUT', 'LOST', 'DAMAGED', 'WITHDRAWN' ], |
71 |
"Multiple item statuses set from other fields" |
72 |
); |
73 |
|
74 |
$itemtype->notforloan(1)->store(); |
75 |
$statuses = $item->z3950_status(); |
76 |
is_deeply( |
77 |
$statuses, [ 'CHECKED_OUT', 'LOST', 'NOT_FOR_LOAN', 'DAMAGED', 'WITHDRAWN' ], |
78 |
"Not for loan status correctly added from itemtype" |
79 |
); |
80 |
|
81 |
$statuses = $item->z3950_status( { LOST => 'Gone', 'WITHDRAWN' => 'Weeded' } ); |
82 |
is_deeply( |
83 |
$statuses, [ 'CHECKED_OUT', 'Gone', 'NOT_FOR_LOAN', 'DAMAGED', 'Weeded' ], |
84 |
"Lost items correctly substituted when values passed" |
85 |
); |
86 |
|
87 |
$builder->build_object( |
88 |
{ class => 'Koha::Item::Transfers', value => { itemnumber => $item->itemnumber, datesent => '1999-12-31' } } ); |
89 |
$builder->build_object( { class => 'Koha::Holds', value => { itemnumber => $item->itemnumber, found => 'W' } } ); |
90 |
|
91 |
$statuses = $item->z3950_status( { LOST => 'Gone', 'WITHDRAWN' => 'Weeded', 'ON_HOLD' => 'Patron awaits' } ); |
92 |
is_deeply( |
93 |
$statuses, [ 'CHECKED_OUT', 'Gone', 'NOT_FOR_LOAN', 'DAMAGED', 'Weeded', 'IN_TRANSIT', 'Patron awaits' ], |
94 |
"Hold and transit statuses applied correctly" |
95 |
); |
96 |
|
97 |
t::lib::Mocks::mock_preference( 'z3950Status', "homebranch: [" . $item->homebranch . "]" ); |
98 |
$statuses = $item->z3950_status( { LOST => 'Gone', 'WITHDRAWN' => 'Weeded', 'ON_HOLD' => 'Patron awaits' } ); |
99 |
is_deeply( |
100 |
$statuses, |
101 |
[ 'CHECKED_OUT', 'Gone', 'NOT_FOR_LOAN', 'DAMAGED', 'Weeded', 'IN_TRANSIT', 'Patron awaits', 'SYSPREF' ], |
102 |
"System preference statuses applied correctly" |
103 |
); |
104 |
|
105 |
my $item_2 = $builder->build_sample_item( |
106 |
{ |
107 |
homebranch => $item->homebranch, |
108 |
} |
109 |
); |
110 |
|
111 |
$statuses = $item_2->z3950_status( |
112 |
{ |
113 |
LOST => 'Gone', 'WITHDRAWN' => 'Weeded', 'ON_HOLD' => 'Patron awaits', |
114 |
'SYSPREF' => 'Library policy forbids' |
115 |
} |
116 |
); |
117 |
is_deeply( $statuses, ['Library policy forbids'], "system preference statuses substituted correctly" ); |
118 |
|
119 |
t::lib::Mocks::mock_preference( 'z3950Status', "ccode: [FAKE]\r\n\nhomebranch: [" . $item->homebranch . "]" ); |
120 |
$statuses = $item_2->z3950_status( |
121 |
{ |
122 |
LOST => 'Gone', 'WITHDRAWN' => 'Weeded', 'ON_HOLD' => 'Patron awaits', |
123 |
'SYSPREF' => 'Library policy forbids' |
124 |
} |
125 |
); |
126 |
is_deeply( $statuses, ['Library policy forbids'], "Status applied when any field matches" ); |
127 |
|
128 |
$schema->storage->txn_rollback; |
129 |
}; |
130 |
|
47 |
subtest 'return_claims relationship' => sub { |
131 |
subtest 'return_claims relationship' => sub { |
48 |
plan tests => 3; |
132 |
plan tests => 3; |
49 |
|
133 |
|
50 |
- |
|
|