3 # This file is part of Koha.
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.
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.
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>.
20 use Test::More tests => 5;
23 use t::lib::TestBuilder;
26 use Koha::ArticleRequests;
28 my $schema = Koha::Database->new->schema;
29 my $builder = t::lib::TestBuilder->new;
31 subtest 'request() tests' => sub {
35 $schema->storage->txn_begin;
37 my $patron = $builder->build_object({ class => 'Koha::Patrons' });
38 my $biblio = $builder->build_sample_biblio;
40 my $ar_mock = Test::MockModule->new('Koha::ArticleRequest');
41 $ar_mock->mock( 'notify', sub { ok( 1, '->notify() called' ); } );
43 my $ar = Koha::ArticleRequest->new(
45 borrowernumber => $patron->id,
46 biblionumber => $biblio->id,
50 $ar->request()->discard_changes;
52 is( $ar->status, Koha::ArticleRequest::Status::Requested );
53 ok( defined $ar->created_on, 'created_on is set' );
55 $schema->storage->txn_rollback;
58 subtest 'set_pending() tests' => sub {
62 $schema->storage->txn_begin;
64 my $patron = $builder->build_object({ class => 'Koha::Patrons' });
65 my $biblio = $builder->build_sample_biblio;
67 my $ar_mock = Test::MockModule->new('Koha::ArticleRequest');
68 $ar_mock->mock( 'notify', sub { ok( 1, '->notify() called' ); } );
70 my $ar = Koha::ArticleRequest->new(
72 borrowernumber => $patron->id,
73 biblionumber => $biblio->id,
77 $ar->set_pending()->discard_changes;
79 is( $ar->status, Koha::ArticleRequest::Status::Pending );
80 ok( defined $ar->created_on, 'created_on is set' );
82 $schema->storage->txn_rollback;
85 subtest 'process() tests' => sub {
89 $schema->storage->txn_begin;
91 my $ar_mock = Test::MockModule->new('Koha::ArticleRequest');
92 $ar_mock->mock( 'notify', sub { ok( 1, '->notify() called' ); } );
94 my $ar = $builder->build_object(
95 { class => 'Koha::ArticleRequests',
96 value => { status => Koha::ArticleRequest::Status::Requested }
100 $ar->process()->discard_changes;
102 is( $ar->status, Koha::ArticleRequest::Status::Processing );
104 $schema->storage->txn_rollback;
107 subtest 'complete() tests' => sub {
111 $schema->storage->txn_begin;
113 my $ar_mock = Test::MockModule->new('Koha::ArticleRequest');
114 $ar_mock->mock( 'notify', sub { ok( 1, '->notify() called' ); } );
116 my $ar = $builder->build_object(
117 { class => 'Koha::ArticleRequests',
118 value => { status => Koha::ArticleRequest::Status::Requested }
122 $ar->complete()->discard_changes;
124 is( $ar->status, Koha::ArticleRequest::Status::Completed );
126 $schema->storage->txn_rollback;
129 subtest 'cancel() tests' => sub {
133 $schema->storage->txn_begin;
135 my $ar_mock = Test::MockModule->new('Koha::ArticleRequest');
136 $ar_mock->mock( 'notify', sub { ok( 1, '->notify() called' ); } );
138 my $ar = $builder->build_object(
139 { class => 'Koha::ArticleRequests',
140 value => { status => Koha::ArticleRequest::Status::Requested }
144 my $reason = "Hey, ho";
145 my $notes = "Let's go!";
147 $ar->cancel({ cancellation_reason => $reason, notes => $notes })->discard_changes;
149 is( $ar->status, Koha::ArticleRequest::Status::Canceled );
150 is( $ar->cancellation_reason, $reason, 'Cancellation reason stored correctly' );
151 is( $ar->notes, $notes, 'Notes stored correctly' );
153 $schema->storage->txn_rollback;