Bug 24757: Leap day failing tests - Fix the tests!
[koha.git] / t / db_dependent / Koha / Reports.t
1 #!/usr/bin/perl
2
3 # This file is part of Koha
4 #
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.
9 #
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.
14 #
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>.
17
18 use Modern::Perl;
19
20 use Test::More tests => 4;
21
22 use Koha::Report;
23 use Koha::Reports;
24 use Koha::Database;
25
26 use t::lib::TestBuilder;
27
28 my $schema = Koha::Database->new->schema;
29 $schema->storage->txn_begin;
30
31 my $builder = t::lib::TestBuilder->new;
32 my $nb_of_reports = Koha::Reports->search->count;
33 my $new_report_1 = Koha::Report->new({
34     report_name => 'report_name_for_test_1',
35     savedsql => 'SELECT "I wrote a report"',
36 })->store;
37 my $new_report_2 = Koha::Report->new({
38     report_name => 'report_name_for_test_1',
39     savedsql => 'SELECT "Oops, I did it again"',
40 })->store;
41
42 like( $new_report_1->id, qr|^\d+$|, 'Adding a new report should have set the id');
43 is( Koha::Reports->search->count, $nb_of_reports + 2, 'The 2 reports should have been added' );
44
45 my $retrieved_report_1 = Koha::Reports->find( $new_report_1->id );
46 is( $retrieved_report_1->report_name, $new_report_1->report_name, 'Find a report by id should return the correct report' );
47
48 $retrieved_report_1->delete;
49 is( Koha::Reports->search->count, $nb_of_reports + 1, 'Delete should have deleted the report' );
50
51 $schema->storage->txn_rollback;