Skip to content
Snippets Groups Projects
Commit 1ce2b746 authored by Demian Katz's avatar Demian Katz
Browse files

Smarter COinS ID loading; added unit test.

parent 3c2634c7
Branches
Tags
No related merge requests found
...@@ -646,23 +646,36 @@ class SolrDefault extends AbstractBase ...@@ -646,23 +646,36 @@ class SolrDefault extends AbstractBase
} }
/** /**
* Get the OpenURL parameters to represent this record (useful for the * Get the COinS identifier.
* title attribute of a COinS span tag).
* *
* @return string OpenURL parameters. * @return string
*/ */
public function getOpenURL() protected function getCoinsID()
{ {
// Get the COinS ID -- it should be in the OpenURL section of config.ini, // Get the COinS ID -- it should be in the OpenURL section of config.ini,
// but we'll also check the COinS section for compatibility with legacy // but we'll also check the COinS section for compatibility with legacy
// configurations (this moved between the RC2 and 1.0 releases). // configurations (this moved between the RC2 and 1.0 releases).
$coinsID = isset($this->mainConfig->OpenURL->rfr_id) if (isset($this->mainConfig->OpenURL->rfr_id)
? $this->mainConfig->OpenURL->rfr_id && !empty($this->mainConfig->OpenURL->rfr_id)
: $this->mainConfig->COinS->identifier; ) {
if (empty($coinsID)) { return $this->mainConfig->OpenURL->rfr_id;
$coinsID = 'vufind.svn.sourceforge.net'; }
if (isset($this->mainConfig->COinS->identifier)
&& !empty($this->mainConfig->COinS->identifier)
) {
return $this->mainConfig->COinS->identifier;
} }
return 'vufind.svn.sourceforge.net';
}
/**
* Get the OpenURL parameters to represent this record (useful for the
* title attribute of a COinS span tag).
*
* @return string OpenURL parameters.
*/
public function getOpenURL()
{
// Get a representative publication date: // Get a representative publication date:
$pubDate = $this->getPublicationDates(); $pubDate = $this->getPublicationDates();
$pubDate = empty($pubDate) ? '' : $pubDate[0]; $pubDate = empty($pubDate) ? '' : $pubDate[0];
...@@ -671,7 +684,7 @@ class SolrDefault extends AbstractBase ...@@ -671,7 +684,7 @@ class SolrDefault extends AbstractBase
$params = array( $params = array(
'ctx_ver' => 'Z39.88-2004', 'ctx_ver' => 'Z39.88-2004',
'ctx_enc' => 'info:ofi/enc:UTF-8', 'ctx_enc' => 'info:ofi/enc:UTF-8',
'rfr_id' => "info:sid/{$coinsID}:generator", 'rfr_id' => 'info:sid/' . $this->getCoinsID() . ':generator',
'rft.title' => $this->getTitle(), 'rft.title' => $this->getTitle(),
'rft.date' => $pubDate 'rft.date' => $pubDate
); );
......
<?php
/**
* SolrDefault Record Driver Test Class
*
* PHP version 5
*
* Copyright (C) Villanova University 2010.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @category VuFind2
* @package Tests
* @author Demian Katz <demian.katz@villanova.edu>
* @author Preetha Rao <vufind-tech@lists.sourceforge.net>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org/wiki/vufind2:unit_tests Wiki
*/
namespace VuFindTest\RecordDriver;
use VuFind\RecordDriver\SolrDefault;
/**
* SolrDefault Record Driver Test Class
*
* @category VuFind2
* @package Tests
* @author Demian Katz <demian.katz@villanova.edu>
* @author David Maus <maus@hab.de>
* @author Preetha Rao <vufind-tech@lists.sourceforge.net>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org/wiki/vufind2:unit_tests Wiki
*/
class SolrDefaultTest extends \VuFindTest\Unit\TestCase
{
/**
* Test an OpenURL for a book.
*
* @return void
*/
public function testBookOpenURL()
{
$driver = $this->getDriver();
$this->assertEquals('ctx_ver=Z39.88-2004&ctx_enc=info%3Aofi%2Fenc%3AUTF-8&rfr_id=info%3Asid%2Fvufind.svn.sourceforge.net%3Agenerator&rft.title=La+congiura+dei+Principi+Napoletani+1701+%3A+%28prima+e+seconda+stesura%29+%2F&rft.date=1992&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=book&rft.btitle=La+congiura+dei+Principi+Napoletani+1701+%3A+%28prima+e+seconda+stesura%29+%2F&rft.series=Vico%2C+Giambattista%2C+1668-1744.+Works.+1982+%3B&rft.au=Vico%2C+Giambattista%2C+1668-1744.&rft.pub=Centro+di+Studi+Vichiani%2C&rft.edition=Fictional+edition.&rft.isbn=8820737493', $driver->getOpenURL());
}
/**
* Test an OpenURL for an article.
*
* @return void
*/
public function testArticleOpenURL()
{
$overrides = array(
'format' => array('Article'),
'container_title' => 'Fake Container',
'container_volume' => 'XVII',
'container_issue' => '6',
'container_start_page' => '12',
);
$driver = $this->getDriver($overrides);
$this->assertEquals('ctx_ver=Z39.88-2004&ctx_enc=info%3Aofi%2Fenc%3AUTF-8&rfr_id=info%3Asid%2Fvufind.svn.sourceforge.net%3Agenerator&rft.date=1992&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.genre=article&rft.issn=&rft.isbn=8820737493&rft.volume=XVII&rft.issue=6&rft.spage=12&rft.jtitle=Fake+Container&rft.atitle=La+congiura+dei+Principi+Napoletani+1701+%3A+%28prima+e+seconda+stesura%29+%2F&rft.au=Vico%2C+Giambattista%2C+1668-1744.&rft.format=Article&rft.language=Italian', $driver->getOpenURL());
}
/**
* Test an OpenURL for a journal.
*
* @return void
*/
public function testJournalOpenURL()
{
$overrides = array(
'format' => array('Journal'),
'issn' => array('1234-5678'),
);
$driver = $this->getDriver($overrides);
$this->assertEquals('ctx_ver=Z39.88-2004&ctx_enc=info%3Aofi%2Fenc%3AUTF-8&rfr_id=info%3Asid%2Fvufind.svn.sourceforge.net%3Agenerator&rft.title=La+congiura+dei+Principi+Napoletani+1701+%3A+%28prima+e+seconda+stesura%29+%2F&rft.issn=1234-5678&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Adc&rft.creator=Vico%2C+Giambattista%2C+1668-1744.&rft.pub=Centro+di+Studi+Vichiani%2C&rft.format=Journal&rft.language=Italian', $driver->getOpenURL());
}
/**
* Test an OpenURL for an unknown material type.
*
* @return void
*/
public function testUnknownTypeOpenURL()
{
$overrides = array(
'format' => array('Thingie'),
);
$driver = $this->getDriver($overrides);
$this->assertEquals('ctx_ver=Z39.88-2004&ctx_enc=info%3Aofi%2Fenc%3AUTF-8&rfr_id=info%3Asid%2Fvufind.svn.sourceforge.net%3Agenerator&rft.title=La+congiura+dei+Principi+Napoletani+1701+%3A+%28prima+e+seconda+stesura%29+%2F&rft.date=1992&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Adc&rft.creator=Vico%2C+Giambattista%2C+1668-1744.&rft.pub=Centro+di+Studi+Vichiani%2C&rft.format=Thingie&rft.language=Italian', $driver->getOpenURL());
}
/**
* Get a record driver with fake data.
*
* @param array $overrides Fixture fields to override.
*
* @return SolrDefault
*/
protected function getDriver($overrides = array())
{
$fixture = json_decode(
file_get_contents(
realpath(
VUFIND_PHPUNIT_MODULE_PATH . '/fixtures/misc/testbug2.json'
)
),
true
);
$record = new SolrDefault();
$record->setRawData($overrides + $fixture['response']['docs'][0]);
return $record;
}
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment