|
Lines 17-28
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 7; |
20 |
use Test::More tests => 8; |
| 21 |
|
21 |
|
| 22 |
use Koha::Report; |
22 |
use Koha::Report; |
| 23 |
use Koha::Reports; |
23 |
use Koha::Reports; |
| 24 |
use Koha::Database; |
24 |
use Koha::Database; |
| 25 |
|
25 |
|
|
|
26 |
use t::lib::Mocks; |
| 26 |
use t::lib::TestBuilder; |
27 |
use t::lib::TestBuilder; |
| 27 |
|
28 |
|
| 28 |
my $schema = Koha::Database->new->schema; |
29 |
my $schema = Koha::Database->new->schema; |
|
Lines 136-139
subtest 'check_columns' => sub {
Link Here
|
| 136 |
); |
137 |
); |
| 137 |
}; |
138 |
}; |
| 138 |
|
139 |
|
|
|
140 |
subtest '_might_add_limit' => sub { |
| 141 |
plan tests => 10; |
| 142 |
|
| 143 |
my $sql; |
| 144 |
|
| 145 |
t::lib::Mocks::mock_preference( 'GuidedReportsExportLimit', undef ); # i.e. no limit |
| 146 |
$sql = "SELECT * FROM biblio WHERE 1"; |
| 147 |
is( Koha::Report->_might_add_limit($sql), $sql, 'Pref is undefined, no changes' ); |
| 148 |
t::lib::Mocks::mock_preference( 'GuidedReportsExportLimit', 0 ); # i.e. no limit |
| 149 |
is( Koha::Report->_might_add_limit($sql), $sql, 'Pref is zero, no changes' ); |
| 150 |
t::lib::Mocks::mock_preference( 'GuidedReportsExportLimit', q{} ); # i.e. no limit |
| 151 |
is( Koha::Report->_might_add_limit($sql), $sql, 'Pref is empty, no changes' ); |
| 152 |
t::lib::Mocks::mock_preference( 'GuidedReportsExportLimit', 10 ); |
| 153 |
like( Koha::Report->_might_add_limit($sql), qr/ LIMIT 10$/, 'Limit 10 found at the end' ); |
| 154 |
$sql = "SELECT * FROM biblio WHERE 1 LIMIT 1000 "; |
| 155 |
is( Koha::Report->_might_add_limit($sql), $sql, 'Already contains a limit' ); |
| 156 |
$sql = "SELECT * FROM biblio WHERE 1 LIMIT 1000,2000"; |
| 157 |
is( Koha::Report->_might_add_limit($sql), $sql, 'Variation, also contains a limit' ); |
| 158 |
|
| 159 |
# trying a subquery having a limit (testing the lookahead in regex) |
| 160 |
$sql = "SELECT * FROM biblio WHERE biblionumber IN (SELECT biblionumber FROM reserves LIMIT 2)"; |
| 161 |
like( Koha::Report->_might_add_limit($sql), qr/ LIMIT 10$/, 'Subquery, limit 10 found at the end' ); |
| 162 |
$sql = "SELECT * FROM biblio WHERE biblionumber IN (SELECT biblionumber FROM reserves LIMIT 2, 3 ) AND 1"; |
| 163 |
like( Koha::Report->_might_add_limit($sql), qr/ LIMIT 10$/, 'Subquery variation, limit 10 found at the end' ); |
| 164 |
$sql = "select * from biblio where biblionumber in (select biblionumber from reserves limiT 3,4) and 1"; |
| 165 |
like( Koha::Report->_might_add_limit($sql), qr/ LIMIT 10$/, 'Subquery lc variation, limit 10 found at the end' ); |
| 166 |
|
| 167 |
$sql = "select limit, 22 from mylimits where limit between 1 and 3"; |
| 168 |
like( |
| 169 |
Koha::Report->_might_add_limit($sql), qr/ LIMIT 10$/, |
| 170 |
'Query refers to limit field, limit 10 found at the end' |
| 171 |
); |
| 172 |
}; |
| 173 |
|
| 139 |
$schema->storage->txn_rollback; |
174 |
$schema->storage->txn_rollback; |
| 140 |
- |
|
|