|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
# Copyright 2017 Aleisha Amohia <aleisha@catalyst.net.nz> |
| 4 |
# |
| 5 |
# This file is part of Koha |
| 6 |
# |
| 7 |
# Koha is free software; you can redistribute it and/or modify it |
| 8 |
# under the terms of the GNU General Public License as published by |
| 9 |
# the Free Software Foundation; either version 3 of the License, or |
| 10 |
# (at your option) any later version. |
| 11 |
# |
| 12 |
# Koha is distributed in the hope that it will be useful, but |
| 13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
# GNU General Public License for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 19 |
|
| 20 |
use Modern::Perl; |
| 21 |
|
| 22 |
use Test::More tests => 4; |
| 23 |
|
| 24 |
use Koha::Database; |
| 25 |
use Koha::Acquisition::Basket; |
| 26 |
use Koha::Acquisition::Baskets; |
| 27 |
use Koha::Acquisition::Bookseller; |
| 28 |
|
| 29 |
use t::lib::TestBuilder; |
| 30 |
|
| 31 |
my $schema = Koha::Database->new->schema; |
| 32 |
$schema->storage->txn_begin; |
| 33 |
|
| 34 |
my $builder = t::lib::TestBuilder->new; |
| 35 |
my $num_of_baskets = Koha::Acquisition::Baskets->search->count; |
| 36 |
|
| 37 |
my $bookseller = Koha::Acquisition::Bookseller->new({ |
| 38 |
name => 'Bookseller1', |
| 39 |
currency => 'USD', |
| 40 |
})->store; |
| 41 |
|
| 42 |
my $basket = Koha::Acquisition::Basket->new({ |
| 43 |
basketname => 'Basket1', |
| 44 |
booksellerid => $bookseller->id, |
| 45 |
is_standing => 0, |
| 46 |
})->store; |
| 47 |
|
| 48 |
my $basket2 = Koha::Acquisition::Basket->new({ |
| 49 |
basketname => 'BasketToDelete', |
| 50 |
booksellerid => $bookseller->id, |
| 51 |
is_standing => 0, |
| 52 |
})->store; |
| 53 |
|
| 54 |
like( $basket->basketno, qr|^\d+$|, 'Adding a new basket should have set the basketno'); |
| 55 |
|
| 56 |
my $retrieved_basket = Koha::Acquisition::Baskets->find( $basket->basketno ); |
| 57 |
is( $retrieved_basket->basketname, $basket->basketname, 'Find a basket by id should return the correct basket' ); |
| 58 |
|
| 59 |
my $retrieved_bookseller = $retrieved_basket->bookseller; |
| 60 |
is( $retrieved_bookseller->name, $bookseller->name, "Finding the bookseller of a basket by the basket's booksellerid should work as expected" ); |
| 61 |
|
| 62 |
$basket2->delete; |
| 63 |
is( Koha::Acquisition::Baskets->search->count, $num_of_baskets + 1, 'Delete should have deleted the basket' ); |
| 64 |
|
| 65 |
$schema->storage->txn_rollback; |