Lines 234-249
subtest 'get_saved_reports' => sub {
Link Here
|
234 |
is( scalar @{ get_saved_reports() }, |
234 |
is( scalar @{ get_saved_reports() }, |
235 |
$count, "Report2 and report3 have been deleted" ); |
235 |
$count, "Report2 and report3 have been deleted" ); |
236 |
|
236 |
|
237 |
my $sth = execute_query('SELECT COUNT(*) FROM systempreferences', 0, 10); |
237 |
my $sth = execute_query( |
|
|
238 |
{ |
239 |
sql => 'SELECT COUNT(*) FROM systempreferences', |
240 |
offset => 0, |
241 |
limit => 10, |
242 |
} |
243 |
); |
238 |
my $results = $sth->fetchall_arrayref; |
244 |
my $results = $sth->fetchall_arrayref; |
239 |
is(scalar @$results, 1, 'running a query returned a result'); |
245 |
is(scalar @$results, 1, 'running a query returned a result'); |
240 |
|
246 |
|
241 |
my $version = C4::Context->preference('Version'); |
247 |
my $version = C4::Context->preference('Version'); |
242 |
$sth = execute_query( |
248 |
$sth = execute_query( |
243 |
'SELECT value FROM systempreferences WHERE variable = ?', |
249 |
{ |
244 |
0, |
250 |
sql => 'SELECT value FROM systempreferences WHERE variable = ?', |
245 |
10, |
251 |
offset => 0, |
246 |
[ 'Version' ], |
252 |
limit => 10, |
|
|
253 |
sql_params => ['Version'], |
254 |
} |
247 |
); |
255 |
); |
248 |
$results = $sth->fetchall_arrayref; |
256 |
$results = $sth->fetchall_arrayref; |
249 |
is_deeply( |
257 |
is_deeply( |
Lines 254-264
subtest 'get_saved_reports' => sub {
Link Here
|
254 |
|
262 |
|
255 |
# for next test, we want to let execute_query capture any SQL errors |
263 |
# for next test, we want to let execute_query capture any SQL errors |
256 |
my $errors; |
264 |
my $errors; |
257 |
warning_like {local $dbh->{RaiseError} = 0; ($sth, $errors) = execute_query( |
265 |
warning_like { |
258 |
'SELECT surname FRM borrowers', # error in the query is intentional |
266 |
local $dbh->{RaiseError} = 0; |
259 |
0, 10 ) } |
267 |
( $sth, $errors ) = execute_query( |
260 |
qr/DBD::mysql::st execute failed: You have an error in your SQL syntax;/, |
268 |
{ |
261 |
"Wrong SQL syntax raises warning"; |
269 |
sql => 'SELECT surname FRM borrowers', # error in the query is intentional |
|
|
270 |
offset => 0, |
271 |
limit => 10, |
272 |
} |
273 |
) |
274 |
} |
275 |
qr/DBD::mysql::st execute failed: You have an error in your SQL syntax;/, |
276 |
"Wrong SQL syntax raises warning"; |
262 |
ok( |
277 |
ok( |
263 |
defined($errors) && exists($errors->{queryerr}), |
278 |
defined($errors) && exists($errors->{queryerr}), |
264 |
'attempting to run a report with an SQL syntax error returns error message (Bug 12214)' |
279 |
'attempting to run a report with an SQL syntax error returns error message (Bug 12214)' |
Lines 283-296
subtest 'Ensure last_run is populated' => sub {
Link Here
|
283 |
|
298 |
|
284 |
is( $report->last_run, undef, 'Newly created report has null last_run ' ); |
299 |
is( $report->last_run, undef, 'Newly created report has null last_run ' ); |
285 |
|
300 |
|
286 |
execute_query( $report->savedsql, undef, undef, undef, $report->id ); |
301 |
execute_query( { sql => $report->savedsql, report_id => $report->id } ); |
287 |
$report->discard_changes(); |
302 |
$report->discard_changes(); |
288 |
|
303 |
|
289 |
isnt( $report->last_run, undef, 'First run of report populates last_run' ); |
304 |
isnt( $report->last_run, undef, 'First run of report populates last_run' ); |
290 |
|
305 |
|
291 |
my $previous_last_run = $report->last_run; |
306 |
my $previous_last_run = $report->last_run; |
292 |
sleep(1); # last_run is stored to the second, so we need to ensure at least one second has passed between runs |
307 |
sleep(1); # last_run is stored to the second, so we need to ensure at least one second has passed between runs |
293 |
execute_query( $report->savedsql, undef, undef, undef, $report->id ); |
308 |
execute_query( { sql => $report->savedsql, report_id => $report->id } ); |
294 |
$report->discard_changes(); |
309 |
$report->discard_changes(); |
295 |
|
310 |
|
296 |
isnt( $report->last_run, $previous_last_run, 'Second run of report updates last_run' ); |
311 |
isnt( $report->last_run, $previous_last_run, 'Second run of report updates last_run' ); |
297 |
- |
|
|