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

(-)a/t/Koha.t (-2 / +34 lines)
Lines 2-11 Link Here
2
use strict;
2
use strict;
3
use warnings;
3
use warnings;
4
4
5
use Test::More tests => 8;
5
use C4::Context;
6
use Test::More tests => 11;
7
use Test::MockModule;
8
use DBD::Mock;
6
9
7
use_ok('C4::Koha');
10
use_ok('C4::Koha');
8
11
12
my $module_context = new Test::MockModule('C4::Context');
13
$module_context->mock(
14
    '_new_dbh',
15
    sub {
16
        my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
17
          || die "Cannot create handle: $DBI::errstr\n";
18
        return $dbh;
19
    }
20
);
21
22
SKIP: {
23
24
    skip "DBD::Mock is too old", 8
25
        unless $DBD::Mock::VERSION >= 1.45;
26
27
    my @loc_results = (['category'],['LOC']);
28
    my @empty_results = ([]);
29
    my @relterms_results = (['category'],['RELTERMS']);
30
31
    my $dbh = C4::Context->dbh();
32
    
33
    $dbh->{mock_add_resultset} = \@loc_results;
34
    is ( IsAuthorisedValueCategory('LOC'), 1, 'LOC is a valid authorized value category');
35
    $dbh->{mock_add_resultset} = \@empty_results;
36
    is ( IsAuthorisedValueCategory('something'), 0, 'something is not a valid authorized value category');
37
    $dbh->{mock_add_resultset} = \@relterms_results;
38
    is ( IsAuthorisedValueCategory('RELTERMS'), 1, 'RELTERMS is a valid authorized value category');
39
40
} # End SKIP block
41
9
#
42
#
10
# test that &slashifyDate returns correct (non-US) date
43
# test that &slashifyDate returns correct (non-US) date
11
#
44
#
Lines 28-31 is(C4::Koha::_isbn_cleanup('0-590-35340-3'), '0590353403', '_isbn_cleanup remove Link Here
28
is(C4::Koha::_isbn_cleanup('0590353403 (pbk.)'), '0590353403', '_isbn_cleanup removes parenthetical');
61
is(C4::Koha::_isbn_cleanup('0590353403 (pbk.)'), '0590353403', '_isbn_cleanup removes parenthetical');
29
is(C4::Koha::_isbn_cleanup('978-0-321-49694-2'), '0321496949', '_isbn_cleanup converts ISBN-13 to ISBN-10');
62
is(C4::Koha::_isbn_cleanup('978-0-321-49694-2'), '0321496949', '_isbn_cleanup converts ISBN-13 to ISBN-10');
30
63
31
(-)a/t/ReportsGuided.t (-1 / +111 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
5
use Test::More tests => 12;
6
use Test::MockModule;
7
use DBD::Mock;
8
9
use_ok('C4::Reports::Guided');
10
11
my $context = new Test::MockModule('C4::Context');
12
my $koha = new Test::MockModule('C4::Koha');
13
14
$context->mock(
15
    '_new_dbh',
16
    sub {
17
        my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
18
          || die "Cannot create handle: $DBI::errstr\n";
19
        return $dbh;
20
    }
21
);
22
23
24
sub MockedIsAuthorisedValueCategory {
25
    my $authorised_value = shift;
26
27
    if ( $authorised_value eq 'LOC' ) {
28
        return 1;
29
    } else {
30
        return 0;
31
    }
32
}
33
34
$koha->mock(
35
    'IsAuthorisedValueCategory',
36
    \&MockedIsAuthorisedValueCategory
37
);
38
39
{   # GetReservedAuthorisedValues tests
40
    # This one will catch new reserved words not added
41
    # to GetReservedAuthorisedValues
42
    my %test_authval = (
43
        'date' => 1,
44
        'branches' => 1,
45
        'itemtypes' => 1,
46
        'cn_source' => 1,
47
        'categorycode' => 1
48
    );
49
50
    my $reserved_authorised_values = GetReservedAuthorisedValues();
51
    is_deeply(\%test_authval, $reserved_authorised_values,
52
                'GetReservedAuthorisedValues returns a fixed list');
53
}
54
55
SKIP: {
56
57
    skip "DBD::Mock is too old", 6
58
        unless $DBD::Mock::VERSION >= 1.45;
59
60
    ok( IsAuthorisedValueValid('LOC'),
61
        'User defined authorised value category is valid');
62
63
    ok( ! IsAuthorisedValueValid('XXX'),
64
        'Not defined authorised value category is invalid');
65
66
    # Loop through the reserved authorised values
67
    foreach my $authorised_value ( keys GetReservedAuthorisedValues() ) {
68
        ok( IsAuthorisedValueValid($authorised_value),
69
            '\''.$authorised_value.'\' is a reserved word, and thus a valid authorised value');
70
    }
71
}
72
73
{   # GetParametersFromSQL tests
74
75
    my $test_query_1 = "
76
        SELECT date_due
77
        FROM old_issues
78
        WHERE YEAR(timestamp) = <<Year|custom_list>> AND
79
              branchcode = <<Branch|branches>> AND
80
              borrowernumber = <<Borrower>>
81
    ";
82
83
    my @test_parameters_with_custom_list = (
84
        { 'name' => 'Year', 'authval' => 'custom_list' }, 
85
        { 'name' => 'Branch', 'authval' => 'branches' },
86
        { 'name' => 'Borrower', 'authval' => undef }
87
    );
88
89
    is_deeply( GetParametersFromSQL($test_query_1), \@test_parameters_with_custom_list,
90
        'SQL params are correctly parsed');
91
92
    # ValidateSQLParameters tests
93
    my @problematic_parameters = ();
94
    push @problematic_parameters, { 'name' => 'Year', 'authval' => 'custom_list' };
95
    is_deeply( ValidateSQLParameters( $test_query_1 ),
96
               \@problematic_parameters,
97
               '\'custom_list\' not a valid category' );
98
99
    my $test_query_2 = "
100
        SELECT date_due
101
        FROM old_issues
102
        WHERE YEAR(timestamp) = <<Year|date>> AND
103
              branchcode = <<Branch|branches>> AND
104
              borrowernumber = <<Borrower|LOC>>
105
    ";
106
107
    is_deeply( ValidateSQLParameters( $test_query_2 ),
108
        [],
109
        'All parameters valid, empty problematic authvals list');
110
}
111

Return to bug 9659