diff --git a/.travis.yml b/.travis.yml index e524a05..428e148 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ language: php php: 5.4 script: + - curl -o reflectivedoc.php http://www.monperrus.net/martin/reflectivedoc.php.txt - curl -o gakowiki-syntax.php http://www.monperrus.net/martin/gakowiki-syntax.php.txt - phpunit bibtexbrowser-test.php diff --git a/bibtexbrowser-test.php b/bibtexbrowser-test.php index 8ec90fb..0f166b6 100755 --- a/bibtexbrowser-test.php +++ b/bibtexbrowser-test.php @@ -10,22 +10,44 @@ (be sure that xdebug is enabled: /etc/php5/cli/conf.d# ln -s ../../mods-available/xdebug.ini) */ -$_GET['library']=1; +function exception_error_handler($severity, $message, $file, $line) { + if ($severity != E_ERROR) { + //trigger_error($message); + return; + } + throw new ErrorException($message, 0, $severity, $file, $line); +} +error_reporting(E_ALL); @copy('bibtexbrowser.local.php','bibtexbrowser.local.php.bak'); @unlink('bibtexbrowser.local.php'); -require_once ('bibtexbrowser.php'); +if(is_file('reflectivedoc.php')) { + set_error_handler("exception_error_handler"); + require('reflectivedoc.php'); + $_GET['library'] = 1; + foreach(getAllSnippetsInFile('bibtexbrowser.php') as $snippet) { + //echo $snippet; + ob_start(); + eval($snippet); + ob_get_clean(); + unset($_GET['bib']); + } + restore_error_handler(); +} else { + $_GET['library']=1; + require_once ('bibtexbrowser.php'); +} -error_reporting(E_ALL); class BTBTest extends PHPUnit_Framework_TestCase { function test_checkdoc() { - include('gakowiki-syntax.php'); + if(!is_file('gakowiki-syntax.php')) { return; } + if (!function_exists('gk_wiki2html')) { include('gakowiki-syntax.php'); } create_wiki_parser()->parse(file_get_contents('bibtexbrowser-documentation.wiki')); } - + function createDB() { return $this->_createDB("@book{aKey,title={A Book},author={Martin Monperrus},publisher={Springer},year=2009}\n" ."@book{aKey/withSlash,title={Slash Dangerous for web servers},author={Ap Ache},publisher={Springer},year=2009}\n" @@ -578,4 +600,6 @@ function test_removeField() { } // end class +@copy('bibtexbrowser.local.php.bak','bibtexbrowser.local.php'); + ?> diff --git a/bibtexbrowser.php b/bibtexbrowser.php index ce2bfcf..36f4239 100755 --- a/bibtexbrowser.php +++ b/bibtexbrowser.php @@ -478,7 +478,7 @@ function createMenuManager() { $x = new MenuManager(); return $x;}
$delegate = new XMLPrettyPrinter();// or another delegate such as BibDBBuilder $parser = new StateBasedBibtexParser($delegate); - $parser->parse('foo.bib'); + $parser->parse(fopen('bibacid-utf8.bib','r'));notes: - It has no dependencies, it can be used outside of bibtexbrowser @@ -493,6 +493,7 @@ function StateBasedBibtexParser(&$delegate) { } function parse($handle) { + if (gettype($handle) == 'string') { throw new Exception('oops'); } $delegate = &$this->delegate; // STATE DEFINITIONS @define('NOTHING',1); @@ -714,11 +715,36 @@ function parse($handle) { } // end function } // end class -/** is a delegate for StateBasedBibParser. +/** a default empty implementation of a delegate for StateBasedBibtexParser */ +class ParserDelegate { + + function beginFile() {} + + function endFile() {} + + function setEntryField($finalkey,$entryvalue) {} + + function setEntryType($entrytype) {} + + function setEntryKey($entrykey) {} + + function beginEntry() {} + + function endEntry($entrysource) {} + + /** called for each sub parts of type {part} of a field value + * for now, only CURLYTOP and CURLYONE events + */ + function entryValuePart($key, $value, $type) {} + +} // end class ParserDelegate + + +/** is a possible delegate for StateBasedBibParser. usage: see snippet of [[#StateBasedBibParser]] */ -class XMLPrettyPrinter { +class XMLPrettyPrinter extends ParserDelegate { function beginFile() { header('Content-type: text/xml;'); print ''; @@ -764,29 +790,6 @@ function toString() { } // end class StringEntry -/** a default empty implementation of a delegate for StateBasedBibtexParser */ -class ParserDelegate { - - function beginFile() {} - - function endFile() {} - - function setEntryField($finalkey,$entryvalue) {} - - function setEntryType($entrytype) {} - - function setEntryKey($entrykey) {} - - function beginEntry() {} - - function endEntry($entrysource) {} - - /** called for each sub parts of type {part} of a field value - * for now, only CURLYTOP and CURLYONE events - */ - function entryValuePart($key, $value, $type) {} - -} // end class ParserDelegate /** builds arrays of BibEntry objects from a bibtex file. @@ -794,7 +797,7 @@ function entryValuePart($key, $value, $type) {}
$empty_array = array(); $db = new BibDBBuilder(); // see also factory method createBibDBBuilder - $db->build('foo.bib'); // parses foo.bib + $db->build('bibacid-utf8.bib'); // parses bib file print_r($db->builtdb);// an associated array key -> BibEntry objects print_r($db->stringdb);// an associated array key -> strings representing @string@@ -1115,8 +1118,8 @@ function formatAuthor() { /** represents a bibliographic entry. usage:
- $db = zetDB('metrics.bib'); - $entry = $db->getEntryByKey('Schmietendorf2000'); + $db = zetDB('bibacid-utf8.bib'); + $entry = $db->getEntryByKey('classical'); echo bib2html($entry);notes: @@ -2631,7 +2634,7 @@ function splitFullName($author){ usage:
$_GET['library']=1; - $_GET['bib']='metrics.bib'; + $_GET['bib']='bibacid-utf8.bib'; $_GET['all']=1; include( 'bibtexbrowser.php' ); setDB(); @@ -2723,7 +2726,7 @@ function javascript_math() { /** is used for creating menus (by type, by year, by author, etc.). usage:- $db = zetDB('metrics.bib'); + $db = zetDB('bibacid-utf8.bib'); $menu = new MenuManager(); $menu->setDB($db); $menu->year_size=100;// should display all years :) @@ -2979,7 +2982,7 @@ function query2title(&$query) { /** displays the latest modified bibtex entries. usage:- $db = zetDB('metrics.bib'); + $db = zetDB('bibacid-utf8.bib'); $d = new NewEntriesDisplay(); $d->setDB($db); $d->setN(7);// optional @@ -3015,7 +3018,7 @@ function display() { /** displays the entries by year in reverse chronological order. usage:- $db = zetDB('metrics.bib'); + $db = zetDB('bibacid-utf8.bib'); $d = new YearDisplay(); $d->setDB($db); $d->display(); @@ -3072,7 +3075,7 @@ function display() { /** displays the summary information of all bib entries. usage:- $db = zetDB('metrics.bib'); + $db = zetDB('bibacid-utf8.bib'); $d = new SimpleDisplay(); $d->setDB($db); $d->display(); @@ -3237,7 +3240,7 @@ function display() { /** displays the publication records sorted by publication types (as configured by constant BIBLIOGRAPHYSECTIONS). usage:- $db = zetDB('metrics.bib'); + $db = zetDB('bibacid-utf8.bib'); $d = new AcademicDisplay(); $d->setDB($db); $d->display(); @@ -3324,8 +3327,8 @@ function display() { /** displays a single bib entry. usage:- $db = zetDB('metrics.bib'); - $dis = new BibEntryDisplay($db->getEntryByKey('Schmietendorf2000')); + $db = zetDB('bibacid-utf8.bib'); + $dis = new BibEntryDisplay($db->getEntryByKey('classical')); $dis->display();notes: @@ -3617,7 +3620,7 @@ function metadata_eprints($result) { usage:$db = new BibDataBase(); -$db->load('metrics.bib'); +$db->load('bibacid-utf8.bib'); $query = array('author'=>'martin', 'year'=>2008); foreach ($db->multisearch($query) as $bibentry) { echo $bibentry->getTitle(); }@@ -4070,9 +4073,9 @@ function bibtexbrowserDefaultCSS() { /** encapsulates the content of a delegate into full-fledged HTML (<HTML><BODY> and TITLE) usage:- $db = zetDB('metrics.bib'); - $dis = new BibEntryDisplay($db->getEntryByKey('Schmietendorf2000')); - new HTMLTemplate($dis); + $db = zetDB('bibacid-utf8.bib'); + $dis = new BibEntryDisplay($db->getEntryByKey('classical')); + HTMLTemplate($dis);* $content: an object with methods display() @@ -4156,9 +4159,9 @@ function HTMLTemplate(&$content) { /** does nothing but calls method display() on the content. usage:- $db = zetDB('metrics.bib'); + $db = zetDB('bibacid-utf8.bib'); $dis = new SimpleDisplay($db); - new NoWrapper($dis); + NoWrapper($dis);*/ function NoWrapper(&$content) { @@ -4168,9 +4171,10 @@ function NoWrapper(&$content) { /** is used to create an subset of a bibtex file. usage:- $db = zetDB('metrics.bib'); + $db = zetDB('bibacid-utf8.bib'); $query = array('year'=>2005); - $dis = new BibtexDisplay()->setEntries($db->multisearch($query)); + $dis = new BibtexDisplay(); + $dis->setEntries($db->multisearch($query)); $dis->display();*/ @@ -4193,7 +4197,6 @@ function display() { echo '% '.@$this->title."\n"; echo '% Encoding: '.OUTPUT_ENCODING."\n"; foreach($this->entries as $bibentry) { echo $bibentry->getText()."\n"; } - exit; } } @@ -4203,7 +4206,7 @@ function display() {$_GET['library']=1; include( 'bibtexbrowser.php' ); - $db = zetDB('metrics.bib'); + $db = zetDB('bibacid-utf8.bib'); $pd = new PagedDisplay(); $pd->setEntries($db->bibdb); $pd->display(); @@ -4291,7 +4294,7 @@ function menu($less, $more) { /** is used to create an RSS feed. usage:- $db = zetDB('metrics.bib'); + $db = zetDB('bibacid-utf8.bib'); $query = array('year'=>2005); $rss = new RSSDisplay(); $entries = $db->getLatestEntries(10); @@ -4388,8 +4391,7 @@ function display() {$_GET['library']=1; @require('bibtexbrowser.php'); - // simulating ?bib=metrics.bib&year=2009 - $_GET['bib']='metrics.bib'; + $_GET['bib']='bibacid-utf8.bib'; $_GET['year']='2006'; $x = new Dispatcher(); $x->main();