diff --git a/bibacid-utf8.bib b/bibacid-utf8.bib index e0c088e..313e3a1 100755 --- a/bibacid-utf8.bib +++ b/bibacid-utf8.bib @@ -1,5 +1,5 @@ -%% test concatenation in @string + @string{foo="Foo"} @string{bar=foo#" Bar"} diff --git a/bibtexbrowser-test.php b/bibtexbrowser-test.php index 690c439..51e8b1e 100755 --- a/bibtexbrowser-test.php +++ b/bibtexbrowser-test.php @@ -32,12 +32,12 @@ class BTBTest extends PHPUnit_Framework_TestCase { ."@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) { + function _createDB($content, $fakefilename="inline") { $test_data = fopen('php://memory','x+'); fwrite($test_data, $content); fseek($test_data,0); $btb = new BibDataBase(); - $btb->update_internal("inline", $test_data); + $btb->update_internal($fakefilename, $test_data); return $btb; } @@ -511,16 +511,36 @@ class BTBTest extends PHPUnit_Framework_TestCase { $this->assertEquals("array (\n 'Foo Acé' => 'Foo Acé',\n 'Martin Monperrus' => 'Martin Monperrus',\n)", $index); } + function test_string_entries() { + $btb = new BibDataBase(); + $btb->load('bibacid-utf8.bib'); + $this->assertEquals(5, count($btb->stringdb)); + $this->assertEquals("@string{foo={Foo}}",$btb->stringdb['foo']->toString()); + } + function test_identity() { $btb = new BibDataBase(); $btb->load('bibacid-utf8.bib'); + + // computing the representation + $d = new SimpleDisplay(); + $d->setDB($btb); + ob_start(); + $d->display(); + $rep = ob_get_clean(); + $nref = count($btb->bibdb); $bibtex = $btb->toBibtex(); // reparsing the new content - $btb2 = $this->_createDB($bibtex); + $btb2 = $this->_createDB($bibtex, 'bibacid-utf8.bib'); + $d->setDB($btb2); + ob_start(); + $d->display(); + $rep2 = ob_get_clean(); // there is the same number of entries $this->assertEquals($nref, count($btb2->bibdb)); $this->assertEquals($bibtex, $btb2->toBibtex()); + $this->assertEquals($rep, $rep2); } function test_cli() { diff --git a/bibtexbrowser.php b/bibtexbrowser.php index 5e9fb9c..1634c82 100755 --- a/bibtexbrowser.php +++ b/bibtexbrowser.php @@ -753,6 +753,10 @@ class StringEntry { $this->value=$v; $this->filename=$filename; } + + function toString() { + return '@string{'.$this->name.'={'.$this->value.'}}'; + } } // end class StringEntry @@ -3902,8 +3906,17 @@ class BibDataBase { return $result; } + /** returns the text of all @String entries of this dabatase */ + function stringEntriesText() { + $s = ""; + foreach($this->stringdb as $entry) { $s.=$entry->toString()."\n"; } + return $s; + } + + /** returns a classical textual Bibtex representation of this database */ function toBibtex() { $s = ""; + $s .= $this->stringEntriesText(); foreach($this->bibdb as $bibentry) { $s.=$bibentry->getText()."\n"; } return $s; }