diff options
author | William Desportes <williamdes@wdes.fr> | 2019-05-01 22:19:25 +0300 |
---|---|---|
committer | William Desportes <williamdes@wdes.fr> | 2019-05-01 22:19:25 +0300 |
commit | a0d091e1f86c858b00a686572a7671fa095b3c3a (patch) | |
tree | daecd8b122b05688541189b92374c3775653972d /test/classes/ErrorReportTest.php | |
parent | defd6761bafff72d53acc79571e19a89428e8bed (diff) |
Add test for sanitizeUrl and improve testGetForm with real data
Signed-off-by: William Desportes <williamdes@wdes.fr>
Diffstat (limited to 'test/classes/ErrorReportTest.php')
-rw-r--r-- | test/classes/ErrorReportTest.php | 143 |
1 files changed, 138 insertions, 5 deletions
diff --git a/test/classes/ErrorReportTest.php b/test/classes/ErrorReportTest.php index 28aaf6b95a..90b0c0b760 100644 --- a/test/classes/ErrorReportTest.php +++ b/test/classes/ErrorReportTest.php @@ -151,9 +151,33 @@ class ErrorReportTest extends TestCase $form = $this->errorReport->getForm(); $this->assertStringContainsString('<pre class="report-data">[]</pre>', $form); + $context = [ + 'Widget.prototype = {', + ' close: function() {', + ' if (this.completion.widget != this) return;', + ' this.completion.widget = null;', + ' this.hints.parentNode.removeChild(this.hints);', + ' this.completion.cm.removeKeyMap(this.keyMap);', + '', + ' var cm = this.completion.cm;', + ' if (this.completion.options.closeOnUnfocus) {', + ' cm.off("blur", this.onBlur);', + ]; + $_POST['exception'] = [ - 'stack' => [], - 'url' => 'http://localhost/index.php' + '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, + ], + ], + 'url' => 'http://pma.7.3.local/tbl_sql.php?db=aaaaa&table=a&server=14' ]; $_POST['microhistory'] = ''; $_POST['description'] = 'description'; @@ -168,11 +192,23 @@ class ErrorReportTest extends TestCase 'locale' => $_COOKIE['pma_lang'], 'configuration_storage' => 'disabled', 'php_version' => phpversion(), - 'script_name' => 'index.php', + 'script_name' => 'tbl_sql.php', 'exception_type' => 'js', 'exception' => [ - 'stack' => [], - 'uri' => 'index.php?' + 'mode' => 'stack', + 'name' => 'TypeError', + 'message' => 'Cannot read property \'removeChild\' of null', + 'stack' => [ + [ + 'func' => 'Widget.close', + 'line' => 307, + 'column' => 29, + 'context' => $context, + 'uri' => 'js/vendor/codemirror/addon/hint/show-hint.js?v=4.8.6-dev', + 'scriptname' => 'js/vendor/codemirror/addon/hint/show-hint.js', + ], + ], + 'uri' => 'tbl_sql.php?' ], 'microhistory' => $_POST['microhistory'], 'steps' => $_POST['description'], @@ -182,4 +218,101 @@ class ErrorReportTest extends TestCase $form = $this->errorReport->getForm(); $this->assertStringContainsString('<pre class="report-data">' . $expectedData . '</pre>', $form); } + + /** + * Call private functions by setting visibility to public. + * + * @param string $name method name + * @param array $params parameters for the invocation + * + * @return mixed the output from the private method. + */ + private function _callPrivateFunction($name, $params) + { + $class = new \ReflectionClass(ErrorReport::class); + $method = $class->getMethod($name); + $method->setAccessible(true); + return $method->invokeArgs($this->errorReport, $params); + } + + /** + * The urls to be tested for sanitization + * + * @return array[] + */ + public function urlsToSanitize(): array + { + return [ + [ + '', + [ + 'index.php?', + 'index.php', + ], + ], + [ + 'http://localhost/js/vendor/codemirror/addon/hint/show-hint.js?v=4.8.6-dev', + [ + 'js/vendor/codemirror/addon/hint/show-hint.js?v=4.8.6-dev', + 'js/vendor/codemirror/addon/hint/show-hint.js', + ], + ], + [ + 'http://pma.7.3.local/tbl_sql.php?db=aaaaa&table=a&server=14', + [ + 'tbl_sql.php?', + 'tbl_sql.php', + ], + ], + [ + 'http://pma.7.3.local/tbl_sql.php?db=aaaaa;table=a;server=14', + [ + 'tbl_sql.php?', + 'tbl_sql.php', + ], + ], + [ + 'https://pma.7.3.local/tbl_sql.php?db=aaaaa;table=a;server=14', + [ + 'tbl_sql.php?', + 'tbl_sql.php', + ], + ], + [ + 'https://pma.7.3.local/fileDotPhp.php?db=aaaaa;table=a;server=14', + [ + 'fileDotPhp.php?', + 'fileDotPhp.php', + ], + ], + [ + 'https://pma.7.3.local/secretFolder/fileDotPhp.php?db=aaaaa;table=a;server=14', + [ + 'fileDotPhp.php?', + 'fileDotPhp.php', + ], + ], + [ + 'http://7.2.local/@williamdes/theREALphpMyAdminREPO/js/vendor/jquery/jquery-ui.min.js?v=5.0.0-dev', + [ + 'js/vendor/jquery/jquery-ui.min.js?v=5.0.0-dev', + 'js/vendor/jquery/jquery-ui.min.js', + ], + ], + ]; + } + + /** + * Test the url sanitization + * + * @dataProvider urlsToSanitize + * @param string $url The url to test + * @param array $result The result + * @return void + */ + public function testSanitizeUrl(string $url, array $result): void + { + // $this->errorReport->sanitizeUrl + $this->assertSame($result, $this->_callPrivateFunction('sanitizeUrl', [$url])); + } } |