From 0ccac10a79b3163611268661b9e60e6037a90519 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Mon, 15 Jan 2018 14:38:13 +0000 Subject: [PATCH] Bug 20052 - Add Koha Reports object class To test: prove -v t/db_dependent/Koha/Reports.t Signed-off-by: Claire Gravely Signed-off-by: Maksim Sen --- Koha/Report.pm | 44 +++++++++++++++++++++++++++++++++++ Koha/Reports.pm | 50 ++++++++++++++++++++++++++++++++++++++++ t/db_dependent/Koha/Reports.t | 53 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 147 insertions(+) create mode 100644 Koha/Report.pm create mode 100644 Koha/Reports.pm create mode 100644 t/db_dependent/Koha/Reports.t diff --git a/Koha/Report.pm b/Koha/Report.pm new file mode 100644 index 0000000..a4b540d --- /dev/null +++ b/Koha/Report.pm @@ -0,0 +1,44 @@ +package Koha::Report; + +# 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 Carp; + +use Koha::Database; + +use base qw(Koha::Object); + +=head1 NAME + +Koha::Report - Koha Report Object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'SavedSql'; +} + +1; diff --git a/Koha/Reports.pm b/Koha/Reports.pm new file mode 100644 index 0000000..c0715ae --- /dev/null +++ b/Koha/Reports.pm @@ -0,0 +1,50 @@ +package Koha::Reports; + +# 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 Carp; + +use Koha::Database; + +use Koha::Report; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::Reports - Koha Report Object set class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'SavedSql'; +} + +sub object_class { + return 'Koha::Report'; +} + +1; diff --git a/t/db_dependent/Koha/Reports.t b/t/db_dependent/Koha/Reports.t new file mode 100644 index 0000000..4948e12 --- /dev/null +++ b/t/db_dependent/Koha/Reports.t @@ -0,0 +1,53 @@ +#!/usr/bin/perl + +# Copyright 2015 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::Report; +use Koha::Reports; +use Koha::Database; + +use t::lib::TestBuilder; + +my $schema = Koha::Database->new->schema; +$schema->storage->txn_begin; + +my $builder = t::lib::TestBuilder->new; +my $nb_of_reports = Koha::Reports->search->count; +my $new_report_1 = Koha::Report->new({ + report_name => 'report_name_for_test_1', + savedsql => 'SELECT "I wrote a report"', +})->store; +my $new_report_2 = Koha::Report->new({ + report_name => 'report_name_for_test_1', + savedsql => 'SELECT "Oops, I did it again"', +})->store; + +like( $new_report_1->id, qr|^\d+$|, 'Adding a new report should have set the id'); +is( Koha::Reports->search->count, $nb_of_reports + 2, 'The 2 reports should have been added' ); + +my $retrieved_report_1 = Koha::Reports->find( $new_report_1->id ); +is( $retrieved_report_1->report_name, $new_report_1->report_name, 'Find a report by id should return the correct report' ); + +$retrieved_report_1->delete; +is( Koha::Reports->search->count, $nb_of_reports + 1, 'Delete should have deleted the report' ); + +$schema->storage->txn_rollback; -- 2.7.4