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

(-)a/t/db_dependent/Koha.t (-62 / +2 lines)
Lines 4-22 Link Here
4
# It requires a working Koha database with the sample data
4
# It requires a working Koha database with the sample data
5
5
6
use Modern::Perl;
6
use Modern::Perl;
7
use DateTime::Format::MySQL;
7
use Test::More tests => 5;
8
use Test::More tests => 6;
9
8
10
use t::lib::TestBuilder;
9
use t::lib::TestBuilder;
11
10
12
use C4::Context;
11
use C4::Context;
13
use Koha::Database;
12
use Koha::Database;
14
use Koha::DateUtils qw(dt_from_string);
15
use Koha::AuthorisedValue;
13
use Koha::AuthorisedValue;
16
use Koha::AuthorisedValueCategories;
14
use Koha::AuthorisedValueCategories;
17
15
18
BEGIN {
16
BEGIN {
19
    use_ok('C4::Koha', qw( :DEFAULT GetDailyQuote GetItemTypesCategorized));
17
    use_ok('C4::Koha', qw( :DEFAULT GetItemTypesCategorized));
20
    use_ok('C4::Members');
18
    use_ok('C4::Members');
21
}
19
}
22
20
Lines 157-219 subtest 'Authorized Values Tests' => sub { Link Here
157
155
158
};
156
};
159
157
160
### test for C4::Koha->GetDailyQuote()
161
SKIP:
162
    {
163
        eval { require Test::Deep; import Test::Deep; };
164
        skip "Test::Deep required to run the GetDailyQuote tests.", 1 if $@;
165
166
        subtest 'Daily Quotes Test' => sub {
167
            plan tests => 4;
168
169
            SKIP: {
170
171
                skip "C4::Koha can't \'GetDailyQuote\'!", 3 unless can_ok('C4::Koha','GetDailyQuote');
172
173
# Fill the quote table with the default needed and a spare
174
$dbh->do("DELETE FROM quotes WHERE id=3 OR id=25;");
175
my $sql = "INSERT INTO quotes (id,source,text,timestamp) VALUES
176
(25,'Richard Nixon','When the President does it, that means that it is not illegal.',NOW()),
177
(3,'Abraham Lincoln','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.',NOW());";
178
$dbh->do($sql);
179
180
                my $expected_quote = {
181
                    id          => 3,
182
                    source      => 'Abraham Lincoln',
183
                    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.',
184
                    timestamp   => re('\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}'),   #'YYYY-MM-DD HH:MM:SS'
185
                };
186
187
# test quote retrieval based on id
188
189
                my $quote = GetDailyQuote('id'=>3);
190
                cmp_deeply ($quote, $expected_quote, "Got a quote based on id.") or
191
                    diag('Be sure to run this test on a clean install of sample data.');
192
193
# test quote retrieval based on today's date
194
195
                my $query = 'UPDATE quotes SET timestamp = ? WHERE id = ?';
196
                my $sth = C4::Context->dbh->prepare($query);
197
                $sth->execute(DateTime::Format::MySQL->format_datetime( dt_from_string() ), $expected_quote->{'id'});
198
199
                DateTime::Format::MySQL->format_datetime( dt_from_string() ) =~ m/(\d{4}-\d{2}-\d{2})/;
200
                $expected_quote->{'timestamp'} = re("^$1");
201
202
#        $expected_quote->{'timestamp'} = DateTime::Format::MySQL->format_datetime( dt_from_string() );   # update the timestamp of expected quote data
203
204
                $quote = GetDailyQuote(); # this is the "default" mode of selection
205
                cmp_deeply ($quote, $expected_quote, "Got a quote based on today's date.") or
206
                    diag('Be sure to run this test on a clean install of sample data.');
207
208
# test random quote retrieval
209
210
                $quote = GetDailyQuote('random'=>1);
211
                ok ($quote, "Got a random quote.");
212
            }
213
        };
214
}
215
216
217
subtest 'ISBN tests' => sub {
158
subtest 'ISBN tests' => sub {
218
    plan tests => 6;
159
    plan tests => 6;
219
160
220
- 

Return to bug 16371