From 95c148f6aa5cd40df7cbd5a39ce716f50d2d7482 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 3 Dec 2019 17:40:06 +0100 Subject: [PATCH] Bug 24149: Add tests Signed-off-by: Josef Moravec --- t/db_dependent/Koha/Statistics.t | 56 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 t/db_dependent/Koha/Statistics.t diff --git a/t/db_dependent/Koha/Statistics.t b/t/db_dependent/Koha/Statistics.t new file mode 100644 index 0000000000..12ebc9e75a --- /dev/null +++ b/t/db_dependent/Koha/Statistics.t @@ -0,0 +1,56 @@ +#!/usr/bin/perl + +# Copyright 2019 Koha Development team +# +# 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, see . + +use Modern::Perl; + +use Test::More tests => 4; + +use Koha::Database; +use Koha::Statistics; +use C4::Stats; + +use t::lib::TestBuilder; + +my $schema = Koha::Database->new->schema; +$schema->storage->txn_begin; + +my $builder = t::lib::TestBuilder->new; +my $library = $builder->build_object( { class => 'Koha::Libraries' } ); +my $item = $builder->build_sample_item; +my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); +C4::Stats::UpdateStats( + { + type => 'issue', + branch => $library->branchcode, + itemnumber => $item->itemnumber, + borrowernumber => $patron->borrowernumber, + itemtype => $item->effective_itemtype, + location => $item->location, + ccode => $item->ccode, + } +); + +my $stat = + Koha::Statistics->search( { itemnumber => $item->itemnumber } )->next; +is( $stat->borrowernumber, $patron->borrowernumber, 'Patron is there' ); +is( $stat->branch, $library->branchcode, 'Library is there' ); +is( ref( $stat->item ), 'Koha::Item', '->item returns a Koha::Item object' ); +is( $stat->item->itemnumber, $item->itemnumber, '->item works great' ); + +$schema->storage->txn_rollback; -- 2.11.0