Lines 30-62
use t::lib::TestBuilder;
Link Here
|
30 |
my $schema = Koha::Database->new->schema; |
30 |
my $schema = Koha::Database->new->schema; |
31 |
$schema->storage->txn_begin; |
31 |
$schema->storage->txn_begin; |
32 |
|
32 |
|
33 |
my $builder = t::lib::TestBuilder->new; |
33 |
my $builder = t::lib::TestBuilder->new; |
34 |
my $library = $builder->build( { source => 'Branch' } ); |
34 |
my $patron = $builder->build( { source => 'Borrower' } ); |
35 |
my $patron = $builder->build( { source => 'Borrower', value => { branchcode => $library->{branchcode} } } ); |
35 |
my $item_1 = $builder->build( { source => 'Item' } ); |
36 |
my $item_1 = $builder->build( { source => 'Item' } ); |
36 |
my $item_2 = $builder->build( { source => 'Item' } ); |
37 |
my $item_2 = $builder->build( { source => 'Item' } ); |
37 |
my $nb_of_issues = Koha::Checkouts->search->count; |
38 |
my $nb_of_checkouts = Koha::Checkouts->search->count; |
38 |
my $new_issue_1 = Koha::Checkout->new( |
39 |
my $new_checkout_1 = Koha::Checkout->new( |
|
|
40 |
{ borrowernumber => $patron->{borrowernumber}, |
39 |
{ borrowernumber => $patron->{borrowernumber}, |
41 |
itemnumber => $item_1->{itemnumber}, |
40 |
itemnumber => $item_1->{itemnumber}, |
42 |
branchcode => $library->{branchcode}, |
|
|
43 |
} |
41 |
} |
44 |
)->store; |
42 |
)->store; |
45 |
my $new_checkout_2 = Koha::Checkout->new( |
43 |
my $new_issue_2 = Koha::Checkout->new( |
46 |
{ borrowernumber => $patron->{borrowernumber}, |
44 |
{ borrowernumber => $patron->{borrowernumber}, |
47 |
itemnumber => $item_2->{itemnumber}, |
45 |
itemnumber => $item_2->{itemnumber}, |
48 |
branchcode => $library->{branchcode}, |
|
|
49 |
} |
46 |
} |
50 |
)->store; |
47 |
)->store; |
51 |
|
48 |
|
52 |
like( $new_checkout_1->issue_id, qr|^\d+$|, 'Adding a new checkout should have set the issue_id' ); |
49 |
like( $new_issue_1->issue_id, qr|^\d+$|, 'Adding a new issue should have set the issue_id' ); |
53 |
is( Koha::Checkouts->search->count, $nb_of_checkouts + 2, 'The 2 checkouts should have been added' ); |
50 |
is( Koha::Checkouts->search->count, $nb_of_issues + 2, 'The 2 issues should have been added' ); |
54 |
|
51 |
|
55 |
my $retrieved_checkout_1 = Koha::Checkouts->find( $new_checkout_1->issue_id ); |
52 |
my $retrieved_issue_1 = Koha::Checkouts->find( $new_issue_1->issue_id ); |
56 |
is( $retrieved_checkout_1->itemnumber, $new_checkout_1->itemnumber, 'Find a checkout by id should return the correct checkout' ); |
53 |
is( $retrieved_issue_1->itemnumber, $new_issue_1->itemnumber, 'Find a issue by id should return the correct issue' ); |
57 |
|
54 |
|
58 |
$retrieved_checkout_1->delete; |
55 |
$retrieved_issue_1->delete; |
59 |
is( Koha::Checkouts->search->count, $nb_of_checkouts + 1, 'Delete should have deleted the checkout' ); |
56 |
is( Koha::Checkouts->search->count, $nb_of_issues + 1, 'Delete should delete the issue' ); |
60 |
|
57 |
|
61 |
$schema->storage->txn_rollback; |
58 |
$schema->storage->txn_rollback; |
62 |
|
59 |
|