diff options
author | William Desportes <williamdes@wdes.fr> | 2021-04-24 20:01:26 +0300 |
---|---|---|
committer | William Desportes <williamdes@wdes.fr> | 2021-04-24 20:01:26 +0300 |
commit | d20f7f7d0ab502f00d3a4c9155c719dc146092b6 (patch) | |
tree | 281e87d0fab1f48a64a1203c74d288bc2d6d3a30 /test/classes/SqlTest.php | |
parent | b1e3bac4c5200edde2d8d20e26633e1a2af5ab77 (diff) | |
parent | e2dc122ce991b7fbe7b4715804ed2a3d3421794b (diff) |
Merge branch 'QA_5_1'
Signed-off-by: William Desportes <williamdes@wdes.fr>
Diffstat (limited to 'test/classes/SqlTest.php')
-rw-r--r-- | test/classes/SqlTest.php | 219 |
1 files changed, 218 insertions, 1 deletions
diff --git a/test/classes/SqlTest.php b/test/classes/SqlTest.php index 7d4b1373bd..32110a6210 100644 --- a/test/classes/SqlTest.php +++ b/test/classes/SqlTest.php @@ -313,7 +313,7 @@ class SqlTest extends AbstractTestCase /** * We can not say all the columns are from the same table if all the columns - * are funtion columns (table is '') + * are function columns (table is '') */ public function testWithOnlyFunctionColumns(): void { @@ -345,4 +345,221 @@ class SqlTest extends AbstractTestCase return $analyzedSqlResults; } + + public function dataProviderCountQueryResults(): array + { + // sql query + // session tmpval + // num rows + // result + // just browsing + return [ + [ + 'SELECT * FROM company_users WHERE id != 0 LIMIT 0, 10', + ['max_rows' => 250], + -1, + -1, + ], + [ + 'SELECT * FROM company_users WHERE id != 0', + [ + 'max_rows' => 250, + 'pos' => -1, + ], + -1, + -2, + ], + [ + 'SELECT * FROM company_users WHERE id != 0', + [ + 'max_rows' => 250, + 'pos' => -1, + ], + -1, + -2, + ], + [ + 'SELECT * FROM company_users WHERE id != 0', + [ + 'max_rows' => 250, + 'pos' => 250, + ], + -1, + 249, + ], + [ + 'SELECT * FROM company_users WHERE id != 0', + [ + 'max_rows' => 250, + 'pos' => 4, + ], + 2, + 6, + ], + [ + 'SELECT * FROM company_users WHERE id != 0', + [ + 'max_rows' => 'all', + 'pos' => 4, + ], + 2, + 2, + ], + [ + null, + [], + 2, + 0, + ], + [ + + 'SELECT * FROM company_users LIMIT 1,4', + [ + 'max_rows' => 10, + 'pos' => 4, + ], + 20, + 20, + + ], + [ + + 'SELECT * FROM company_users', + [ + 'max_rows' => 10, + 'pos' => 4, + ], + 20, + 4, + ], + [ + + 'SELECT * FROM company_users WHERE not_working_count != 0', + [ + 'max_rows' => 10, + 'pos' => 4, + ], + 20, + 0, + ], + [ + + 'SELECT * FROM company_users WHERE working_count = 0', + [ + 'max_rows' => 10, + 'pos' => 4, + ], + 20, + 15, + + ], + [ + 'UPDATE company_users SET a=1 WHERE working_count = 0', + [ + 'max_rows' => 10, + 'pos' => 4, + ], + 20, + 20, + ], + [ + 'UPDATE company_users SET a=1 WHERE working_count = 0', + [ + 'max_rows' => 'all', + 'pos' => 4, + ], + 20, + 20, + ], + [ + 'UPDATE company_users SET a=1 WHERE working_count = 0', + ['max_rows' => 15], + 20, + 20, + ], + [ + 'SELECT * FROM company_users WHERE id != 0', + [ + 'max_rows' => 250, + 'pos' => 4, + ], + 2, + 6, + true, + ], + [ + 'SELECT *, (SELECT COUNT(*) FROM tbl1) as c1, (SELECT 1 FROM tbl2) as c2 ' + . 'FROM company_users WHERE id != 0', + [ + 'max_rows' => 250, + 'pos' => 4, + ], + 2, + 6, + true, + ], + [ + + 'SELECT * FROM company_users', + [ + 'max_rows' => 10, + 'pos' => 4, + ], + 20, + 18, + true, + ], + [ + 'SELECT *, 1, (SELECT COUNT(*) FROM tbl1) as c1, ' + . '(SELECT 1 FROM tbl2) as c2 FROM company_users WHERE subquery_case = 0', + [ + 'max_rows' => 10, + 'pos' => 4, + ], + 20, + 42, + + ], + [ + 'SELECT ( as c2 FROM company_users WHERE working_count = 0',// Invalid query + ['max_rows' => 10], + 20, + 20, + + ], + ]; + } + + /** + * @dataProvider dataProviderCountQueryResults + */ + public function testCountQueryResults( + ?string $sqlQuery, + array $sessionTmpVal, + int $numRows, + int $expectedNumRows, + bool $justBrowsing = false + ): void { + if ($justBrowsing) { + $GLOBALS['cfg']['Server']['DisableIS'] = true; + } + + $_SESSION['tmpval'] = $sessionTmpVal; + + $analyzed_sql_results = $sqlQuery === null ? [] : $this->parseAndAnalyze($sqlQuery); + + $result = $this->callFunction( + $this->sql, + Sql::class, + 'countQueryResults', + [ + $numRows, + $justBrowsing, + 'my_dataset',// db + 'company_users',// table + $analyzed_sql_results, + ] + ); + $this->assertSame($expectedNumRows, $result); + } } |