update_internal("inline", $test_data); return $btb; } function test_bibentry_to_html() { $btb = $this->createDB(); $first_entry=$btb->bibdb[array_keys($btb->bibdb)[0]]; $this->assertEquals('[bibtex]',$first_entry->bib2links()); $this->assertEquals('',$first_entry->anchor()); } 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_flush()); // 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_flush()); } 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_flush(); $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->getUrlLink()); $this->assertEquals('[pdf]',$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->getUrlLink()); } // 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 Monperrus},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 Monperrus},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 Monperrus},\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 = "
".ob_get_flush()."
"; $xml = new SimpleXMLElement($content); $result = $xml->xpath('//td[@class=\'bibref\']'); $this->assertEquals($PAGE_SIZE,count($result)); } function test_getKeywords() { $bibtex = "@article{aKey,title={\`a Book},keywords={foo,bar},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(2,count($dis->getKeywords())); } } // end class ?>