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 => 1;
23 use t::lib::TestBuilder;
26 use Koha::ArticleRequests;
29 my $schema = Koha::Database->new->schema;
30 my $builder = t::lib::TestBuilder->new;
32 subtest 'requested() tests' => sub {
36 $schema->storage->txn_begin;
38 my $library_1 = $builder->build_object( { class => 'Koha::Libraries' } );
39 my $library_2 = $builder->build_object( { class => 'Koha::Libraries' } );
41 my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library_1->id, flags => 1 } } );
42 t::lib::Mocks::mock_userenv( { branchcode => $library_1 } );
44 # FIXME: we moved past this pattern. This method should be refactored
45 # as ->filter_by_requested
46 Koha::ArticleRequests->delete;
48 my $ar_mock = Test::MockModule->new('Koha::ArticleRequest');
49 $ar_mock->mock( 'notify', sub { ok( 1, '->notify() called' ); } );
51 my $ar_1 = $builder->build_object(
52 { class => 'Koha::ArticleRequests',
53 value => { status => Koha::ArticleRequest::Status::Requested, branchcode => $library_1->id }
57 my $ar_2 = $builder->build_object(
58 { class => 'Koha::ArticleRequests',
59 value => { status => Koha::ArticleRequest::Status::Requested, branchcode => $library_2->id }
63 my $ar_3 = $builder->build_object(
64 { class => 'Koha::ArticleRequests',
65 value => { status => Koha::ArticleRequest::Status::Pending, branchcode => $library_2->id }
69 my $requested = Koha::ArticleRequests->requested;
70 is( $requested->count, 2, 'Two article requests with the REQUESTED status' );
71 is( $requested->next->status, Koha::ArticleRequest::Status::Requested, 'Status is correct' );
72 is( $requested->next->status, Koha::ArticleRequest::Status::Requested, 'Status is correct' );
74 my $requested_branch = Koha::ArticleRequests->requested( $library_1->id );
75 is( $requested_branch->count, 1, 'One article request with the REQUESTED status, for the selected branchcode' );
76 is( $requested_branch->next->status, Koha::ArticleRequest::Status::Requested, 'Status is correct' );
78 $schema->storage->txn_rollback;