|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 2; |
22 |
use Test::More tests => 4; |
| 23 |
|
23 |
|
| 24 |
use Test::Exception; |
24 |
use Test::Exception; |
| 25 |
|
25 |
|
|
Lines 54-59
subtest 'library' => sub {
Link Here
|
| 54 |
$schema->storage->txn_rollback; |
54 |
$schema->storage->txn_rollback; |
| 55 |
}; |
55 |
}; |
| 56 |
|
56 |
|
|
|
57 |
subtest 'accountlines' => sub { |
| 58 |
plan tests => 3; |
| 59 |
|
| 60 |
$schema->storage->txn_begin; |
| 61 |
|
| 62 |
my $register = |
| 63 |
$builder->build_object( { class => 'Koha::Cash::Registers' } ); |
| 64 |
my $accountline1 = $builder->build_object( |
| 65 |
{ |
| 66 |
class => 'Koha::Account::Lines', |
| 67 |
value => { register_id => $register->id }, |
| 68 |
} |
| 69 |
); |
| 70 |
my $accountline2 = $builder->build_object( |
| 71 |
{ |
| 72 |
class => 'Koha::Account::Lines', |
| 73 |
value => { register_id => $register->id }, |
| 74 |
} |
| 75 |
); |
| 76 |
|
| 77 |
my $accountlines = $register->accountlines; |
| 78 |
is( ref($accountlines), 'Koha::Account::Lines', |
| 79 |
'Koha::Cash::Register->accountlines should return a set of Koha::Account::Lines' |
| 80 |
); |
| 81 |
is( $accountlines->count, 2, |
| 82 |
'Koha::Cash::Register->accountlines should return the correct number of accountlines' |
| 83 |
); |
| 84 |
|
| 85 |
$accountline1->delete; |
| 86 |
is( $register->accountlines->next->id, $accountline2->id, |
| 87 |
'Koha::Cash::Register->accountlines should return the correct acocuntlines' |
| 88 |
); |
| 89 |
|
| 90 |
$schema->storage->txn_rollback; |
| 91 |
}; |
| 92 |
|
| 57 |
subtest 'branch_default' => sub { |
93 |
subtest 'branch_default' => sub { |
| 58 |
plan tests => 3; |
94 |
plan tests => 3; |
| 59 |
|
95 |
|
|
Lines 89-109
subtest 'branch_default' => sub {
Link Here
|
| 89 |
subtest 'make_default' => sub { |
125 |
subtest 'make_default' => sub { |
| 90 |
plan tests => 3; |
126 |
plan tests => 3; |
| 91 |
|
127 |
|
| 92 |
ok($register2->make_default,'Koha::Register->make_default ran'); |
128 |
ok( $register2->make_default, 'Koha::Register->make_default ran' ); |
| 93 |
|
129 |
|
| 94 |
$register1 = $register1->get_from_storage; |
130 |
$register1 = $register1->get_from_storage; |
| 95 |
$register2 = $register2->get_from_storage; |
131 |
$register2 = $register2->get_from_storage; |
| 96 |
is($register1->branch_default, 0, 'register1 was unset as expected'); |
132 |
is( $register1->branch_default, 0, 'register1 was unset as expected' ); |
| 97 |
is($register2->branch_default, 1, 'register2 was set as expected'); |
133 |
is( $register2->branch_default, 1, 'register2 was set as expected' ); |
| 98 |
}; |
134 |
}; |
| 99 |
|
135 |
|
| 100 |
subtest 'drop_default' => sub { |
136 |
subtest 'drop_default' => sub { |
| 101 |
plan tests => 2; |
137 |
plan tests => 2; |
| 102 |
|
138 |
|
| 103 |
ok($register2->drop_default,'Koha::Register->drop_default ran'); |
139 |
ok( $register2->drop_default, 'Koha::Register->drop_default ran' ); |
| 104 |
|
140 |
|
| 105 |
$register2 = $register2->get_from_storage; |
141 |
$register2 = $register2->get_from_storage; |
| 106 |
is($register2->branch_default, 0, 'register2 was unset as expected'); |
142 |
is( $register2->branch_default, 0, 'register2 was unset as expected' ); |
|
|
143 |
}; |
| 144 |
|
| 145 |
$schema->storage->txn_rollback; |
| 146 |
}; |
| 147 |
|
| 148 |
subtest 'cashup' => sub { |
| 149 |
plan tests => 3; |
| 150 |
|
| 151 |
$schema->storage->txn_begin; |
| 152 |
|
| 153 |
my $register = |
| 154 |
$builder->build_object( { class => 'Koha::Cash::Registers' } ); |
| 155 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 156 |
|
| 157 |
my $cashup1; |
| 158 |
subtest 'add_cashup' => sub { |
| 159 |
plan tests => 6; |
| 160 |
|
| 161 |
ok( |
| 162 |
$cashup1 = $register->add_cashup( |
| 163 |
{ user_id => $patron->id, amount => '12.00' } |
| 164 |
), |
| 165 |
'call successfull' |
| 166 |
); |
| 167 |
|
| 168 |
is( |
| 169 |
ref($cashup1), |
| 170 |
'Koha::Cash::Register::Action', |
| 171 |
'return is Koha::Cash::Register::Action' |
| 172 |
); |
| 173 |
is( $cashup1->code, 'CASHUP', |
| 174 |
'CASHUP code set in Koha::Cash::Register::Action' ); |
| 175 |
is( $cashup1->manager_id, $patron->id, |
| 176 |
'manager_id set correctly in Koha::Cash::Register::Action' ); |
| 177 |
is( $cashup1->amount, '12.000000', |
| 178 |
'amount set correctly in Koha::Cash::Register::Action' ); |
| 179 |
isnt( $cashup1->timestamp, undef, |
| 180 |
'timestamp set in Koha::Cash::Register::Action' ); |
| 181 |
}; |
| 182 |
|
| 183 |
subtest 'last_cashup' => sub { |
| 184 |
plan tests => 3; |
| 185 |
|
| 186 |
my $cashup2 = |
| 187 |
$register->add_cashup( { user_id => $patron->id, amount => '6.00' } ); |
| 188 |
|
| 189 |
my $last_cashup = $register->last_cashup; |
| 190 |
is( |
| 191 |
ref($last_cashup), |
| 192 |
'Koha::Cash::Register::Action', |
| 193 |
'A cashup was returned when one existed' |
| 194 |
); |
| 195 |
is( $last_cashup->id, $cashup2->id, |
| 196 |
'The most recent cashup was returned' ); |
| 197 |
$cashup1->delete; |
| 198 |
$cashup2->delete; |
| 199 |
$last_cashup = $register->last_cashup; |
| 200 |
is( $last_cashup, undef, 'undef is returned when no cashup exists' ); |
| 201 |
}; |
| 202 |
|
| 203 |
subtest 'outstanding_accountlines' => sub { |
| 204 |
plan tests => 4; |
| 205 |
|
| 206 |
my $accountline1 = $builder->build_object( |
| 207 |
{ |
| 208 |
class => 'Koha::Account::Lines', |
| 209 |
value => { register_id => $register->id }, |
| 210 |
} |
| 211 |
); |
| 212 |
my $accountline2 = $builder->build_object( |
| 213 |
{ |
| 214 |
class => 'Koha::Account::Lines', |
| 215 |
value => { register_id => $register->id }, |
| 216 |
} |
| 217 |
); |
| 218 |
|
| 219 |
my $accountlines = $register->outstanding_accountlines; |
| 220 |
is( $accountlines->count, 2, 'No cashup, all accountlines returned' ); |
| 221 |
|
| 222 |
my $cashup3 = |
| 223 |
$register->add_cashup( { user_id => $patron->id, amount => '2.50' } ); |
| 224 |
|
| 225 |
$accountlines = $register->outstanding_accountlines; |
| 226 |
is( $accountlines->count, 0, 'Cashup added, no accountlines returned' ); |
| 227 |
|
| 228 |
my $accountline3 = $builder->build_object( |
| 229 |
{ |
| 230 |
class => 'Koha::Account::Lines', |
| 231 |
value => { register_id => $register->id }, |
| 232 |
} |
| 233 |
); |
| 234 |
|
| 235 |
$accountlines = $register->outstanding_accountlines; |
| 236 |
is( $accountlines->count, 1, |
| 237 |
'Accountline added, one accountline returned' ); |
| 238 |
is( $accountlines->next->id, |
| 239 |
$accountline3->id, 'Correct accountline returned' ); |
| 107 |
}; |
240 |
}; |
| 108 |
|
241 |
|
| 109 |
$schema->storage->txn_rollback; |
242 |
$schema->storage->txn_rollback; |
| 110 |
- |
|
|