diff --git a/_test/tests/general/general_html.test.php b/_test/tests/general/general_html.test.php new file mode 100644 index 0000000000..8e6dd77c09 --- /dev/null +++ b/_test/tests/general/general_html.test.php @@ -0,0 +1,118 @@ + 'recent']], + ['/doku.php', 'GET', ['do' => 'index']], + ['/doku.php', 'GET', ['do' => 'login']], + ['/doku.php', 'GET', ['do' => 'search', 'q' => 'wiki']], + ['/doku.php', 'GET', ['id' => 'wiki:syntax']], + ['/doku.php', 'GET', ['id' => 'wiki:syntax', 'ns' => 'wiki', 'image' => 'wiki:dokuwiki-128.png', 'do' => 'media']], + ['/lib/exe/detail.php', 'GET', ['id' => 'wiki:syntax', 'media' => 'wiki:dokuwiki-128.png']], + ]; + } + + /** + * Sends the given HTML to the validator and returns the result + * + * @param string $html + * @return array + * @throws Exception when communication failed + */ + protected function validate($html) + { + $http = new \dokuwiki\HTTP\DokuHTTPClient(); + $http->headers['Content-Type'] = 'text/html; charset=utf-8'; + $result = $http->post('https://validator.w3.org/nu/?out=json&level=error', $html); + + if ($result === false) { + throw new \Exception($http->error); + } + + $result = json_decode($result, true); + if ($result === null) { + throw new \Exception('could not decode JSON'); + } + + return $result; + } + + /** + * Reformat the errors for nicer display in output + * + * @param array $result + * @return string[] + */ + protected function listErrors($result) + { + $errors = []; + foreach ($result['messages'] as $msg) { + if ($this->isAllowedError($msg['message'])) continue; + $errors[] = "☛ " . $msg['message'] . "\n" . $msg['extract'] . "\n"; + } + return $errors; + } + + /** + * Is the given string an allowed error that should be skipped? + * + * @param string $string + * @return bool + */ + protected function isAllowedError($string) + { + $re = join('|', array_map('preg_quote_cb', $this->allowedErrors)); + return (bool)preg_match("/$re/", $string); + } + + /** + * @dataProvider requestProvider + * @param string $url + * @param string $method + * @param array $data + * @group internet + */ + public function test_Validity($url, $method, $data) + { + $request = new TestRequest(); + if ($method == 'GET') { + $response = $request->get($data, $url); + } elseif ($method == 'POST') { + $response = $request->post($data, $url); + } else { + throw new \RuntimeException("unknown method given: $method"); + } + + $html = $response->getContent(); + try { + $result = $this->validate($html); + } catch (\Exception $e) { + $this->markTestSkipped($e->getMessage()); + return; + } + + $errors = $this->listErrors($result); + $info = "Invalid HTML found:\n" . join("\n", $errors); + + $this->assertEquals(0, count($errors), $info); + } +} diff --git a/inc/changelog.php b/inc/changelog.php index b96a1d43ae..93dd2271c2 100644 --- a/inc/changelog.php +++ b/inc/changelog.php @@ -228,9 +228,9 @@ function getRecents($first,$num,$ns='',$flags=0){ // read all recent changes. (kept short) if ($flags & RECENTS_MEDIA_CHANGES) { - $lines = @file($conf['media_changelog']); + $lines = @file($conf['media_changelog']) ?: []; } else { - $lines = @file($conf['changelog']); + $lines = @file($conf['changelog']) ?: []; } if (!is_array($lines)) { $lines = array(); @@ -240,7 +240,7 @@ function getRecents($first,$num,$ns='',$flags=0){ $media_lines = array(); if ($flags & RECENTS_MEDIA_PAGES_MIXED) { - $media_lines = @file($conf['media_changelog']); + $media_lines = @file($conf['media_changelog']) ?: []; if (!is_array($media_lines)) { $media_lines = array(); } diff --git a/inc/html.php b/inc/html.php index 773d553649..d42c580e10 100644 --- a/inc/html.php +++ b/inc/html.php @@ -50,7 +50,7 @@ function html_login($svg = false){ print p_locale_xhtml('login'); print '
'.NL; - $form = new Doku_Form(array('id' => 'dw__login')); + $form = new Doku_Form(array('id' => 'dw__login', 'action'=>wl($ID))); $form->startFieldset($lang['btn_login']); $form->addHidden('id', $ID); $form->addHidden('do', 'login'); @@ -707,7 +707,7 @@ function html_recent($first = 0, $show_changes = 'both') { '

'; } - $form = new Doku_Form(array('id' => 'dw__recent', 'method' => 'GET', 'class' => 'changes')); + $form = new Doku_Form(array('id' => 'dw__recent', 'method' => 'GET', 'class' => 'changes', 'action'=>wl($ID))); $form->addHidden('sectok', null); $form->addHidden('do', 'recent'); $form->addHidden('id', $ID);