Browse Source

enable to create one table per year

pull/98/head
Martin Monperrus 6 years ago
parent
commit
75d56cd632
  1. 6
      .travis.yml
  2. 40
      bibtexbrowser-test.php
  3. 24
      bibtexbrowser.php
  4. 2
      reference-output-wp-publications.txt

6
.travis.yml

@ -32,13 +32,9 @@ script:
- $WPCLI plugin install wp-publications --activate
# there is no need to create a post, because one activation task of wp-publications is to create a fake post
#- $WPCLI post create --post_title=test --post_content='[wp-publications bib="sample.bib" all=true]'
- cp bibtexbrowser.php ./wp-content/plugins/wp-publications/
- $WPCLI rest post list --slug=wp-publications-example --field=content | tee before.txt
# do we still have the reference output? (useful for detecting changes in Wordpress or WP-CLI) (diff exits with 1 if there is a difference)
- diff reference-output-wp-publications.txt before.txt
# now we take the newer version and we render again
- cp bibtexbrowser.php ./wp-content/plugins/wp-publications/
- $WPCLI rest post list --slug=wp-publications-example --field=content | tee after.txt
# just to be sure, is there a difference with the previous version?
- diff before.txt after.txt
sudo: false

40
bibtexbrowser-test.php

@ -746,6 +746,25 @@ class BTBTest extends PHPUnit_Framework_TestCase {
$this->assertContains('<a href="https://scholar.google.com/scholar?cites=1234">[citations]</a>', $entry->toHTML());
}
function test_before() {
$bibtex = "@article{doe2000,title={An article},author={Jane Doe},journal={The Wordpress Journal},year=2000}@book{doo2001,title={A book},author={Jane Doe},year=2001}";
$test_data = fopen('php://memory','x+');
fwrite($test_data, $bibtex);
fseek($test_data,0);
$db = new BibDataBase();
$_GET[Q_FILE] = 'sample.bib';
$db->update_internal("inline", $test_data);
$d = new SimpleDisplay();
$d->setDB($db);
ob_start();
$d->display();
$output = ob_get_clean();
$res = eval("return ".file_get_contents('reference-output-wp-publications.txt').";");
$this->assertEquals(strip_tags($res['rendered']), "&#091;wp-publications bib=sample.bib all=1&#093; gives:\n".strip_tags($output)."\n");
}
function test80() {
// entries without year are at the top
$bibtex = "@article{keyWithoutYear,title={First article},author = {Martin}},@article{key2,title={Second article},author = {Martin}, year=2007}";
@ -782,6 +801,27 @@ class BTBTest extends PHPUnit_Framework_TestCase {
}
function test_multiple_table() {
ob_start();
$btb = new BibDataBase();
$btb->load('bibacid-utf8.bib');
$display = new SimpleDisplay($btb, array(Q_YEAR => '1997'));
$display->display();
$display = new SimpleDisplay($btb, array(Q_YEAR => '2010'));
$display->display();
$output = ob_get_clean();
// assertion: we have two tables in the output
$xml = new SimpleXMLElement("<doc>".$output."</doc>");
$result = $xml->xpath('//table');
$this->assertEquals(2,count($result));
}
} // end class

24
bibtexbrowser.php

@ -3122,6 +3122,12 @@ class SimpleDisplay {
var $entries = array();
var $headingLevel = BIBTEXBROWSER_HTMLHEADINGLEVEL;
function __construct($db = NULL, $query = NULL) {
if ($db == NULL) return;
$this->setEntries($db->multisearch($query));
}
function incHeadingLevel ($by=1) {
$this->headingLevel += $by;
}
@ -3220,15 +3226,15 @@ class SimpleDisplay {
echo 'Options: '.@implode(',',$this->options).'<br/>';
}
if ($this->headingLevel == BIBTEXBROWSER_HTMLHEADINGLEVEL) {
echo "\n".'<span class="count">';
if (count($this->entries) == 1) {
echo count ($this->entries).' '.__('result');
} else if (count($this->entries) != 0) {
echo count ($this->entries).' '.__('results');
}
echo "</span>\n";
}
// if ($this->headingLevel == BIBTEXBROWSER_HTMLHEADINGLEVEL) {
// echo "\n".'<span class="count">';
// if (count($this->entries) == 1) {
// echo count ($this->entries).' '.__('result');
// } else if (count($this->entries) != 0) {
// echo count ($this->entries).' '.__('results');
// }
// echo "</span>\n";
// }
print_header_layout();
$pred = NULL;

2
reference-output-wp-publications.txt

@ -1,7 +1,5 @@
array (
'rendered' => '<p>&#091;wp-publications bib=sample.bib all=1&#093; gives:<br />
<span class="count">2 results</span>
<table class="result">
<tr><td colspan="2" class="sheader">2001</td></tr>
<tr class="bibline"><td class="bibref"><a class="bibanchor" name="2"></a>[2]</td><td class="bibitem"><span itemscope="" itemtype="http://schema.org/ScholarlyArticle"><span class="bibtitle" itemprop="name">A book</span> (<span class="bibauthor"><span itemprop="author" itemtype="http://schema.org/Person">Jane Doe</span></span>), <span itemprop="datePublished">2001</span>.<span class="Z3988" title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.btitle=A+book&amp;rft.genre=book&amp;rft.pub=&amp;rfr_id=info%3Asid%2F%3Asample.bib&amp;rft.date=2001&amp;rft.au=Jane+Doe"></span></span> <span class="bibmenu"><a class="biburl" title="doo2001" href="http://bibtexbrowser.com/?wp-publications=doo2001">[bibtex]</a></span></td></tr>

Loading…
Cancel
Save