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

(-)a/t/Koha.t (-31 lines)
Lines 1-31 Link Here
1
#!/usr/bin/perl
2
use strict;
3
use warnings;
4
5
use Test::More tests => 8;
6
7
use_ok('C4::Koha');
8
9
#
10
# test that &slashifyDate returns correct (non-US) date
11
#
12
my $date = "01/01/2002";
13
my $newdate = &slashifyDate("2002-01-01");
14
my $isbn13 = "9780330356473";
15
my $isbn13D = "978-0-330-35647-3";
16
my $isbn10 = "033035647X";
17
my $isbn10D = "0-330-35647-X";
18
19
ok($date eq $newdate, 'slashifyDate');
20
21
my $undef = undef;
22
is(xml_escape($undef), '', 'xml_escape() returns empty string on undef input');
23
my $str = q{'"&<>'};
24
is(xml_escape($str), '&apos;&quot;&amp;&lt;&gt;&apos;', 'xml_escape() works as expected');
25
is($str, q{'"&<>'}, '... and does not change input in place');
26
27
is(C4::Koha::_isbn_cleanup('0-590-35340-3'), '0590353403', '_isbn_cleanup removes hyphens');
28
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');
30
31
(-)a/t/db_dependent/Koha.t (-101 / +20 lines)
Lines 1-111 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
#
3
# This is to test C4/Koha
4
# It requires a working Koha database with the sample data
5
6
use strict;
2
use strict;
7
use warnings;
3
use warnings;
8
use C4::Context;
9
10
use Test::More tests => 4;
11
use DateTime::Format::MySQL;
12
13
eval {use Test::Deep;};
14
15
BEGIN {
16
    use_ok('C4::Koha', qw( :DEFAULT GetDailyQuote ));
17
    use_ok('C4::Members');
18
}
19
20
my $dbh = C4::Context->dbh;
21
22
subtest 'Authorized Values Tests' => sub {
23
    plan tests => 6;
24
25
    my $data = {
26
        category            => 'CATEGORY',
27
        authorised_value    => 'AUTHORISED_VALUE',
28
        lib                 => 'LIB',
29
        lib_opac            => 'LIBOPAC',
30
        imageurl            => 'IMAGEURL'
31
    };
32
33
34
# Insert an entry into authorised_value table
35
    my $query = "INSERT INTO authorised_values (category, authorised_value, lib, lib_opac, imageurl) VALUES (?,?,?,?,?);";
36
    my $sth = $dbh->prepare($query);
37
    my $insert_success = $sth->execute($data->{category}, $data->{authorised_value}, $data->{lib}, $data->{lib_opac}, $data->{imageurl});
38
    ok($insert_success, "Insert data in database");
39
40
41
# Tests
42
    SKIP: {
43
        skip "INSERT failed", 5 unless $insert_success;
44
4
45
        is ( GetAuthorisedValueByCode($data->{category}, $data->{authorised_value}), $data->{lib}, "GetAuthorisedValueByCode" );
5
use Test::More tests => 8;
46
        is ( GetKohaImageurlFromAuthorisedValues($data->{category}, $data->{lib}), $data->{imageurl}, "GetKohaImageurlFromAuthorisedValues" );
47
6
48
        my $sortdet=C4::Members::GetSortDetails("lost", "3");
7
use_ok('C4::Koha');
49
        is ($sortdet, "Lost and Paid For", "lost and paid works");
50
8
51
        my $sortdet2=C4::Members::GetSortDetails("loc", "child");
9
#
52
        is ($sortdet2, "Children's Area", "Child area works");
10
# test that &slashifyDate returns correct (non-US) date
53
11
#
54
        my $sortdet3=C4::Members::GetSortDetails("withdrawn", "1");
12
my $date = "01/01/2002";
55
        is ($sortdet3, "Withdrawn", "Withdrawn works");
13
my $newdate = &slashifyDate("2002-01-01");
56
    }
14
my $isbn13 = "9780330356473";
57
15
my $isbn13D = "978-0-330-35647-3";
58
# Clean up
16
my $isbn10 = "033035647X";
59
    if($insert_success){
17
my $isbn10D = "0-330-35647-X";
60
        $query = "DELETE FROM authorised_values WHERE category=? AND authorised_value=? AND lib=? AND lib_opac=? AND imageurl=?;";
61
        $sth = $dbh->prepare($query);
62
        $sth->execute($data->{category}, $data->{authorised_value}, $data->{lib}, $data->{lib_opac}, $data->{imageurl});
63
    }
64
};
65
### test for C4::Koha->GetDailyQuote()
66
SKIP:
67
    {
68
        skip "Test::Deep required to run the GetDailyQuote tests.", 1 if $@;
69
70
        subtest 'Daily Quotes Test' => sub {
71
            plan tests => 4;
72
73
            SKIP: {
74
75
                skip "C4::Koha can't \'GetDailyQuote\'!", 3 unless can_ok('C4::Koha','GetDailyQuote');
76
77
                my $expected_quote = {
78
                    id          => 3,
79
                    source      => 'Abraham Lincoln',
80
                    text        => 'Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.',
81
                    timestamp   => re('\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}'),   #'0000-00-00 00:00:00',
82
                };
83
84
# test quote retrieval based on id
85
86
                my $quote = GetDailyQuote('id'=>3);
87
                cmp_deeply ($quote, $expected_quote, "Got a quote based on id.") or
88
                    diag('Be sure to run this test on a clean install of sample data.');
89
90
# test random quote retrieval
91
92
                $quote = GetDailyQuote('random'=>1);
93
                ok ($quote, "Got a random quote.");
94
18
95
# test quote retrieval based on today's date
19
ok($date eq $newdate, 'slashifyDate');
96
20
97
                my $query = 'UPDATE quotes SET timestamp = ? WHERE id = ?';
21
my $undef = undef;
98
                my $sth = C4::Context->dbh->prepare($query);
22
is(xml_escape($undef), '', 'xml_escape() returns empty string on undef input');
99
                $sth->execute(DateTime::Format::MySQL->format_datetime(DateTime->now), $expected_quote->{'id'});
23
my $str = q{'"&<>'};
24
is(xml_escape($str), '&apos;&quot;&amp;&lt;&gt;&apos;', 'xml_escape() works as expected');
25
is($str, q{'"&<>'}, '... and does not change input in place');
100
26
101
                DateTime::Format::MySQL->format_datetime(DateTime->now) =~ m/(\d{4}-\d{2}-\d{2})/;
27
is(C4::Koha::_isbn_cleanup('0-590-35340-3'), '0590353403', '_isbn_cleanup removes hyphens');
102
                $expected_quote->{'timestamp'} = re("^$1");
28
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');
103
30
104
#        $expected_quote->{'timestamp'} = DateTime::Format::MySQL->format_datetime(DateTime->now);   # update the timestamp of expected quote data
105
31
106
                $quote = GetDailyQuote(); # this is the "default" mode of selection
107
                cmp_deeply ($quote, $expected_quote, "Got a quote based on today's date.") or
108
                    diag('Be sure to run this test on a clean install of sample data.');
109
            }
110
        };
111
}
112
- 

Return to bug 5327