Bugzilla – Attachment 71249 Details for
Bug 14749
Add API route to get top issues
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 14749: Add unit tests for /topissues
Bug-14749-Add-unit-tests-for-topissues.patch (text/plain), 4.63 KB, created by
Julian Maurice
on 2018-02-06 12:56:37 UTC
(
hide
)
Description:
Bug 14749: Add unit tests for /topissues
Filename:
MIME Type:
Creator:
Julian Maurice
Created:
2018-02-06 12:56:37 UTC
Size:
4.63 KB
patch
obsolete
>From af2058ae089588dc5e619a2e6c1fe7b46afe4dea Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Tue, 6 Feb 2018 13:55:27 +0100 >Subject: [PATCH] Bug 14749: Add unit tests for /topissues > >--- > t/db_dependent/api/v1/topissues.t | 135 ++++++++++++++++++++++++++++++++++++++ > 1 file changed, 135 insertions(+) > create mode 100755 t/db_dependent/api/v1/topissues.t > >diff --git a/t/db_dependent/api/v1/topissues.t b/t/db_dependent/api/v1/topissues.t >new file mode 100755 >index 0000000000..28421c3dab >--- /dev/null >+++ b/t/db_dependent/api/v1/topissues.t >@@ -0,0 +1,135 @@ >+#!/usr/bin/env perl >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 3 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along >+# with Koha; if not, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use Modern::Perl; >+ >+use Test::More tests => 1; >+use Test::MockModule; >+use Test::Mojo; >+use Test::Warn; >+ >+use t::lib::TestBuilder; >+use t::lib::Mocks; >+ >+use C4::Auth; >+use C4::Biblio; >+use C4::Items; >+use C4::Circulation; >+use C4::Members; >+use Koha::Patrons; >+use Koha::Illrequests; >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+my $remote_address = '127.0.0.1'; >+my $t = Test::Mojo->new('Koha::REST::V1'); >+ >+subtest 'list() tests' => sub { >+ plan tests => 3; >+ >+ $schema->storage->txn_begin; >+ >+ my $itemtype = $builder->build({ source => 'Itemtype' })->{ itemtype }; >+ my $category = $builder->build({ source => 'Category' })->{ categorycode }; >+ my $branch_1 = $builder->build({ source => 'Branch' }); >+ my $branch_2 = $builder->build({ source => 'Branch' }); >+ >+ my $c4_context = Test::MockModule->new('C4::Context'); >+ $c4_context->mock('userenv', sub { >+ { branch => $branch_1->{ branchcode } } >+ }); >+ t::lib::Mocks::mock_preference('item-level_itypes', '0'); >+ >+ my $biblionumber1 = create_biblio('Test 1', $itemtype); >+ AddItem({ >+ barcode => 'GTI_BARCODE_001', >+ homebranch => $branch_1->{ branchcode }, >+ ccode => 'GTI_CCODE', >+ }, $biblionumber1); >+ >+ my $biblionumber2 = create_biblio('Test 2', $itemtype); >+ AddItem({ >+ barcode => 'GTI_BARCODE_002', >+ homebranch => $branch_2->{ branchcode }, >+ }, $biblionumber2); >+ >+ my $borrowernumber = AddMember( >+ userid => 'gti.test', >+ categorycode => $category, >+ branchcode => $branch_1->{ branchcode } >+ ); >+ my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; >+ >+ AddIssue($borrower, 'GTI_BARCODE_001'); >+ AddIssue($borrower, 'GTI_BARCODE_002'); >+ >+ my $expected = [ >+ { >+ itemtype => $itemtype, >+ title => 'Test 1', >+ copyrightdate => undef, >+ publishercode => undef, >+ biblionumber => $biblionumber1, >+ count => 1, >+ place => undef, >+ author => undef, >+ publicationyear => undef, >+ pages => undef, >+ ccode => 'GTI_CCODE', >+ size => undef, >+ }, >+ { >+ itemtype => $itemtype, >+ title => 'Test 2', >+ copyrightdate => undef, >+ publishercode => undef, >+ biblionumber => $biblionumber2, >+ count => 1, >+ place => undef, >+ author => undef, >+ publicationyear => undef, >+ pages => undef, >+ ccode => undef, >+ size => undef, >+ }, >+ ]; >+ $t->get_ok("/api/v1/topissues?itemtype=$itemtype") >+ ->status_is(200) >+ ->json_is($expected); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+sub create_biblio { >+ my ($title, $itemtype) = @_; >+ >+ my ($title_tag, $title_subfield) = GetMarcFromKohaField('biblio.title', ''); >+ my ($it_tag, $it_subfield) = GetMarcFromKohaField('biblioitems.itemtype', ''); >+ >+ my $record = MARC::Record->new(); >+ $record->append_fields( >+ MARC::Field->new($title_tag, ' ', ' ', $title_subfield => $title), >+ MARC::Field->new($it_tag, ' ', ' ', $it_subfield => $itemtype), >+ ); >+ >+ my ($biblionumber) = AddBiblio($record, ''); >+ >+ return $biblionumber; >+} >+ >+1; >-- >2.14.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 14749
:
42047
|
42408
|
71248
| 71249