add tests with copilot

This commit is contained in:
Martin Monperrus
2025-01-19 22:27:56 +01:00
parent f15c4ca07e
commit 4cdfb81a64
2 changed files with 435 additions and 14 deletions
+47 -14
View File
@@ -728,7 +728,9 @@ class StateBasedBibtexParser {
} // end function
} // end class
/** a default empty implementation of a delegate for StateBasedBibtexParser */
/** a default empty implementation of a delegate for StateBasedBibtexParser
* @codeCoverageIgnore
*/
class ParserDelegate {
function beginFile() {}
@@ -758,18 +760,20 @@ usage:
see snippet of [[#StateBasedBibParser]]
*/
class XMLPrettyPrinter extends ParserDelegate {
var $header = true;
function beginFile() {
header('Content-type: text/xml;');
if ($this->header) {
header('Content-type: text/xml;');
}
print '<?xml version="1.0" encoding="'.OUTPUT_ENCODING.'"?>';
print '<bibfile>';
}
function endFile() {
print '</bibfile>';
}
function setEntryField($finalkey,$entryvalue) {
print "<data>\n<key>".$finalkey."</key>\n<value>".$entryvalue."</value>\n</data>\n";
print "<data>\n<key>".trim($finalkey)."</key>\n<value>".htmlspecialchars($entryvalue)."</value>\n</data>\n";
}
function setEntryType($entrytype) {
@@ -1148,6 +1152,7 @@ function s3988($s) {
see BibEntry->formatAuthor($author)
@deprecated
@nodoc
@codeCoverageIgnore
*/
function formatAuthor() {
die('Sorry, this function does not exist anymore, however, you can simply use $bibentry->formatAuthor($author) instead.');
@@ -1191,7 +1196,7 @@ class BibEntry {
var $timestamp;
/** The name of the file containing this entry */
var $filename;
var $filename = "nofilename-frommemory";
/** The short name of the entry (parameterized by ABBRV_TYPE) */
var $abbrv;
@@ -1231,7 +1236,9 @@ class BibEntry {
/** Returns the type of this bib entry (always lowercase). */
function getType() {
// strtolower is important to be case-insensitive
return strtolower($this->getField(Q_INNER_TYPE));
$res = $this->getField(Q_INNER_TYPE);
if ($res == NULL) return 'unknown';
return strtolower($res);
}
/** Sets the key of this bib entry. */
@@ -1467,6 +1474,10 @@ class BibEntry {
/** Returns the key of this entry */
function getKey() {
if ($this->getField(Q_KEY) == null) {
$key = md5($this->getTitle().$this->getFormattedAuthorsString());
$this->setField(Q_KEY, $key);
}
return $this->getField(Q_KEY);
}
@@ -2071,6 +2082,7 @@ class BibEntry {
} // end class BibEntry
class RawBibEntry extends BibEntry {
function setField($name, $value) {
$this->fields[$name]=$value;
$this->raw_fields[$name]=$value;
@@ -3168,6 +3180,7 @@ class YearDisplay {
/** is an array of strings representing years */
var $yearIndex;
var $entries;
function setDB($bibdatabase) {
$this->setEntries($bibdatabase->bibdb);
@@ -4303,11 +4316,13 @@ usage:
getTitle()
* $title: title of the page
*/
function HTMLTemplate($content) {
function HTMLTemplate($content, $header = true) {
// when we load a page with AJAX
// the HTTP header is taken into account, not the <meta http-equiv>
header('Content-type: text/html; charset='.OUTPUT_ENCODING);
if ($header) {
header('Content-type: text/html; charset='.OUTPUT_ENCODING);
}
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n";
?>
@@ -4406,7 +4421,9 @@ usage:
</pre>
*/
class BibtexDisplay {
var $header = true;
var $entries;
var $title;
function __construct() {}
function setTitle($title) { $this->title = $title; return $this; }
@@ -4419,7 +4436,9 @@ class BibtexDisplay {
function setWrapper($x) { $x->wrapper = 'NoWrapper'; }
function display() {
header('Content-type: text/plain; charset='.OUTPUT_ENCODING);
if ($this->header) {
header('Content-type: text/plain; charset='.OUTPUT_ENCODING);
}
echo '% generated by bibtexbrowser <http://www.monperrus.net/martin/bibtexbrowser/>'."\n";
echo '% '.@$this->title."\n";
echo '% Encoding: '.OUTPUT_ENCODING."\n";
@@ -4534,7 +4553,8 @@ usage:
class RSSDisplay {
var $title = 'RSS produced by bibtexbrowser';
var $header = true;
var $entries;
function __construct() {
// nothing by default
}
@@ -4558,6 +4578,7 @@ class RSSDisplay {
// be careful of <
$desc = str_replace('<','&#60;',$desc);
$desc = str_replace('>','&#62;',$desc);
// final test with encoding:
if (function_exists('mb_check_encoding')) { // (PHP 4 >= 4.4.3, PHP 5 >= 5.1.3)
@@ -4577,7 +4598,9 @@ class RSSDisplay {
function setWrapper($x) { $x->wrapper = 'NoWrapper'; }
function display() {
header('Content-type: application/rss+xml');
if ($this->header) {
header('Content-type: application/rss+xml');
}
echo '<?xml version="1.0" encoding="'.OUTPUT_ENCODING.'"?>';
//
@@ -4585,8 +4608,8 @@ class RSSDisplay {
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title><?php echo $this->title;?></title>
<link>http://<?php echo @$_SERVER['HTTP_HOST'].htmlentities(@$_SERVER['REQUEST_URI']);?></link>
<atom:link href="http://<?php echo @$_SERVER['HTTP_HOST'].htmlentities(@$_SERVER['REQUEST_URI']);?>" rel="self" type="application/rss+xml" />
<link>http://<?php echo getServerData('HTTP_HOST').htmlentities(getServerData('REQUEST_URI'));?></link>
<atom:link href="http://<?php echo getServerData('HTTP_HOST').htmlentities(getServerData('REQUEST_URI'));?>" rel="self" type="application/rss+xml" />
<description></description>
<generator>bibtexbrowser v__GITHUB__</generator>
@@ -4613,6 +4636,16 @@ class RSSDisplay {
}
}
/**
* workaround deprecation
*/
function getServerData($key) {
// if exists
if (isset($_SERVER[$key])) {
return $_SERVER[$key];
}
return "";
}
/** is responsible for transforming a query string of $_GET[..] into a publication list.