|
Lines 7-57
use strict;
Link Here
|
| 7 |
use warnings; |
7 |
use warnings; |
| 8 |
use C4::Context; |
8 |
use C4::Context; |
| 9 |
|
9 |
|
| 10 |
use Test::More tests => 8; |
10 |
use Test::More tests => 4; |
|
|
11 |
use DateTime::Format::MySQL; |
| 12 |
|
| 13 |
eval {use Test::Deep;}; |
| 11 |
|
14 |
|
| 12 |
BEGIN { |
15 |
BEGIN { |
| 13 |
use_ok('C4::Koha'); |
16 |
use_ok('C4::Koha'); |
| 14 |
use_ok('C4::Members'); |
17 |
use_ok('C4::Members'); |
| 15 |
} |
18 |
} |
| 16 |
|
19 |
|
| 17 |
my $data = { |
|
|
| 18 |
category => 'CATEGORY', |
| 19 |
authorised_value => 'AUTHORISED_VALUE', |
| 20 |
lib => 'LIB', |
| 21 |
lib_opac => 'LIBOPAC', |
| 22 |
imageurl => 'IMAGEURL' |
| 23 |
}; |
| 24 |
|
| 25 |
my $dbh = C4::Context->dbh; |
20 |
my $dbh = C4::Context->dbh; |
| 26 |
|
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 |
|
| 27 |
# Insert an entry into authorised_value table |
34 |
# Insert an entry into authorised_value table |
| 28 |
my $query = "INSERT INTO authorised_values (category, authorised_value, lib, lib_opac, imageurl) VALUES (?,?,?,?,?);"; |
35 |
my $query = "INSERT INTO authorised_values (category, authorised_value, lib, lib_opac, imageurl) VALUES (?,?,?,?,?);"; |
| 29 |
my $sth = $dbh->prepare($query); |
36 |
my $sth = $dbh->prepare($query); |
| 30 |
my $insert_success = $sth->execute($data->{category}, $data->{authorised_value}, $data->{lib}, $data->{lib_opac}, $data->{imageurl}); |
37 |
my $insert_success = $sth->execute($data->{category}, $data->{authorised_value}, $data->{lib}, $data->{lib_opac}, $data->{imageurl}); |
| 31 |
ok($insert_success, "Insert data in database"); |
38 |
ok($insert_success, "Insert data in database"); |
| 32 |
|
39 |
|
| 33 |
|
40 |
|
| 34 |
# Tests |
41 |
# Tests |
| 35 |
SKIP: { |
42 |
SKIP: { |
| 36 |
skip "INSERT failed", 5 unless $insert_success; |
43 |
skip "INSERT failed", 5 unless $insert_success; |
| 37 |
|
|
|
| 38 |
is ( GetAuthorisedValueByCode($data->{category}, $data->{authorised_value}), $data->{lib}, "GetAuthorisedValueByCode" ); |
| 39 |
is ( GetKohaImageurlFromAuthorisedValues($data->{category}, $data->{lib}), $data->{imageurl}, "GetKohaImageurlFromAuthorisedValues" ); |
| 40 |
|
44 |
|
| 41 |
my $sortdet=C4::Members::GetSortDetails("lost", "3"); |
45 |
is ( GetAuthorisedValueByCode($data->{category}, $data->{authorised_value}), $data->{lib}, "GetAuthorisedValueByCode" ); |
| 42 |
is ($sortdet, "Lost and Paid For", "lost and paid works"); |
46 |
is ( GetKohaImageurlFromAuthorisedValues($data->{category}, $data->{lib}), $data->{imageurl}, "GetKohaImageurlFromAuthorisedValues" ); |
| 43 |
|
47 |
|
| 44 |
my $sortdet2=C4::Members::GetSortDetails("loc", "child"); |
48 |
my $sortdet=C4::Members::GetSortDetails("lost", "3"); |
| 45 |
is ($sortdet2, "Children's Area", "Child area works"); |
49 |
is ($sortdet, "Lost and Paid For", "lost and paid works"); |
| 46 |
|
50 |
|
| 47 |
my $sortdet3=C4::Members::GetSortDetails("withdrawn", "1"); |
51 |
my $sortdet2=C4::Members::GetSortDetails("loc", "child"); |
| 48 |
is ($sortdet3, "Withdrawn", "Withdrawn works"); |
52 |
is ($sortdet2, "Children's Area", "Child area works"); |
| 49 |
} |
53 |
|
|
|
54 |
my $sortdet3=C4::Members::GetSortDetails("withdrawn", "1"); |
| 55 |
is ($sortdet3, "Withdrawn", "Withdrawn works"); |
| 56 |
} |
| 50 |
|
57 |
|
| 51 |
# Clean up |
58 |
# Clean up |
| 52 |
if($insert_success){ |
59 |
if($insert_success){ |
| 53 |
$query = "DELETE FROM authorised_values WHERE category=? AND authorised_value=? AND lib=? AND lib_opac=? AND imageurl=?;"; |
60 |
$query = "DELETE FROM authorised_values WHERE category=? AND authorised_value=? AND lib=? AND lib_opac=? AND imageurl=?;"; |
| 54 |
$sth = $dbh->prepare($query); |
61 |
$sth = $dbh->prepare($query); |
| 55 |
$sth->execute($data->{category}, $data->{authorised_value}, $data->{lib}, $data->{lib_opac}, $data->{imageurl}); |
62 |
$sth->execute($data->{category}, $data->{authorised_value}, $data->{lib}, $data->{lib_opac}, $data->{imageurl}); |
| 56 |
} |
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: { |
| 57 |
|
74 |
|
| 58 |
- |
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 = C4::Koha->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 = C4::Koha->GetDailyQuote('random'=>1); |
| 93 |
ok ($quote, "Got a random quote."); |
| 94 |
|
| 95 |
# test quote retrieval based on today's date |
| 96 |
|
| 97 |
my $query = 'UPDATE quotes SET timestamp = ? WHERE id = ?'; |
| 98 |
my $sth = C4::Context->dbh->prepare($query); |
| 99 |
$sth->execute(DateTime::Format::MySQL->format_datetime(DateTime->now), $expected_quote->{'id'}); |
| 100 |
|
| 101 |
DateTime::Format::MySQL->format_datetime(DateTime->now) =~ m/(\d{4}-\d{2}-\d{2})/; |
| 102 |
$expected_quote->{'timestamp'} = re("^$1"); |
| 103 |
|
| 104 |
# $expected_quote->{'timestamp'} = DateTime::Format::MySQL->format_datetime(DateTime->now); # update the timestamp of expected quote data |
| 105 |
|
| 106 |
$quote = C4::Koha->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 |
} |