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 my $schema = Koha::Database->new->schema;
27 my $builder = t::lib::TestBuilder->new;
29 subtest 'request() tests' => sub {
33 $schema->storage->txn_begin;
35 my $ar_mock = Test::MockModule->new('Koha::ArticleRequest');
36 $ar_mock->mock( 'notify', sub { ok( 1, '->notify() called' ); } );
38 my $ar = $builder->build_object(
39 { class => 'Koha::ArticleRequests',
40 value => { status => Koha::ArticleRequest::Status::Pending }
44 $ar->request()->discard_changes;
46 is( $ar->status, Koha::ArticleRequest::Status::Requested );
48 $schema->storage->txn_rollback;
51 subtest 'set_pending() tests' => sub {
55 $schema->storage->txn_begin;
57 my $ar_mock = Test::MockModule->new('Koha::ArticleRequest');
58 $ar_mock->mock( 'notify', sub { ok( 1, '->notify() called' ); } );
60 my $ar = $builder->build_object(
61 { class => 'Koha::ArticleRequests',
62 value => { status => Koha::ArticleRequest::Status::Requested }
66 $ar->set_pending()->discard_changes;
68 is( $ar->status, Koha::ArticleRequest::Status::Pending );
70 $schema->storage->txn_rollback;
73 subtest 'process() tests' => sub {
77 $schema->storage->txn_begin;
79 my $ar_mock = Test::MockModule->new('Koha::ArticleRequest');
80 $ar_mock->mock( 'notify', sub { ok( 1, '->notify() called' ); } );
82 my $ar = $builder->build_object(
83 { class => 'Koha::ArticleRequests',
84 value => { status => Koha::ArticleRequest::Status::Requested }
88 $ar->process()->discard_changes;
90 is( $ar->status, Koha::ArticleRequest::Status::Processing );
92 $schema->storage->txn_rollback;
95 subtest 'complete() tests' => sub {
99 $schema->storage->txn_begin;
101 my $ar_mock = Test::MockModule->new('Koha::ArticleRequest');
102 $ar_mock->mock( 'notify', sub { ok( 1, '->notify() called' ); } );
104 my $ar = $builder->build_object(
105 { class => 'Koha::ArticleRequests',
106 value => { status => Koha::ArticleRequest::Status::Requested }
110 $ar->complete()->discard_changes;
112 is( $ar->status, Koha::ArticleRequest::Status::Completed );
114 $schema->storage->txn_rollback;
117 subtest 'cancel() tests' => sub {
121 $schema->storage->txn_begin;
123 my $ar_mock = Test::MockModule->new('Koha::ArticleRequest');
124 $ar_mock->mock( 'notify', sub { ok( 1, '->notify() called' ); } );
126 my $ar = $builder->build_object(
127 { class => 'Koha::ArticleRequests',
128 value => { status => Koha::ArticleRequest::Status::Requested }
132 my $reason = "Hey, ho";
133 my $notes = "Let's go!";
135 $ar->cancel({ cancellation_reason => $reason, notes => $notes })->discard_changes;
137 is( $ar->status, Koha::ArticleRequest::Status::Canceled );
138 is( $ar->cancellation_reason, $reason, 'Cancellation reason stored correctly' );
139 is( $ar->notes, $notes, 'Notes stored correctly' );
141 $schema->storage->txn_rollback;