cvs: pear /Structures_BibTex BibTex.php /Structures_BibTex/tests BibTexTest.php

From: Date: Tue, 23 Jan 2007 22:56:40 +0000
Subject: cvs: pear /Structures_BibTex BibTex.php /Structures_BibTex/tests BibTexTest.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-44364@lists.php.net to get a copy of this message
hugoki Tue Jan 23 22:56:40 2007 UTC Modified files: /pear/Structures_BibTex BibTex.php /pear/Structures_BibTex/tests BibTexTest.php Log: - Changes for Request #9878 http://cvs.php.net/viewvc.cgi/pear/Structures_BibTex/BibTex.php?r1=1.14&r2=1.15&diff_format=u Index: pear/Structures_BibTex/BibTex.php diff -u pear/Structures_BibTex/BibTex.php:1.14 pear/Structures_BibTex/BibTex.php:1.15 --- pear/Structures_BibTex/BibTex.php:1.14 Wed Jan 10 09:45:29 2007 +++ pear/Structures_BibTex/BibTex.php Tue Jan 23 22:56:40 2007 @@ -19,7 +19,7 @@ * @author Elmar Pitschke <elmar.pitschke@gmx.de> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: BibTex.php,v 1.14 2007/01/10 09:45:29 hugoki Exp $ + * @version CVS: $Id: BibTex.php,v 1.15 2007/01/23 22:56:40 hugoki Exp $ * @link http://pear.php.net/package/Structures_BibTex */ @@ -163,6 +163,7 @@ 'wordWrapBreak' => "\n", 'wordWrapCut' => 0, 'removeCurlyBraces' => false, + 'extractAuthors' => true, ); foreach ($options as $option => $value) { $test = $this->setOption($option, $value); @@ -427,7 +428,7 @@ } } //Handling the authors - if (in_array('author', array_keys($ret))) { + if (in_array('author', array_keys($ret)) && $this->_options['extractAuthors']) { $ret['author'] = $this->_extractAuthors($ret['author']); } } @@ -979,11 +980,15 @@ } //Author if (array_key_exists('author', $entry)) { - $tmparray = array(); //In this array the authors are saved and the joind with an and - foreach ($entry['author'] as $authorentry) { - $tmparray[] = $this->_formatAuthor($authorentry); + if ($this->_options['extractAuthors']) { + $tmparray = array(); //In this array the authors are saved and the joind with an and + foreach ($entry['author'] as $authorentry) { + $tmparray[] = $this->_formatAuthor($authorentry); + } + $author = join(' and ', $tmparray); + } else { + $author = $entry['author']; } - $author = join(' and ', $tmparray); } else { $author = ''; } @@ -1060,11 +1065,15 @@ $year = $this->_unwrap($entry['year']); } if (array_key_exists('author', $entry)) { - $tmparray = array(); //In this array the authors are saved and the joind with an and - foreach ($entry['author'] as $authorentry) { - $tmparray[] = $this->_formatAuthor($authorentry); + if ($this->_options['extractAuthors']) { + $tmparray = array(); //In this array the authors are saved and the joind with an and + foreach ($entry['author'] as $authorentry) { + $tmparray[] = $this->_formatAuthor($authorentry); + } + $authors = join(', ', $tmparray); + } else { + $authors = $entry['author']; } - $authors = join(', ', $tmparray); } if ((''!=$title) || (''!=$journal) || (''!=$year) || (''!=$authors)) { $line = str_replace("TITLE", $title, $line); @@ -1113,11 +1122,15 @@ $year = $this->_unwrap($entry['year']); } if (array_key_exists('author', $entry)) { - $tmparray = array(); //In this array the authors are saved and the joind with an and - foreach ($entry['author'] as $authorentry) { - $tmparray[] = $this->_formatAuthor($authorentry); + if ($this->_options['extractAuthors']) { + $tmparray = array(); //In this array the authors are saved and the joind with an and + foreach ($entry['author'] as $authorentry) { + $tmparray[] = $this->_formatAuthor($authorentry); + } + $authors = join(', ', $tmparray); + } else { + $authors = $entry['author']; } - $authors = join(', ', $tmparray); } if ((''!=$title) || (''!=$journal) || (''!=$year) || (''!=$authors)) { $line = str_replace("TITLE", $title, $line); http://cvs.php.net/viewvc.cgi/pear/Structures_BibTex/tests/BibTexTest.php?r1=1.1&r2=1.2&diff_format=u Index: pear/Structures_BibTex/tests/BibTexTest.php diff -u pear/Structures_BibTex/tests/BibTexTest.php:1.1 pear/Structures_BibTex/tests/BibTexTest.php:1.2 --- pear/Structures_BibTex/tests/BibTexTest.php:1.1 Wed Jan 10 18:35:20 2007 +++ pear/Structures_BibTex/tests/BibTexTest.php Tue Jan 23 22:56:40 2007 @@ -973,6 +973,73 @@ $shouldbe[0]['jr'] = ''; $this->assertEquals($shouldbe, $this->obj->_extractAuthors($test)); } + + public function testNotExtractAuthors() { + $this->obj->clearWarnings(); + $test = ' +@phdthesis{foo4, +author = {John Doe}, +} + '; + $shouldbe = 'John Doe'; + $this->obj->content = $test; + $this->obj->setOption('extractAuthors', false); + $this->obj->parse(); + $this->assertEquals($shouldbe, $this->obj->data[0]['author']); + } + + public function testExtractAuthors() { + $this->obj->clearWarnings(); + $test = ' +@phdthesis{foo4, +author = {John Doe}, +} + '; + $shouldbe = array(); + $shouldbe[0]['first'] = 'John'; + $shouldbe[0]['von'] = ''; + $shouldbe[0]['last'] = 'Doe'; + $shouldbe[0]['jr'] = ''; + $this->obj->content = $test; + $this->obj->setOption('extractAuthors', true); + $this->obj->parse(); + $this->assertEquals($shouldbe, $this->obj->data[0]['author']); + } + + public function testNotExtractAuthorsBibtexExport() { + $this->obj->clearWarnings(); + $test = "@phdthesis { foo4,\n\tauthor = {John Doe}\n}\n\n"; + $this->obj->content = $test; + $this->obj->setOption('extractAuthors', false); + $this->obj->parse(); + $this->assertEquals($test, $this->obj->bibTex()); + } + + public function testNotExtractAuthorsRtfExport() { + $this->obj->clearWarnings(); + $test = "@phdthesis { foo4,\n\tauthor = {John Doe}\n}\n\n"; + $shouldbe = '{\rtf +John Doe, "{\b }", {\i }, +\par +}'; + $this->obj->content = $test; + $this->obj->setOption('extractAuthors', false); + $this->obj->parse(); + $this->assertEquals($shouldbe, $this->obj->rtf()); + } + + public function testNotExtractAuthorsHtmlExport() { + $this->obj->clearWarnings(); + $test = "@phdthesis { foo4,\n\tauthor = {John Doe}\n}\n\n"; + $shouldbe = '<p> +John Doe, "<strong></strong>", <em></em>, <br /> +</p> +'; + $this->obj->content = $test; + $this->obj->setOption('extractAuthors', false); + $this->obj->parse(); + $this->assertEquals($shouldbe, $this->obj->html()); + } } // Call Structures_BibTexTest::main() if this source file is executed directly.

« previous php.pear.cvs (#44364) next »