View | Details | Raw Unified | Return to bug 14719
Collapse All | Expand All

(-)a/t/db_dependent/Members/statistics.t (-1 / +77 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2015 Open Source Freedom Fighters
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Test::More;
23
use Try::Tiny; #Even Selenium::Remote::Driver uses Try::Tiny :)
24
use Scalar::Util qw(blessed);
25
26
use t::lib::Page::Members::Statistics;
27
use t::lib::TestObjects::BorrowerFactory;
28
use t::lib::TestObjects::CheckoutFactory;
29
use Koha::Auth::PermissionManager;
30
31
$ENV{KOHA_PAGEOBJECT_DEBUG} = 1;
32
33
subtest "Show Borrower Statistics" => \&showBorrowerStatistics;
34
sub showBorrowerStatistics {
35
    ##Setting up the test context
36
    my $subtestContext = {};
37
38
    eval { #run in a eval-block so we don't die without tearing down the test context
39
    ##Create the test Borrower
40
    my $password = '1234';
41
    my $borrowerFactory = t::lib::TestObjects::BorrowerFactory->new();
42
    my $borrowers = $borrowerFactory->createTestGroup(
43
                            {cardnumber => '1A01',
44
                             branchcode => 'CPL',
45
                             userid     => 'mini_admin',
46
                             password   => $password,
47
                            },
48
                            , undef, $subtestContext);
49
    my $permissionManager = Koha::Auth::PermissionManager->new();
50
    $permissionManager->grantPermissions($borrowers->{'1A01'}, {borrowers => 'view_borrowers',});
51
52
    ##Test context set, starting testing:
53
    my $statistics = t::lib::Page::Members::Statistics->new({borrowernumber => $borrowers->{'1A01'}->borrowernumber});
54
    $statistics->doPasswordLogin($borrowers->{'1A01'}->userid, $password)->isStatisticsRows([]); #We shouldn't have any statistics
55
56
    ##Checkout two Items
57
    my $checkouts = t::lib::TestObjects::CheckoutFactory->createTestGroup(
58
                            [   {barcode => 'Item021T',
59
                                 cardnumber => '1A01',
60
                                },
61
                                {barcode => 'Item022T',
62
                                 cardnumber => '1A01',
63
                                },
64
                            ],
65
                            undef, $subtestContext);
66
67
    ##We should have one statistics row.
68
    $statistics->refresh()->isStatisticsRows([{todaysCheckouts => 2}]);
69
70
    };
71
    if ($@) { #Catch all leaking errors and gracefully terminate.
72
        warn $@;
73
    }
74
    t::lib::TestObjects::ObjectFactory->tearDownTestContext($subtestContext);
75
}
76
77
done_testing;

Return to bug 14719