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"
."@article{aKeyA,title={An Article},author={Foo Bar and Jane Doe},volume=5,journal=\"New Results\",year=2009,pages={1-2}}\n");
}
function _createDB($content) {
$test_data = fopen('php://memory','x+');
fwrite($test_data, $content);
fseek($test_data,0);
$btb = new BibDataBase();
$btb->update_internal("inline", $test_data);
return $btb;
}
function test_bibentry_to_html_book() {
$btb = $this->createDB();
$first_entry=$btb->getEntryByKey('aKey');
// default style
$this->assertEquals("A Book (Martin Monperrus), Springer, 2009. [bibtex]",strip_tags($first_entry->toHTML()));
$this->assertEquals('A Book ( ), Springer, 2009. ',$first_entry->toHTML());
// IEEE style
bibtexbrowser_configure('BIBLIOGRAPHYSTYLE','JanosBibliographyStyle');
$this->assertEquals("Martin Monperrus, \"A Book\", Springer, 2009.\n [bibtex]",strip_tags($first_entry->toHTML()));
// Vancouver style
bibtexbrowser_configure('BIBLIOGRAPHYSTYLE','VancouverBibliographyStyle');
$this->assertEquals("Martin Monperrus. A Book. Springer; 2009.\n [bibtex]",strip_tags($first_entry->toHTML()));
// other methods
$this->assertEquals(' ',$first_entry->bib2links());
$this->assertEquals('',$first_entry->anchor());
}
function test_bibentry_to_html_article() {
$btb = $this->createDB();
$first_entry=$btb->getEntryByKey('aKeyA');
$this->assertEquals("1-2",$first_entry->getField("pages"));
$this->assertEquals("1",$first_entry->getPages()[0]);
$this->assertEquals("2",$first_entry->getPages()[1]);
// default style
$this->assertEquals("An Article (Foo Bar and Jane Doe), In New Results, volume 5, 2009. [bibtex]",strip_tags($first_entry->toHTML()));
$this->assertEquals('An Article ( ), In New Results, volume 5, 2009. ',$first_entry->toHTML());
// IEEE style
bibtexbrowser_configure('BIBLIOGRAPHYSTYLE','JanosBibliographyStyle');
$this->assertEquals("Foo Bar and Jane Doe, \"An Article\", In New Results, vol. 5, pp. 1-2, 2009.\n [bibtex]",strip_tags($first_entry->toHTML()));
// Vancouver style
bibtexbrowser_configure('BIBLIOGRAPHYSTYLE','VancouverBibliographyStyle');
$this->assertEquals("Foo Bar and Jane Doe. An Article. New Results. 2009;5:1-2.\n [bibtex]",strip_tags($first_entry->toHTML()));
}
function testMultiSearch() {
$btb = $this->createDB();
$q=array(Q_AUTHOR=>'monperrus');
$results=$btb->multisearch($q);
$entry = $results[0];
$this->assertTrue(count($results) == 1);
$this->assertTrue($entry->getTitle() == 'A Book');
}
function testMultiSearch2() {
$btb = $this->createDB();
$q=array(Q_AUTHOR=>'monperrus|ducasse');
$results=$btb->multisearch($q);
$entry = $results[0];
$this->assertTrue(count($results) == 1);
$this->assertTrue($entry->getTitle() == 'A Book');
}
function test_config_value() {
// default value
$this->assertFalse(config_value('BIBTEXBROWSER_NO_DEFAULT'));
// setting to true
bibtexbrowser_configure('BIBTEXBROWSER_NO_DEFAULT', true);
$this->assertTrue(config_value('BIBTEXBROWSER_NO_DEFAULT'));
ob_start();
default_message();
$this->assertEquals('', ob_get_clean());
// setting to false
bibtexbrowser_configure('BIBTEXBROWSER_NO_DEFAULT', false);
$this->assertFalse(config_value('BIBTEXBROWSER_NO_DEFAULT'));
ob_start();
default_message();
$this->assertContains('Congratulations', ob_get_clean());
}
function testInternationalization() {
$btb = $this->createDB();
global $BIBTEXBROWSER_LANG;
$BIBTEXBROWSER_LANG=array();
$BIBTEXBROWSER_LANG['Refereed Conference Papers']="foo";
$this->assertEquals("foo",__("Refereed Conference Papers"));
$BIBTEXBROWSER_LANG['Books']="Livres";
$d = new AcademicDisplay();
$d->setDB($btb);
ob_start();
$d->display();
$data = ob_get_clean();
$this->assertContains('Livres', $data);
}
function testNoSlashInKey() {
$btb = $this->createDB();
$q=array(Q_SEARCH=>'Slash');
$results=$btb->multisearch($q);
$this->assertTrue(count($results) == 1);
$entry = $results[0];
$this->assertContains("aKey-withSlash",$entry->toHTML());
$q=array(Q_KEY=>'aKey-withSlash');
$results=$btb->multisearch($q);
$entry2 = $results[0];
$this->assertSame($entry2,$entry);
}
function test_string_should_be_deleted_after_update() {
$test_data = fopen('php://memory','x+');
fwrite($test_data, "@book{aKey,title={A Book},author={Martin Monperrus},publisher={Springer},year=2009}\n".
"@String{x=2008}\n"
);
fseek($test_data,0);
$btb = new BibDataBase();
$btb->update_internal("inline", $test_data);
// print_r($btb->stringdb);
$this->assertEquals(1,count($btb->stringdb));
// replacing the existing one
$test_data = fopen('php://memory','x+');
fwrite($test_data, "@book{aKey2,title={A Book},author={Martin Monperrus},publisher={Springer},year=2009}\n".
"@String{x=2009}\n"
);
fseek($test_data,0);
$btb = new BibDataBase();
$btb->update_internal("inline2", $test_data);
// print_r($btb->stringdb);
$this->assertEquals(1,count($btb->stringdb));
$this->assertEquals("2009",$btb->stringdb['x']->value);//
// now adding another one and removing the string
$test_data2 = fopen('php://memory','x+');
fwrite($test_data2, "@book{aKey,title={A Book},author={Martin Monperrus},publisher={Springer},year=2009}\n".
"@String{y=2010}\n"
);
fseek($test_data2,0);
$btb->update_internal("inline2", $test_data2);
$this->assertEquals(1,count($btb->stringdb));//
$this->assertEquals("2010",$btb->stringdb['y']->value);//
}
function test_google_scholar_metadata() {
$test_data = fopen('php://memory','x+');
fwrite($test_data, "@article{aKey,title={A Book},author={Martin Monperrus},publisher={Springer},year=2009,pages={42--4242},number=1}\n".
"@String{x=2008}\n"
);
fseek($test_data,0);
$db = new BibDataBase();
$db->update_internal("inline", $test_data);
$dis = new BibEntryDisplay($db->getEntryByKey('aKey'));
$metadata = $dis->metadata_dict();
//print_r($metadata);
$this->assertEquals("A Book",$metadata['citation_title']);
$this->assertEquals("2009",$metadata['citation_date']);
$this->assertEquals("2009",$metadata['citation_year']);
$this->assertEquals("42",$metadata['citation_firstpage']);
$this->assertEquals("4242",$metadata['citation_lastpage']);
$this->assertEquals("1",$metadata['citation_issue']);
}
function test_metadata_opengraph() {
$test_data = fopen('php://memory','x+');
fwrite($test_data, "@article{aKey,title={A Book},author={Martin Monperrus},url={http://foo.com/},publisher={Springer},year=2009,pages={42--4242},number=1}\n".
"@String{x=2008}\n"
);
fseek($test_data,0);
$db = new BibDataBase();
$db->update_internal("inline", $test_data);
$dis = new BibEntryDisplay($db->getEntryByKey('aKey'));
$metadata = $dis->metadata_dict();
//print_r($metadata);
$this->assertEquals("A Book",$metadata['og:title']);
$this->assertEquals("article",$metadata['og:type']);
$this->assertTrue(1 == preg_match("/http:.*author=Martin\+Monperrus/",$metadata['og:author']));
$this->assertEquals("2009",$metadata['og:published_time']);
}
function test_math_cal() {
$test_data = fopen('php://memory','x+');
fwrite($test_data, "@book{aKey,title={{A Book $\mbox{foo}$ tt $\boo{t}$}} ,author={Martin Monperrus},publisher={Springer},year=2009}\n".
"@String{x=2008}\n"
);
fseek($test_data,0);
$btb = new BibDataBase();
$btb->update_internal("inline", $test_data);
$first_entry=$btb->bibdb[array_keys($btb->bibdb)[0]];
// $this->assertTrue(strpos('A Book{} $\mbox{foo}$',$first_entry->toHTML());
$this->assertEquals('A Book $\mbox{foo}$ tt $\boo{t}$',$first_entry->getTitle());
}
function test_link_configuration() {
$test_data = fopen('php://memory','x+');
fwrite($test_data, "@book{aKey,pdf={myarticle.pdf}}\n"
);
fseek($test_data,0);
$btb = new BibDataBase();
$btb->update_internal("inline", $test_data);
$first_entry=$btb->bibdb[array_keys($btb->bibdb)[0]];
$this->assertEquals('[pdf]',$first_entry->getLink('pdf'));
$this->assertEquals('[pdf]',$first_entry->getPdfLink());
$this->assertEquals('',$first_entry->getLink('pdf','pdficon.png'));
$this->assertEquals('[see]',$first_entry->getLink('pdf',NULL,'see'));
}
// see https://github.com/monperrus/bibtexbrowser/pull/14
function test_zotero() {
$test_data = fopen('php://memory','x+');
fwrite($test_data, "@book{aKey,file={myarticle.pdf}}\n"
);
fseek($test_data,0);
$btb = new BibDataBase();
$btb->update_internal("inline", $test_data);
$first_entry=$btb->bibdb[array_keys($btb->bibdb)[0]];
$this->assertEquals('[pdf]',$first_entry->getPdfLink());
}
// https://github.com/monperrus/bibtexbrowser/issues/40
function test_doi_url() {
$test_data = fopen('php://memory','x+');
fwrite($test_data, "@Article{Baldwin2014Quantum,Doi={10.1103/PhysRevA.90.012110},Url={http://link.aps.org/doi/10.1103/PhysRevA.90.012110}}"
);
fseek($test_data,0);
$btb = new BibDataBase();
$btb->update_internal("inline", $test_data);
$first_entry=$btb->bibdb[array_keys($btb->bibdb)[0]];
$this->assertEquals('
@Article{Baldwin2014Quantum,Doi={10.1103/PhysRevA.90.012110},Url={http://link.aps.org/doi/10.1103/PhysRevA.90.012110}}',$first_entry->toEntryUnformatted()); } function test_filter_view() { $test_data = fopen('php://memory','x+'); fwrite($test_data, "@article{aKey,title={A Book},author={Martin M\'e},publisher={Springer},year=2009,pages={42--4242},number=1}\n"); fseek($test_data,0); $db = new BibDataBase(); $db->update_internal("inline", $test_data); $dis = $db->getEntryByKey('aKey'); $this->assertEquals("@article{aKey,title={A Book},author={Martin M\'e},publisher={Springer},year=2009,pages={42--4242},number=1}",$dis->getText()); // now ith option bibtexbrowser_configure('BIBTEXBROWSER_BIBTEX_VIEW', 'reconstructed'); bibtexbrowser_configure('BIBTEXBROWSER_BIBTEX_VIEW_FILTEREDOUT', 'pages|number'); $this->assertEquals("@article{aKey,\n title = {A Book},\n author = {Martin M\'e},\n publisher = {Springer},\n year = {2009},\n}\n", $dis->getText()); } function test_BIBTEXBROWSER_USE_LATEX2HTML() { $bibtex = "@article{aKey,title={\`a Book},author={Martin Monperrus},publisher={Springer},year=2009,pages={42--4242},number=1}\n"; bibtexbrowser_configure('BIBTEXBROWSER_USE_LATEX2HTML', true); $test_data = fopen('php://memory','x+'); fwrite($test_data, $bibtex); fseek($test_data,0); $db = new BibDataBase(); $db->update_internal("inline", $test_data); $dis = $db->getEntryByKey('aKey'); $this->assertEquals("à Book",$dis->getTitle()); bibtexbrowser_configure('BIBTEXBROWSER_USE_LATEX2HTML', false); $test_data = fopen('php://memory','x+'); fwrite($test_data, $bibtex); fseek($test_data,0); $db = new BibDataBase(); $db->update_internal("inline", $test_data); $dis = $db->getEntryByKey('aKey'); $this->assertEquals("\`a Book",$dis->getTitle()); } function test_PagedDisplay() { $PAGE_SIZE = 3; bibtexbrowser_configure('BIBTEXBROWSER_DEFAULT_DISPLAY', 'PagedDisplay'); bibtexbrowser_configure('PAGE_SIZE', $PAGE_SIZE); $_GET['bib'] = 'bibacid-utf8.bib'; $_GET['all'] = 1; $d = new Dispatcher(); ob_start(); $d->main(); $content = "