Lines 50-63
is( Koha::Reports->search->count, $nb_of_reports + 1, 'Delete should have delete
Link Here
|
50 |
|
50 |
|
51 |
$schema->storage->txn_rollback; |
51 |
$schema->storage->txn_rollback; |
52 |
|
52 |
|
53 |
subtest 'validate_sql' => sub { |
53 |
subtest 'is_sql_valid' => sub { |
54 |
plan tests => 3 + 6*2; |
54 |
plan tests => 3 + 6 * 2; |
55 |
my @badwords = ('UPDATE', 'DELETE', 'DROP', 'INSERT', 'SHOW', 'CREATE'); |
55 |
my @badwords = ( 'UPDATE', 'DELETE', 'DROP', 'INSERT', 'SHOW', 'CREATE' ); |
56 |
is_deeply( Koha::Reports->validate_sql(), [{ queryerr => 'Missing SELECT'}], 'Empty sql is missing SELECT' ); |
56 |
is_deeply( |
57 |
is_deeply( Koha::Reports->validate_sql('FOO'), [{ queryerr => 'Missing SELECT'}], 'Nonsense sql is missing SELECT' ); |
57 |
[ Koha::Report->new( { savedsql => '' } )->is_sql_valid ], |
58 |
is_deeply( Koha::Reports->validate_sql('select FOO'), [], 'select FOO is good' ); |
58 |
[ 0, [ { queryerr => 'Missing SELECT' } ] ], |
|
|
59 |
'Empty sql is missing SELECT' |
60 |
); |
61 |
is_deeply( |
62 |
[ Koha::Report->new( { savedsql => 'FOO' } )->is_sql_valid ], |
63 |
[ 0, [ { queryerr => 'Missing SELECT' } ] ], |
64 |
'Nonsense sql is missing SELECT' |
65 |
); |
66 |
is_deeply( |
67 |
[ Koha::Report->new( { savedsql => 'select FOO' } )->is_sql_valid ], |
68 |
[ 1, [] ], |
69 |
'select FOO is good' |
70 |
); |
59 |
foreach my $word (@badwords) { |
71 |
foreach my $word (@badwords) { |
60 |
is_deeply( Koha::Reports->validate_sql('select FOO;'.$word.' BAR'), [{ sqlerr => $word}], 'select FOO with '.$word.' BAR' ); |
72 |
is_deeply( |
61 |
is_deeply( Koha::Reports->validate_sql($word.' qux'), [{ sqlerr => $word}], $word.' qux' ); |
73 |
[ |
|
|
74 |
Koha::Report->new( |
75 |
{ savedsql => 'select FOO;' . $word . ' BAR' } |
76 |
)->is_sql_valid |
77 |
], |
78 |
[ 0, [ { sqlerr => $word } ] ], |
79 |
'select FOO with ' . $word . ' BAR' |
80 |
); |
81 |
is_deeply( |
82 |
[ |
83 |
Koha::Report->new( { savedsql => $word . ' qux' } ) |
84 |
->is_sql_valid |
85 |
], |
86 |
[ 0, [ { sqlerr => $word } ] ], |
87 |
$word . ' qux' |
88 |
); |
62 |
} |
89 |
} |
63 |
} |
90 |
} |
64 |
- |
|
|