Bug 29082: Add filtering methods to Koha::ArticleRequests
This patch adds handy methods for filtering Koha::ArticleRequests resultsets. To test: 1. Apply this patch 2. Run: $ kshell k$ prove t/db_dependent/Koha/ArticleRequests.t => SUCCESS: Tests pass! 3. Sign off :-D Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Nick Clemens <nick@bywatersolutions.com> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
parent
861bce53c3
commit
6ae273ddcb
|
|
@ -33,7 +33,7 @@ Koha::ArticleRequests - Koha ArticleRequests Object class
|
|||
|
||||
=head1 API
|
||||
|
||||
=head2 Class Methods
|
||||
=head2 Class methods
|
||||
|
||||
=cut
|
||||
|
||||
|
|
@ -60,6 +60,49 @@ sub search_limited {
|
|||
return $self->search( $params, $attributes );
|
||||
}
|
||||
|
||||
=head3 filter_by_current
|
||||
|
||||
my $current_article_requests = $article_requests->filter_by_current;
|
||||
|
||||
Returns a new resultset, filtering out finished article requests.
|
||||
|
||||
=cut
|
||||
|
||||
sub filter_by_current {
|
||||
my ($self) = @_;
|
||||
|
||||
return $self->search(
|
||||
{
|
||||
status => [
|
||||
Koha::ArticleRequest::Status::Requested,
|
||||
Koha::ArticleRequest::Status::Pending,
|
||||
Koha::ArticleRequest::Status::Processing,
|
||||
]
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
=head3 filter_by_finished
|
||||
|
||||
my $finished_article_requests = $article_requests->filter_by_finished;
|
||||
|
||||
Returns a new resultset, filtering out current article requests.
|
||||
|
||||
=cut
|
||||
|
||||
sub filter_by_finished {
|
||||
my ($self) = @_;
|
||||
|
||||
return $self->search(
|
||||
{
|
||||
status => [
|
||||
Koha::ArticleRequest::Status::Completed,
|
||||
Koha::ArticleRequest::Status::Canceled,
|
||||
]
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
=head3 requested
|
||||
|
||||
=cut
|
||||
|
|
|
|||
|
|
@ -17,15 +17,16 @@
|
|||
|
||||
use Modern::Perl;
|
||||
|
||||
use Test::More tests => 1;
|
||||
use Test::More tests => 3;
|
||||
use Test::MockModule;
|
||||
|
||||
use t::lib::TestBuilder;
|
||||
use t::lib::Mocks;
|
||||
|
||||
use Koha::ArticleRequest::Status;
|
||||
use Koha::ArticleRequests;
|
||||
use Koha::Database;
|
||||
|
||||
use t::lib::Mocks;
|
||||
use t::lib::TestBuilder;
|
||||
|
||||
my $schema = Koha::Database->new->schema;
|
||||
my $builder = t::lib::TestBuilder->new;
|
||||
|
||||
|
|
@ -77,3 +78,109 @@ subtest 'requested() tests' => sub {
|
|||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
||||
subtest 'filter_by_current() tests' => sub {
|
||||
|
||||
plan tests => 1;
|
||||
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
my $ar_requested = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::ArticleRequests',
|
||||
value => { status => Koha::ArticleRequest::Status::Requested }
|
||||
}
|
||||
);
|
||||
my $ar_pending = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::ArticleRequests',
|
||||
value => { status => Koha::ArticleRequest::Status::Pending }
|
||||
}
|
||||
);
|
||||
my $ar_processing = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::ArticleRequests',
|
||||
value => { status => Koha::ArticleRequest::Status::Processing }
|
||||
}
|
||||
);
|
||||
my $ar_completed = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::ArticleRequests',
|
||||
value => { status => Koha::ArticleRequest::Status::Completed }
|
||||
}
|
||||
);
|
||||
my $ar_cancelled = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::ArticleRequests',
|
||||
value => { status => Koha::ArticleRequest::Status::Canceled }
|
||||
}
|
||||
);
|
||||
|
||||
my $article_requests = Koha::ArticleRequests->search(
|
||||
{
|
||||
id => [
|
||||
$ar_requested->id, $ar_pending->id, $ar_processing->id,
|
||||
$ar_completed->id, $ar_cancelled->id
|
||||
]
|
||||
}
|
||||
);
|
||||
|
||||
my $current_article_requests = $article_requests->filter_by_current;
|
||||
|
||||
is( $current_article_requests->count, 3, 'Count is correct' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
||||
subtest 'filter_by_current() tests' => sub {
|
||||
|
||||
plan tests => 1;
|
||||
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
my $ar_requested = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::ArticleRequests',
|
||||
value => { status => Koha::ArticleRequest::Status::Requested }
|
||||
}
|
||||
);
|
||||
my $ar_pending = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::ArticleRequests',
|
||||
value => { status => Koha::ArticleRequest::Status::Pending }
|
||||
}
|
||||
);
|
||||
my $ar_processing = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::ArticleRequests',
|
||||
value => { status => Koha::ArticleRequest::Status::Processing }
|
||||
}
|
||||
);
|
||||
my $ar_completed = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::ArticleRequests',
|
||||
value => { status => Koha::ArticleRequest::Status::Completed }
|
||||
}
|
||||
);
|
||||
my $ar_cancelled = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::ArticleRequests',
|
||||
value => { status => Koha::ArticleRequest::Status::Canceled }
|
||||
}
|
||||
);
|
||||
|
||||
my $article_requests = Koha::ArticleRequests->search(
|
||||
{
|
||||
id => [
|
||||
$ar_requested->id, $ar_pending->id, $ar_processing->id,
|
||||
$ar_completed->id, $ar_cancelled->id
|
||||
]
|
||||
}
|
||||
);
|
||||
|
||||
my $finished_article_requests = $article_requests->filter_by_finished;
|
||||
|
||||
is( $finished_article_requests->count, 2, 'Count is correct' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue