Lines 71-84
subtest 'prep_report' => sub {
Link Here
|
71 |
|
71 |
|
72 |
$schema->storage->txn_rollback; |
72 |
$schema->storage->txn_rollback; |
73 |
|
73 |
|
74 |
subtest 'validate_sql' => sub { |
74 |
subtest 'is_sql_valid' => sub { |
75 |
plan tests => 3 + 6*2; |
75 |
plan tests => 3 + 6 * 2; |
76 |
my @badwords = ('UPDATE', 'DELETE', 'DROP', 'INSERT', 'SHOW', 'CREATE'); |
76 |
my @badwords = ( 'UPDATE', 'DELETE', 'DROP', 'INSERT', 'SHOW', 'CREATE' ); |
77 |
is_deeply( Koha::Reports->validate_sql(), [{ queryerr => 'Missing SELECT'}], 'Empty sql is missing SELECT' ); |
77 |
is_deeply( |
78 |
is_deeply( Koha::Reports->validate_sql('FOO'), [{ queryerr => 'Missing SELECT'}], 'Nonsense sql is missing SELECT' ); |
78 |
[ Koha::Report->new( { savedsql => '' } )->is_sql_valid ], |
79 |
is_deeply( Koha::Reports->validate_sql('select FOO'), [], 'select FOO is good' ); |
79 |
[ 0, [ { queryerr => 'Missing SELECT' } ] ], |
|
|
80 |
'Empty sql is missing SELECT' |
81 |
); |
82 |
is_deeply( |
83 |
[ Koha::Report->new( { savedsql => 'FOO' } )->is_sql_valid ], |
84 |
[ 0, [ { queryerr => 'Missing SELECT' } ] ], |
85 |
'Nonsense sql is missing SELECT' |
86 |
); |
87 |
is_deeply( |
88 |
[ Koha::Report->new( { savedsql => 'select FOO' } )->is_sql_valid ], |
89 |
[ 1, [] ], |
90 |
'select FOO is good' |
91 |
); |
80 |
foreach my $word (@badwords) { |
92 |
foreach my $word (@badwords) { |
81 |
is_deeply( Koha::Reports->validate_sql('select FOO;'.$word.' BAR'), [{ sqlerr => $word}], 'select FOO with '.$word.' BAR' ); |
93 |
is_deeply( |
82 |
is_deeply( Koha::Reports->validate_sql($word.' qux'), [{ sqlerr => $word}], $word.' qux' ); |
94 |
[ |
|
|
95 |
Koha::Report->new( |
96 |
{ savedsql => 'select FOO;' . $word . ' BAR' } |
97 |
)->is_sql_valid |
98 |
], |
99 |
[ 0, [ { sqlerr => $word } ] ], |
100 |
'select FOO with ' . $word . ' BAR' |
101 |
); |
102 |
is_deeply( |
103 |
[ |
104 |
Koha::Report->new( { savedsql => $word . ' qux' } ) |
105 |
->is_sql_valid |
106 |
], |
107 |
[ 0, [ { sqlerr => $word } ] ], |
108 |
$word . ' qux' |
109 |
); |
83 |
} |
110 |
} |
84 |
} |
111 |
} |
85 |
- |
|
|