Bug 26157: Hide expected DBI warnings from tests
[koha.git] / t / db_dependent / StockRotationRotas.t
blob31e63c486857feed208bb8e421b23643b37f1a49
1 #!/usr/bin/perl
3 # Copyright PTFS Europe 2016
5 # This file is part of Koha.
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.
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.
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>.
20 use Modern::Perl;
22 use Koha::Database;
23 use t::lib::TestBuilder;
25 use Test::More tests => 5;
27 my $schema = Koha::Database->new->schema;
29 use_ok('Koha::StockRotationRotas');
30 use_ok('Koha::StockRotationRota');
32 subtest 'Basic object tests' => sub {
34 plan tests => 5;
36 $schema->storage->txn_begin;
38 my $builder = t::lib::TestBuilder->new;
40 my $rota = $builder->build({ source => 'Stockrotationrota' });
42 my $srrota = Koha::StockRotationRotas->find($rota->{rota_id});
43 isa_ok(
44 $srrota,
45 'Koha::StockRotationRota',
46 "Correctly create and load a stock rotation rota."
49 $builder->build({
50 source => 'Stockrotationstage',
51 value => { rota_id => $rota->{rota_id} },
52 });
53 $builder->build({
54 source => 'Stockrotationstage',
55 value => { rota_id => $rota->{rota_id} },
56 });
57 $builder->build({
58 source => 'Stockrotationstage',
59 value => { rota_id => $rota->{rota_id} },
60 });
62 my $srstages = $srrota->stockrotationstages;
63 is( $srstages->count, 3, 'Correctly fetched stockrotationstages associated with this rota');
65 isa_ok( $srstages->next, 'Koha::StockRotationStage', "Relationship correctly creates Koha::Objects." );
67 #### Test add_item
69 my $item = $builder->build({ source => 'Item' });
71 $srrota->add_item($item->{itemnumber});
73 is(
74 Koha::StockRotationItems->find($item->{itemnumber})->stage_id,
75 $srrota->first_stage->stage_id,
76 "Adding an item results in a new sritem item being assigned to the first stage."
79 my $newrota = $builder->build({ source => 'Stockrotationrota' });
81 my $srnewrota = Koha::StockRotationRotas->find($newrota->{rota_id});
83 $builder->build({
84 source => 'Stockrotationstage',
85 value => { rota_id => $newrota->{rota_id} },
86 });
88 $srnewrota->add_item($item->{itemnumber});
90 is(
91 Koha::StockRotationItems->find($item->{itemnumber})->stage_id,
92 $srnewrota->stockrotationstages->next->stage_id,
93 "Moving an item results in that sritem being assigned to the new first stage."
96 $schema->storage->txn_rollback;
99 subtest '->first_stage test' => sub {
100 plan tests => 2;
102 $schema->storage->txn_begin;
104 my $builder = t::lib::TestBuilder->new;
106 my $rota = $builder->build({ source => 'Stockrotationrota' });
108 my $stage1 = $builder->build({
109 source => 'Stockrotationstage',
110 value => { rota_id => $rota->{rota_id} },
112 my $stage2 = $builder->build({
113 source => 'Stockrotationstage',
114 value => { rota_id => $rota->{rota_id} },
116 my $stage3 = $builder->build({
117 source => 'Stockrotationstage',
118 value => { rota_id => $rota->{rota_id} },
121 my $srrota = Koha::StockRotationRotas->find($rota->{rota_id});
122 my $srstage2 = Koha::StockRotationStages->find($stage2->{stage_id});
123 my $firststage = $srstage2->first_sibling || $srstage2;
125 is( $srrota->first_stage->stage_id, $firststage->stage_id, "First stage works" );
127 $srstage2->move_first;
129 is( Koha::StockRotationRotas->find($rota->{rota_id})->first_stage->stage_id, $stage2->{stage_id}, "Stage re-organized" );
131 $schema->storage->txn_rollback;
134 subtest '->items test' => sub {
135 plan tests => 1;
137 $schema->storage->txn_begin;
139 my $builder = t::lib::TestBuilder->new;
141 my $rota = $builder->build({ source => 'Stockrotationrota' });
143 my $stage1 = $builder->build({
144 source => 'Stockrotationstage',
145 value => { rota_id => $rota->{rota_id} },
147 my $stage2 = $builder->build({
148 source => 'Stockrotationstage',
149 value => { rota_id => $rota->{rota_id} },
151 my $stage3 = $builder->build({
152 source => 'Stockrotationstage',
153 value => { rota_id => $rota->{rota_id} },
156 map { $builder->build({
157 source => 'Stockrotationitem',
158 value => { stage_id => $_ },
159 }) } (
160 $stage1->{stage_id}, $stage1->{stage_id},
161 $stage2->{stage_id}, $stage2->{stage_id},
162 $stage3->{stage_id}, $stage3->{stage_id},
165 my $srrota = Koha::StockRotationRotas->find($rota->{rota_id});
168 $srrota->stockrotationitems->count,
169 6, "Correct number of items"
172 $schema->storage->txn_rollback;