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

(-)a/t/db_dependent/Koha/RotatingCollections.t (-3 / +118 lines)
Lines 17-33 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 2;
20
use Test::More tests => 4;
21
use C4::Context;
21
use C4::Context;
22
use Koha::Biblios;
22
use Koha::Biblios;
23
use Koha::Biblioitems;
23
use Koha::Database;
24
use Koha::Database;
24
use Koha::Library;
25
use Koha::DateUtils;
25
use Koha::RotatingCollections;
26
use Koha::RotatingCollections;
26
use Koha::Items;
27
use Koha::Items;
27
use Koha::Item::Transfers;
28
use Koha::Item::Transfers;
28
use Koha::Libraries;
29
use Koha::Libraries;
30
use Koha::Patrons;
29
31
30
use t::lib::TestBuilder;
32
use t::lib::TestBuilder;
33
use Test::MockModule;
31
34
32
my $schema = Koha::Database->new->schema;
35
my $schema = Koha::Database->new->schema;
33
my $builder = t::lib::TestBuilder->new;
36
my $builder = t::lib::TestBuilder->new;
Lines 140-142 subtest 'transfer' => sub { Link Here
140
143
141
    $schema->storage->txn_rollback;
144
    $schema->storage->txn_rollback;
142
};
145
};
143
- 
146
147
subtest 'new_create_creator' => sub {
148
    plan tests => 3;
149
150
    $schema->storage->txn_begin;
151
152
    my $collection1 = Koha::RotatingCollection->new( {
153
        colTitle => "Collection 1",
154
        colDesc => "Collection 1 description",
155
    } )->store;
156
157
    is($collection1->creator, undef, "Creator should not be set if patron is not set in userenv");
158
159
    my $categorycode = $builder->build({ source => 'Category' })->{categorycode};
160
    my $branchcode = $builder->build({ source => 'Branch' })->{branchcode};
161
162
    my $patron = Koha::Patron->new( {
163
        firstname => "Creative",
164
        surname => "Librarian",
165
        categorycode => $categorycode,
166
        branchcode => $branchcode,
167
    })->store;
168
169
    my $context = new Test::MockModule('C4::Context');
170
    $context->mock('userenv', sub {
171
        return {
172
            number => $patron->borrowernumber,
173
        }
174
    });
175
    my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
176
177
    my $collection2 = Koha::RotatingCollection->new( {
178
        colTitle => "Collection 2",
179
        colDesc  => "Collection 2 description",
180
    } )->store;
181
182
    is( $collection2->createdOn, $today , "Collection create day should be set");
183
    is( $collection2->creator->borrowernumber, $patron->borrowernumber, "Collection creator should be set");
184
185
    $schema->storage->txn_rollback;
186
};
187
188
subtest 'untransferred_items' => sub {
189
    plan tests => 5;
190
191
    $schema->storage->txn_begin;
192
193
    my $library1 = Koha::Library->new({
194
        branchcode => "LIBCOL1",
195
        branchname => "Library for testing collection 1",
196
    })->store;
197
198
    my $library2 = Koha::Library->new({
199
        branchcode => "LIBCOL2",
200
        branchname => "Library for testing colletions 2",
201
    })->store;
202
203
    my $biblio = Koha::Biblio->new({
204
        author => "Some author 1",
205
        title => "Some title 2",
206
    })->store;
207
208
    my $biblioitem = Koha::Biblioitem->new({
209
        biblionumber => $biblio->biblionumber,
210
    })->store;
211
212
    my $item1 = Koha::Item->new({
213
        barcode => "BC1000001",
214
        biblionumber => $biblio->biblionumber,
215
        biblioitemnumber => $biblioitem->biblioitemnumber,
216
        homebranch => $library1->branchcode,
217
        holdingbranch => $library1->branchcode,
218
    })->store;
219
220
    my $item2 = Koha::Item->new({
221
        barcode => "BC1000002",
222
        biblionumber => $biblio->biblionumber,
223
        biblioitemnumber => $biblioitem->biblioitemnumber,
224
        homebranch => $library1->branchcode,
225
        holdingbranch => $library1->branchcode,
226
    })->store;
227
228
    my $item3 = Koha::Item->new({
229
        barcode => "BC1000003",
230
        biblionumber => $biblio->biblionumber,
231
        biblioitemnumber => $biblioitem->biblioitemnumber,
232
        homebranch => $library1->branchcode,
233
        holdingbranch => $library1->branchcode,
234
    })->store;
235
236
    my $collection = Koha::RotatingCollection->new({
237
        colTitle => "Collection",
238
        colDesc => "Collection description",
239
    })->store;
240
241
    is($collection->untransferred_items->count, 0, "There are no items, so no untransferred");
242
243
    $collection->add_item( $item1 );
244
    $collection->add_item( $item2 );
245
246
    is($collection->untransferred_items->count, 2, "We added 2 items");
247
248
    $collection->transfer( $library2 );
249
250
    is($collection->untransferred_items->count, 0, "There are no untransferred items after transfer");
251
252
    $collection->add_item( $item3 );
253
254
    is($collection->untransferred_items->count, 1, "We added 1 more item");
255
    is($collection->untransferred_items->next->itemnumber, $item3->itemnumber, "The returned item is the one added after transfer");
256
257
    $schema->storage->txn_rollback;
258
};

Return to bug 19520