View | Details | Raw Unified | Return to bug 16686
Collapse All | Expand All

(-)a/t/db_dependent/Koha/Item/Transfers.t (+69 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2016 Koha Development team
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 => 2;
23
24
use Koha::Item::Transfer;
25
use Koha::Item::Transfers;
26
use Koha::Database;
27
use Koha::DateUtils;
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 $library_from = $builder->build( { source => 'Branch' } );
36
my $library_to   = $builder->build( { source => 'Branch' } );
37
my $item         = $builder->build( { source => 'Item', value => { holding_branch => $library_from->{branchcode}, homebranch => $library_to->{branchcode} } } );
38
39
my $nb_of_transfers = Koha::Item::Transfers->search->count;
40
my $new_transfer_1  = Koha::Item::Transfer->new(
41
    {   itemnumber  => $item->{itemnumber},
42
        frombranch  => $library_from->{branchcode},
43
        tobranch    => $library_to->{branchcode},
44
        datearrived => dt_from_string,
45
        datesent    => dt_from_string,
46
    }
47
)->store;
48
my $new_transfer_2 = Koha::Item::Transfer->new(
49
    {   itemnumber  => $item->{itemnumber},
50
        frombranch  => $library_from->{branchcode},
51
        tobranch    => $library_to->{branchcode},
52
        datearrived => undef,
53
        datesent    => dt_from_string,
54
    }
55
)->store;
56
57
is( Koha::Item::Transfers->search->count, $nb_of_transfers + 2, 'The 2 transfers should have been added' );
58
59
my $retrieved_transfer_1 = Koha::Item::Transfers->search( { itemnumber => $new_transfer_1->itemnumber })->next;
60
is( $retrieved_transfer_1->itemnumber, $new_transfer_1->itemnumber, 'Find a transfer by id should return the correct transfer' );
61
62
# FIXME: This does not pass and should be fixed later
63
# "Operation requires a primary key to be declared on 'Branchtransfer' via set_primary_key"
64
#$retrieved_transfer_1->delete;
65
#is( Koha::Item::Transfers->search->count, $nb_of_transfers + 1, 'Delete should have deleted the transfer' );
66
67
$schema->storage->txn_rollback;
68
69
1;
(-)a/t/db_dependent/Koha/Items.t (-1 / +82 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2016 Koha Development team
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 => 5;
23
24
use C4::Circulation;
25
use Koha::Item;
26
use Koha::Items;
27
use Koha::Database;
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 $biblioitem  = $builder->build( { source => 'Biblioitem' } );
36
my $library     = $builder->build( { source => 'Branch' } );
37
my $nb_of_items = Koha::Items->search->count;
38
my $new_item_1  = Koha::Item->new(
39
    {   biblionumber     => $biblioitem->{biblionumber},
40
        biblioitemnumber => $biblioitem->{biblioitemnumber},
41
        homebranch       => $library->{branchcode},
42
        holdingbranch    => $library->{branchcode},
43
        barcode          => "a_barcode_for_t",
44
    }
45
)->store;
46
my $new_item_2 = Koha::Item->new(
47
    {   biblionumber     => $biblioitem->{biblionumber},
48
        biblioitemnumber => $biblioitem->{biblioitemnumber},
49
        homebranch       => $library->{branchcode},
50
        holdingbranch    => $library->{branchcode},
51
        barcode          => "another_barcode_for_t",
52
    }
53
)->store;
54
55
like( $new_item_1->itemnumber, qr|^\d+$|, 'Adding a new item should have set the itemnumber' );
56
is( Koha::Items->search->count, $nb_of_items + 2, 'The 2 items should have been added' );
57
58
my $retrieved_item_1 = Koha::Items->find( $new_item_1->itemnumber );
59
is( $retrieved_item_1->barcode, $new_item_1->barcode, 'Find a item by id should return the correct item' );
60
61
subtest 'get_transfer' => sub {
62
    plan tests => 3;
63
64
    my $transfer = $new_item_1->get_transfer();
65
    is( $transfer, undef, 'Koha::Item->get_transfer should return undef if the item is not in transit' );
66
67
    my $library_to = $builder->build( { source => 'Branch' } );
68
69
    C4::Circulation::transferbook( $library_to->{branchcode}, $new_item_1->barcode );
70
71
    $transfer = $new_item_1->get_transfer();
72
    is( ref($transfer), 'Koha::Item::Transfer', 'Koha::Item->get_transfer should return a Koha::Item::Transfers object' );
73
74
    is( $transfer->itemnumber, $new_item_1->itemnumber, 'Koha::Item->get_transfer should return a valid Koha::Item::Transfers object' );
75
};
76
77
$retrieved_item_1->delete;
78
is( Koha::Items->search->count, $nb_of_items + 1, 'Delete should have deleted the item' );
79
80
$schema->storage->txn_rollback;
81
82
1;

Return to bug 16686