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 | |
parent | b1e3bac4c5200edde2d8d20e26633e1a2af5ab77 (diff) | |
parent | e2dc122ce991b7fbe7b4715804ed2a3d3421794b (diff) |
Merge branch 'QA_5_1'
Signed-off-by: William Desportes <williamdes@wdes.fr>
Diffstat (limited to 'test/classes')
-rw-r--r-- | test/classes/ErrorReportTest.php | 62 | ||||
-rw-r--r-- | test/classes/SqlTest.php | 219 | ||||
-rw-r--r-- | test/classes/Stubs/DbiDummy.php | 41 |
3 files changed, 319 insertions, 3 deletions
diff --git a/test/classes/ErrorReportTest.php b/test/classes/ErrorReportTest.php index 75998265b1..82036d8305 100644 --- a/test/classes/ErrorReportTest.php +++ b/test/classes/ErrorReportTest.php @@ -227,6 +227,68 @@ class ErrorReportTest extends AbstractTestCase ); } + public function testTruncateJsTrace(): void + { + $context = [ + ' success: function (response) {', + ' Functions.ajaxRemoveMessage($msgbox);', + ' if (response.success) {', + ' // Get the column min value.', + ' var min = response.column_data.min', + ' ? \'(\' + Messages.strColumnMin +', + ' this.completion.cm.removeKeyMap(this.keyMap);', + ' \' \' + response.column_data.min + \')\'', + ' : \'\';', + ' if (this.completion.options.closeOnUnfocus) {', + ' cm.off("blur", this.onBlur);', + ]; + + $data = [ + 'mode' => 'stack', + 'name' => 'TypeError', + 'message' => 'Cannot read property \'removeChild\' of null', + 'stack' => [ + [ + 'url' => 'http://pma.7.3.local/js/vendor/codemirror/addon/hint/show-hint.js?v=4.8.6-dev', + 'func' => 'Widget.close', + 'line' => 307, + 'column' => 29, + 'context' => $context, + ], + [ + 'func' => 'Object.fireWith [as resolveWith]', + 'line' => '2', + 'column' => '29039', + 'context' => [ + '/*! jQuery v3.5.1 | (c) JS Foundation and other contributors | jquery.org/license */', + '!function(e,t){"use strict";"object"==typeof module&&' + . '"object"==typeof module.exports?module.exports=e.document?t', + ], + 'url' => 'js/vendor/jquery/jquery.min.js?v=5.1.0-rc2', + 'scriptname' => 'js/vendor/jquery/jquery.min.js', + ], + ], + 'url' => 'http://pma.7.3.local/index.php?route=/table/sql&db=aaaaa&table=a&server=14', + ]; + $_POST['exception'] = $data; + + $actual = $this->errorReport->getData('js'); + // Adjust the data + unset($data['stack'][0]['url']); + $data['stack'][0]['uri'] = 'js/vendor/codemirror/addon/hint/show-hint.js?v=4.8.6-dev'; + $data['stack'][0]['scriptname'] = 'js/vendor/codemirror/addon/hint/show-hint.js'; + unset($data['stack'][1]['url']); + $data['stack'][1]['uri'] = 'js/vendor/jquery/jquery.min.js?v=5.1.0-rc2'; + unset($data['url']); + $data['uri'] = 'index.php?route=%2Ftable%2Fsql'; + $data['stack'][1]['context'][0] = '/*! jQuery v3.5.1 | (c) JS Foundation' + . ' and other contributors | jquery.org/l//...'; + $data['stack'][1]['context'][1] = '!function(e,t){"use strict";"object"=' + . '=typeof module&&"object"==typeof modul//...'; + + $this->assertEquals($data, $actual['exception']); + } + /** * The urls to be tested for sanitization * 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); + } } diff --git a/test/classes/Stubs/DbiDummy.php b/test/classes/Stubs/DbiDummy.php index d5d7caa22e..6b2468fb73 100644 --- a/test/classes/Stubs/DbiDummy.php +++ b/test/classes/Stubs/DbiDummy.php @@ -953,6 +953,11 @@ class DbiDummy implements DbiExtension ], [ 'query' => 'SELECT TABLE_NAME FROM information_schema.VIEWS' + . ' WHERE TABLE_SCHEMA = \'my_dataset\' AND TABLE_NAME = \'company_users\'', + 'result' => [], + ], + [ + 'query' => 'SELECT TABLE_NAME FROM information_schema.VIEWS' . ' WHERE TABLE_SCHEMA = \'my_db\' ' . 'AND TABLE_NAME = \'test_tbl\' AND IS_UPDATABLE = \'YES\'', 'result' => [], @@ -1468,7 +1473,7 @@ class DbiDummy implements DbiExtension ], ], [ - 'query' => "SHOW FULL TABLES FROM `default` WHERE `Table_type`IN('BASE TABLE', 'SYSTEM VERSIONED')", + 'query' => "SHOW FULL TABLES FROM `default` WHERE `Table_type` IN('BASE TABLE', 'SYSTEM VERSIONED')", 'result' => [ [ 'test1', @@ -1482,7 +1487,7 @@ class DbiDummy implements DbiExtension ], [ 'query' => 'SHOW FULL TABLES FROM `default` ' - . "WHERE `Table_type`NOT IN('BASE TABLE', 'SYSTEM VERSIONED')", + . "WHERE `Table_type` NOT IN('BASE TABLE', 'SYSTEM VERSIONED')", 'result' => [], ], [ @@ -1579,6 +1584,10 @@ class DbiDummy implements DbiExtension 'result' => [], ], [ + 'query' => "SHOW TABLE STATUS FROM `my_dataset` WHERE `Name` LIKE 'company\_users%'", + 'result' => [], + ], + [ 'query' => 'SELECT *, `TABLE_SCHEMA` AS `Db`, `TABLE_NAME` AS `Name`,' . ' `TABLE_TYPE` AS `TABLE_TYPE`, `ENGINE` AS `Engine`,' . ' `ENGINE` AS `Type`, `VERSION` AS `Version`, `ROW_FORMAT` AS `Row_format`,' @@ -2565,6 +2574,34 @@ class DbiDummy implements DbiExtension 'columns' => ['Host', 'User', 'Password'], 'result' => [['hostname', 'username', 'password']], ], + [ + 'query' => 'SELECT COUNT(*) FROM company_users WHERE not_working_count != 0', + 'result' => false, + ], + [ + 'query' => 'SELECT COUNT(*) FROM company_users', + 'result' => [ + [4], + ], + ], + [ + 'query' => 'SELECT COUNT(*) FROM company_users WHERE working_count = 0', + 'result' => [ + [15], + ], + ], + [ + 'query' => 'SELECT COUNT(*) FROM `my_dataset`.`company_users`', + 'result' => [ + [18], + ], + ], + [ + 'query' => 'SELECT COUNT(*) FROM company_users WHERE subquery_case = 0', + 'result' => [ + [42], + ], + ], ]; /** * Current database. |