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

(-)a/t/db_dependent/CourseReserves/CourseItems.t (-1 / +200 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use t::lib::Mocks;
21
use t::lib::TestBuilder;
22
use C4::CourseReserves qw/ModCourseItem ModCourseReserve DelCourseReserve GetCourseItem/;
23
use C4::Context;
24
use Koha::Items;
25
26
use Test::More tests => 17;
27
28
BEGIN {
29
    require_ok('C4::CourseReserves');
30
}
31
32
my $schema  = Koha::Database->new->schema;
33
$schema->storage->txn_begin;
34
35
my $builder = t::lib::TestBuilder->new();
36
37
create_dependent_objets();
38
my ($biblionumber, $itemnumber) = create_bib_and_item();
39
40
my $course = $builder->build({
41
    source => 'CourseReserve',
42
});
43
44
my $ci_id = ModCourseItem(
45
    itemnumber    => $itemnumber,
46
    itype         => 'BK_foo',
47
    ccode         => 'BOOK',
48
    holdingbranch => 'B2',
49
    location      => 'TH',
50
);
51
52
my $cr_id = ModCourseReserve(
53
    course_id   => $course->{course_id},
54
    ci_id       => $ci_id,
55
    staff_note  => '',
56
    public_note => '',
57
);
58
59
my $course_item = GetCourseItem( ci_id => $ci_id );
60
is($course_item->{itype}, 'CD_foo', 'Course item itype should be CD_foo');
61
is($course_item->{ccode}, 'CD', 'Course item ccode should be CD');
62
is($course_item->{holdingbranch}, 'B1', 'Course item holding branch should be B1');
63
is($course_item->{location}, 'HR', 'Course item location should be HR');
64
65
my $item = Koha::Items->find($itemnumber);
66
is($item->itype, 'BK_foo', 'Item type in course should be BK_foo');
67
is($item->ccode, 'BOOK', 'Item ccode in course should be BOOK');
68
is($item->holdingbranch, 'B2', 'Item holding branch in course should be B2');
69
is($item->location, 'TH', 'Item location in course should be TH');
70
71
DelCourseReserve( cr_id => $cr_id );
72
$item = Koha::Items->find($itemnumber);
73
is($item->itype, 'CD_foo', 'Item type removed from course should be set back to CD_foo');
74
is($item->ccode, 'CD', 'Item ccode removed from course should be set back to CD');
75
is($item->holdingbranch, 'B1', 'Item holding branch removed from course should be set back B1');
76
is($item->location, 'HR', 'Item location removed from course should be TH');
77
78
# Test the specific case described on bug #10382.
79
$item->ccode('')->store;
80
81
$item = Koha::Items->find($itemnumber);
82
is($item->ccode, '', 'Item ccode should be empty');
83
84
my $ci_id2 = ModCourseItem(
85
    itemnumber    => $itemnumber,
86
    itype         => 'CD_foo',
87
    ccode         => 'BOOK',
88
    holdingbranch => 'B1',
89
    location      => 'HR',
90
);
91
92
my $cr_id2 = ModCourseReserve(
93
    course_id   => $course->{course_id},
94
    ci_id       => $ci_id2,
95
    staff_note  => '',
96
    public_note => '',
97
);
98
99
$item = Koha::Items->find($itemnumber);
100
is($item->ccode, 'BOOK', 'Item ccode should be BOOK');
101
102
my $course_item2 = GetCourseItem( ci_id => $ci_id2 );
103
is($course_item2->{ccode}, '', 'Course item ccode should be empty');
104
105
DelCourseReserve( cr_id => $cr_id2 );
106
$item = Koha::Items->find($itemnumber);
107
is($item->ccode, '', 'Item ccode should be set back to empty');
108
109
$schema->storage->txn_rollback;
110
111
sub create_dependent_objets {
112
    $builder->build({
113
        source => 'Itemtype',
114
        value  => {
115
            itemtype => 'CD_foo',
116
            description => 'Compact Disk'
117
        }
118
    });
119
120
    $builder->build({
121
        source => 'Itemtype',
122
        value  => {
123
            itemtype => 'BK_foo',
124
            description => 'Book'
125
        }
126
    });
127
128
    $builder->build({
129
        source => 'Branch',
130
        value  => {
131
            branchcode => 'B1',
132
            branchname => 'Branch 1'
133
        }
134
    });
135
136
    $builder->build({
137
        source => 'Branch',
138
        value  => {
139
            branchcode => 'B2',
140
            branchname => 'Branch 2'
141
        }
142
    });
143
144
    $builder->build({
145
        source => 'AuthorisedValue',
146
        value  => {
147
            category => 'CCODE',
148
            authorised_value => 'BOOK',
149
            lib => 'Book'
150
        }
151
    });
152
153
    $builder->build({
154
        source => 'AuthorisedValue',
155
        value  => {
156
            category => 'CCODE',
157
            authorised_value => 'CD',
158
            lib => 'Compact Disk'
159
        }
160
    });
161
162
    $builder->build({
163
        source => 'AuthorisedValue',
164
        value  => {
165
            category => 'LOC',
166
            authorised_value => 'HR',
167
            lib => 'Here'
168
        }
169
    });
170
171
    $builder->build({
172
        source => 'AuthorisedValue',
173
        value  => {
174
            category => 'LOC',
175
            authorised_value => 'TH',
176
            lib => 'There'
177
        }
178
    });
179
}
180
181
sub create_bib_and_item {
182
    my $biblio = $builder->build({
183
        source => 'Biblio',
184
        value  => {
185
            title => 'Title',
186
        }
187
    });
188
    my $item = $builder->build({
189
        source => 'Item',
190
        value  => {
191
            biblionumber  => $biblio->{biblionumber},
192
            itype         => 'CD_foo',
193
            ccode         => 'CD',
194
            location      => 'HR',
195
            homebranch    => 'B1',
196
            holdingbranch => 'B1',
197
        }
198
    });
199
    return ($biblio->{biblionumber}, $item->{itemnumber});
200
}

Return to bug 10382