|
Lines 19-26
use Modern::Perl;
Link Here
|
| 19 |
|
19 |
|
| 20 |
use File::Basename qw/basename/; |
20 |
use File::Basename qw/basename/; |
| 21 |
use Koha::Database; |
21 |
use Koha::Database; |
| 22 |
use Koha::IllbatchStatus; |
22 |
use Koha::ILL::Batch::Status; |
| 23 |
use Koha::IllbatchStatuses; |
23 |
use Koha::ILL::Batch::Statuses; |
| 24 |
use Koha::Patrons; |
24 |
use Koha::Patrons; |
| 25 |
use Koha::Libraries; |
25 |
use Koha::Libraries; |
| 26 |
use t::lib::Mocks; |
26 |
use t::lib::Mocks; |
|
Lines 32-43
use Test::More tests => 13;
Link Here
|
| 32 |
|
32 |
|
| 33 |
my $schema = Koha::Database->new->schema; |
33 |
my $schema = Koha::Database->new->schema; |
| 34 |
my $builder = t::lib::TestBuilder->new; |
34 |
my $builder = t::lib::TestBuilder->new; |
| 35 |
use_ok('Koha::IllbatchStatus'); |
35 |
use_ok('Koha::ILL::Batch::Status'); |
| 36 |
use_ok('Koha::IllbatchStatuses'); |
36 |
use_ok('Koha::ILL::Batch::Statuses'); |
| 37 |
|
37 |
|
| 38 |
$schema->storage->txn_begin; |
38 |
$schema->storage->txn_begin; |
| 39 |
|
39 |
|
| 40 |
Koha::IllbatchStatuses->search->delete; |
40 |
Koha::ILL::Batch::Statuses->search->delete; |
| 41 |
|
41 |
|
| 42 |
# Keep track of whether our CRUD logging side-effects are happening |
42 |
# Keep track of whether our CRUD logging side-effects are happening |
| 43 |
my $effects = { |
43 |
my $effects = { |
|
Lines 68-85
my $status = $builder->build(
Link Here
|
| 68 |
} |
68 |
} |
| 69 |
); |
69 |
); |
| 70 |
|
70 |
|
| 71 |
my $status_obj = Koha::IllbatchStatuses->find( { code => $status->{code} } ); |
71 |
my $status_obj = Koha::ILL::Batch::Statuses->find( { code => $status->{code} } ); |
| 72 |
isa_ok( $status_obj, 'Koha::IllbatchStatus' ); |
72 |
isa_ok( $status_obj, 'Koha::ILL::Batch::Status' ); |
| 73 |
|
73 |
|
| 74 |
# Try to delete the status, it's a system status, so this should fail |
74 |
# Try to delete the status, it's a system status, so this should fail |
| 75 |
$status_obj->delete_and_log; |
75 |
$status_obj->delete_and_log; |
| 76 |
my $status_obj_del = Koha::IllbatchStatuses->find( { code => $status->{code} } ); |
76 |
my $status_obj_del = Koha::ILL::Batch::Statuses->find( { code => $status->{code} } ); |
| 77 |
isa_ok( $status_obj_del, 'Koha::IllbatchStatus' ); |
77 |
isa_ok( $status_obj_del, 'Koha::ILL::Batch::Status' ); |
| 78 |
|
78 |
|
| 79 |
## Status create |
79 |
## Status create |
| 80 |
|
80 |
|
| 81 |
# Try creating a duplicate status |
81 |
# Try creating a duplicate status |
| 82 |
my $status2 = Koha::IllbatchStatus->new( |
82 |
my $status2 = Koha::ILL::Batch::Status->new( |
| 83 |
{ |
83 |
{ |
| 84 |
name => "Obi-wan", |
84 |
name => "Obi-wan", |
| 85 |
code => $status->{code}, |
85 |
code => $status->{code}, |
|
Lines 93-99
is_deeply(
Link Here
|
| 93 |
); |
93 |
); |
| 94 |
|
94 |
|
| 95 |
# Create a non-duplicate status and ensure that the logger is called |
95 |
# Create a non-duplicate status and ensure that the logger is called |
| 96 |
my $status3 = Koha::IllbatchStatus->new( |
96 |
my $status3 = Koha::ILL::Batch::Status->new( |
| 97 |
{ |
97 |
{ |
| 98 |
name => "Kylo", |
98 |
name => "Kylo", |
| 99 |
code => "DARK_SIDE", |
99 |
code => "DARK_SIDE", |
|
Lines 108-114
is(
Link Here
|
| 108 |
); |
108 |
); |
| 109 |
|
109 |
|
| 110 |
# Try creating a system status and ensure it's not created |
110 |
# Try creating a system status and ensure it's not created |
| 111 |
my $cannot_create_system = Koha::IllbatchStatus->new( |
111 |
my $cannot_create_system = Koha::ILL::Batch::Status->new( |
| 112 |
{ |
112 |
{ |
| 113 |
name => "Jar Jar Binks", |
113 |
name => "Jar Jar Binks", |
| 114 |
code => "GUNGAN", |
114 |
code => "GUNGAN", |
|
Lines 116-122
my $cannot_create_system = Koha::IllbatchStatus->new(
Link Here
|
| 116 |
} |
116 |
} |
| 117 |
); |
117 |
); |
| 118 |
$cannot_create_system->create_and_log; |
118 |
$cannot_create_system->create_and_log; |
| 119 |
my $created_but_not_system = Koha::IllbatchStatuses->find( { code => "GUNGAN" } ); |
119 |
my $created_but_not_system = Koha::ILL::Batch::Statuses->find( { code => "GUNGAN" } ); |
| 120 |
is( $created_but_not_system->{is_system}, undef, "is_system statuses cannot be created" ); |
120 |
is( $created_but_not_system->{is_system}, undef, "is_system statuses cannot be created" ); |
| 121 |
|
121 |
|
| 122 |
## Status update |
122 |
## Status update |
|
Lines 131-137
$status3->update_and_log(
Link Here
|
| 131 |
); |
131 |
); |
| 132 |
|
132 |
|
| 133 |
# Get our updated status, if we can get it by it's code, we know that hasn't changed |
133 |
# Get our updated status, if we can get it by it's code, we know that hasn't changed |
| 134 |
my $not_updated = Koha::IllbatchStatuses->find( { code => "DARK_SIDE" } )->unblessed; |
134 |
my $not_updated = Koha::ILL::Batch::Statuses->find( { code => "DARK_SIDE" } )->unblessed; |
| 135 |
is( $not_updated->{is_system}, 0, "is_system cannot be changed" ); |
135 |
is( $not_updated->{is_system}, 0, "is_system cannot be changed" ); |
| 136 |
is( $not_updated->{name}, "Rey", "name can be changed" ); |
136 |
is( $not_updated->{name}, "Rey", "name can be changed" ); |
| 137 |
|
137 |
|
|
Lines 143-156
is(
Link Here
|
| 143 |
); |
143 |
); |
| 144 |
|
144 |
|
| 145 |
## Status delete |
145 |
## Status delete |
| 146 |
my $cannot_delete = Koha::IllbatchStatus->new( |
146 |
my $cannot_delete = Koha::ILL::Batch::Status->new( |
| 147 |
{ |
147 |
{ |
| 148 |
name => "Palapatine", |
148 |
name => "Palapatine", |
| 149 |
code => "SITH", |
149 |
code => "SITH", |
| 150 |
is_system => 1 |
150 |
is_system => 1 |
| 151 |
} |
151 |
} |
| 152 |
)->store; |
152 |
)->store; |
| 153 |
my $can_delete = Koha::IllbatchStatus->new( |
153 |
my $can_delete = Koha::ILL::Batch::Status->new( |
| 154 |
{ |
154 |
{ |
| 155 |
name => "Windu", |
155 |
name => "Windu", |
| 156 |
code => "JEDI", |
156 |
code => "JEDI", |
|
Lines 158-165
my $can_delete = Koha::IllbatchStatus->new(
Link Here
|
| 158 |
} |
158 |
} |
| 159 |
); |
159 |
); |
| 160 |
$cannot_delete->delete_and_log; |
160 |
$cannot_delete->delete_and_log; |
| 161 |
my $not_deleted = Koha::IllbatchStatuses->find( { code => "SITH" } ); |
161 |
my $not_deleted = Koha::ILL::Batch::Statuses->find( { code => "SITH" } ); |
| 162 |
isa_ok( $not_deleted, 'Koha::IllbatchStatus', "is_system statuses cannot be deleted" ); |
162 |
isa_ok( $not_deleted, 'Koha::ILL::Batch::Status', "is_system statuses cannot be deleted" ); |
| 163 |
$can_delete->create_and_log; |
163 |
$can_delete->create_and_log; |
| 164 |
$can_delete->delete_and_log; |
164 |
$can_delete->delete_and_log; |
| 165 |
|
165 |
|
|
Lines 171-177
is(
Link Here
|
| 171 |
); |
171 |
); |
| 172 |
|
172 |
|
| 173 |
# Create a system "UNKNOWN" status |
173 |
# Create a system "UNKNOWN" status |
| 174 |
my $status_unknown = Koha::IllbatchStatus->new( |
174 |
my $status_unknown = Koha::ILL::Batch::Status->new( |
| 175 |
{ |
175 |
{ |
| 176 |
name => "Unknown", |
176 |
name => "Unknown", |
| 177 |
code => "UNKNOWN", |
177 |
code => "UNKNOWN", |
|
Lines 183-189
$status_unknown->create_and_log;
Link Here
|
| 183 |
# Create a batch and assign it a status |
183 |
# Create a batch and assign it a status |
| 184 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
184 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 185 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
185 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 186 |
my $status5 = Koha::IllbatchStatus->new( |
186 |
my $status5 = Koha::ILL::Batch::Status->new( |
| 187 |
{ |
187 |
{ |
| 188 |
name => "Plagueis", |
188 |
name => "Plagueis", |
| 189 |
code => "DEAD_SITH", |
189 |
code => "DEAD_SITH", |