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