Browse Source

fix and test ordering

pull/117/head
Martin Monperrus 3 years ago
parent
commit
ba1a8ef241
  1. 52
      BibtexbrowserTest.php
  2. 29
      bibtexbrowser.php
  3. 6
      reference-output-wp-publications.txt

52
BibtexbrowserTest.php

@ -653,8 +653,8 @@ class BibtexbrowserTest extends PHPUnit_Framework_TestCase {
ob_get_clean();
// the indices have been set by SimpleDisplay
$this->assertEquals("[1]", $btb->getEntryByKey('aKey')->getAbbrv());
$this->assertEquals("[3]", $btb->getEntryByKey('aKey-withSlash')->getAbbrv());
$this->assertEquals("[3]", $btb->getEntryByKey('aKey')->getAbbrv());
$this->assertEquals("[1]", $btb->getEntryByKey('aKey-withSlash')->getAbbrv());
// SimpleDisplayExt sets the indices differently, using setIndicesInIncreasingOrderChangingEveryYear
$d = new SimpleDisplayExt();
@ -662,7 +662,7 @@ class BibtexbrowserTest extends PHPUnit_Framework_TestCase {
ob_start();
$d->display();
ob_get_clean();
$this->assertEquals("[2]", $btb->getEntryByKey('aKey')->getAbbrv());
$this->assertEquals("[1]", $btb->getEntryByKey('aKey')->getAbbrv());
$this->assertEquals("[1]", $btb->getEntryByKey('aKey-withSlash')->getAbbrv());
}
@ -749,6 +749,7 @@ class BibtexbrowserTest extends PHPUnit_Framework_TestCase {
function test_before() {
// contract: the ordering is chronological
$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);
@ -767,7 +768,7 @@ class BibtexbrowserTest extends PHPUnit_Framework_TestCase {
}
function test80() {
// entries without year are at the top
// contract: entries without year are at the top
$bibtex = "@article{keyWithoutYear,title={First article},author = {Martin}},@article{key2,title={Second article},author = {Martin}, year=2007}";
$test_data = fopen('php://memory','x+');
fwrite($test_data, $bibtex);
@ -860,7 +861,48 @@ class BibtexbrowserTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('Preferential polarization and its reversal in polycrystalline $BiFeO_{3}$/$La_{0. 5}Sr_{0.5} CoO_{3}$ heterostructures', $db->bibdb['doe2000']->getTitle());
}
function test_sorting_year() {
$bibtex = "@article{doe2004,year=2004},@article{doe1999,year=1999},@article{doe2000,year=2000}";
$test_data = fopen('php://memory','x+');
fwrite($test_data, $bibtex);
fseek($test_data,0);
$db = new BibDataBase();
$db->update_internal("inline", $test_data);
// print_r($db);
$data = array_values($db->bibdb);
$this->assertEquals("2004", $data[0]->getYear());
$this->assertEquals("1999", $data[1]->getYear());
$this->assertEquals("2000", $data[2]->getYear());
usort($data, 'compare_bib_entry_by_year');
$this->assertEquals("1999", $data[0]->getYear());
$this->assertEquals("2000", $data[1]->getYear());
$this->assertEquals("2004", $data[2]->getYear());
$bibtex = "@article{doe2004,year=2004},@article{doe1999,year=1999},@article{doe2000,year=2000}";
}
function test_sorting_month() {
$bibtex = "@article{doe2004,year=2004, month={may}},@article{doe1999,year=2004,month={jan}},@article{doe2000,year=2000, month={dec}}";
$test_data = fopen('php://memory','x+');
fwrite($test_data, $bibtex);
fseek($test_data,0);
$db = new BibDataBase();
$db->update_internal("inline", $test_data);
// print_r($db);
$data = array_values($db->bibdb);
$this->assertEquals("may", $data[0]->getField("month"));
usort($data, 'compare_bib_entry_by_month');
$this->assertEquals("jan", $data[0]->getField("month"));
$this->assertEquals("may", $data[1]->getField("month"));
$this->assertEquals("dec", $data[2]->getField("month"));
$bibtex = "@article{doe2004,year=2004},@article{doe1999,year=1999},@article{doe2000,year=2000}";
}
} // end class

29
bibtexbrowser.php

@ -218,10 +218,10 @@ if (defined('ENCODING')) {
// define sort order for special values in 'year' field
// highest number is sorted first
// don't exceed 0 though, since the values are added to PHP_INT_MAX
@define('ORDER_YEAR_INPRESS', -0);
@define('ORDER_YEAR_ACCEPTED', -1);
@define('ORDER_YEAR_SUBMITTED', -2);
@define('ORDER_YEAR_OTHERNONINT', -3);
@define('ORDER_YEAR_INPRESS', 0);
@define('ORDER_YEAR_ACCEPTED', 1);
@define('ORDER_YEAR_SUBMITTED', 2);
@define('ORDER_YEAR_OTHERNONINT', 3);
// in embedded mode, we still need a URL for displaying bibtex entries alone
@ -2157,38 +2157,38 @@ function compare_bib_entry_by_year($a, $b)
if ($yearA === 0) {
switch (strtolower($a->getYearRaw())) {
case Q_YEAR_INPRESS:
$yearA = PHP_INT_MAX + ORDER_YEAR_INPRESS;
$yearA = PHP_INT_MIN + ORDER_YEAR_INPRESS;
break;
case Q_YEAR_ACCEPTED:
$yearA = PHP_INT_MAX + ORDER_YEAR_ACCEPTED;
$yearA = PHP_INT_MIN + ORDER_YEAR_ACCEPTED;
break;
case Q_YEAR_SUBMITTED:
$yearA = PHP_INT_MAX + ORDER_YEAR_SUBMITTED;
$yearA = PHP_INT_MIN + ORDER_YEAR_SUBMITTED;
break;
default:
$yearA = PHP_INT_MAX + ORDER_YEAR_OTHERNONINT;
$yearA = PHP_INT_MIN + ORDER_YEAR_OTHERNONINT;
}
}
if ($yearB === 0) {
switch (strtolower($b->getYearRaw())) {
case Q_YEAR_INPRESS:
$yearB = PHP_INT_MAX + ORDER_YEAR_INPRESS;
$yearB = PHP_INT_MIN + ORDER_YEAR_INPRESS;
break;
case Q_YEAR_ACCEPTED:
$yearB = PHP_INT_MAX + ORDER_YEAR_ACCEPTED;
$yearB = PHP_INT_MIN + ORDER_YEAR_ACCEPTED;
break;
case Q_YEAR_SUBMITTED:
$yearB = PHP_INT_MAX + ORDER_YEAR_SUBMITTED;
$yearB = PHP_INT_MIN + ORDER_YEAR_SUBMITTED;
break;
default:
$yearB = PHP_INT_MAX + ORDER_YEAR_OTHERNONINT;
$yearB = PHP_INT_MIN + ORDER_YEAR_OTHERNONINT;
}
}
if ($yearA === $yearB)
return 0;
else if ($yearA > $yearB)
else if ($yearA < $yearB)
return -1;
else
return 1;
@ -2242,7 +2242,6 @@ function compare_bib_entry_by_month($a, $b)
//desired order of values
$sort_order_values = array('jan','january','feb','february','mar','march','apr','april','may','jun','june','jul','july','aug','august','sep','september','oct','october','nov','november','dec','december');
//order: 1=as specified in $sort_order_values or -1=reversed
$order = -1;
//first check if the search key exists
@ -2278,7 +2277,7 @@ function compare_bib_entry_by_month($a, $b)
}
}
return $order*$retval;
return $retval;
}
/** is the default sectioning for AcademicDisplay (books, articles, proceedings, etc. ) */

6
reference-output-wp-publications.txt

@ -1,10 +1,10 @@
array (
'rendered' => '<p>&#091;wp-publications bib=sample.bib all=1&#093; gives:<br />
<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>
<tr><td colspan="2" class="sheader">2000</td></tr>
<tr class="bibline"><td class="bibref"><a class="bibanchor" name="1"></a>[1]</td><td class="bibitem"><span itemscope="" itemtype="http://schema.org/ScholarlyArticle"><span class="bibtitle" itemprop="name">An article</span> (<span class="bibauthor"><span itemprop="author" itemtype="http://schema.org/Person">Jane Doe</span></span>), <span class="bibbooktitle">In <span itemprop="isPartOf">The Wordpress Journal</span></span>, <span itemprop="datePublished">2000</span>.<span class="Z3988" title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.atitle=An+article&amp;rft.jtitle=The+Wordpress+Journal&amp;rft.volume=&amp;rft.issue=&amp;rft.pub=&amp;rfr_id=info%3Asid%2F%3Asample.bib&amp;rft.date=2000&amp;rft.au=Jane+Doe"></span></span> <span class="bibmenu"><a class="biburl" title="doe2000" href="http://bibtexbrowser.com/?wp-publications=doe2000">[bibtex]</a></span></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">An article</span> (<span class="bibauthor"><span itemprop="author" itemtype="http://schema.org/Person">Jane Doe</span></span>), <span class="bibbooktitle">In <span itemprop="isPartOf">The Wordpress Journal</span></span>, <span itemprop="datePublished">2000</span>.<span class="Z3988" title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.atitle=An+article&amp;rft.jtitle=The+Wordpress+Journal&amp;rft.volume=&amp;rft.issue=&amp;rft.pub=&amp;rfr_id=info%3Asid%2F%3Asample.bib&amp;rft.date=2000&amp;rft.au=Jane+Doe"></span></span> <span class="bibmenu"><a class="biburl" title="doe2000" href="http://bibtexbrowser.com/?wp-publications=doe2000">[bibtex]</a></span></td></tr>
<tr><td colspan="2" class="sheader">2001</td></tr>
<tr class="bibline"><td class="bibref"><a class="bibanchor" name="1"></a>[1]</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>
</table></p>
',
'protected' => false,

Loading…
Cancel
Save